# s-lang output for DCT, by Shiar
+# 1.13.0 200411042100 - menu i/o functions
+# - refresh hook renamed to showall
# 1.12.0 200411032145 - define main loop
# - use slang key reading functions
-# 1.11.0 200410291300 -
+# 1.11.0 200410291300 - basic output using Term::Slang (ported from Curses)
use strict;
use warnings;
use Term::Slang qw(:all);
+use vars qw(%falias $path);
+require $path."termcommon.pm";
+
push @{$hook{init}}, sub {
SLtt_get_terminfo and exit;
SLang_init_tty(-1, 0, 1);
SLsmg_init_smg;
+ SLtt_set_color(1, 0, 'black', 'lightgray');
END { SLsmg_reset_smg; SLang_reset_tty; } # shutdown display system
# where are $SLtt_Screen_Rows and $SLtt_Screen_Cols?
($set{height}, $set{width}) = SLtt_get_screen_size;
- $set{height} -= 2;
+ $set{height} -= 3;
+ $set{menushow} = int($set{width}/(4+$set{width}/20))+1; # menu items to show simultaneously
}; # init
push @{$hook{showerror}}, sub {
SLsmg_erase_eol;
}; # showstack
-push @{$hook{refresh}}, sub {
+push @{$hook{showmenu}}, sub {
+ SLsmg_gotorc($set{height}+2, 1);
+ SLsmg_erase_eol;
+ my $nr = -1;
+ for (grep exists $menu[0][$_], $menu[0][0]+1..$menu[0][0]+$set{menushow}) {
+ $nr++;
+ next unless defined $menu[0][$_];
+ my $sub = (my $s = $menu[0][$_]) =~ s/>[\w ]+$//;
+ SLsmg_gotorc($set{height}+2, $set{width}/$set{menushow}*$nr);
+ SLsmg_write_string($_);
+ SLsmg_reverse_video; # reverse
+ SLsmg_write_string($s);
+ SLsmg_normal_video;
+ SLsmg_write_string('>') if $sub; # indicate submenu
+ } # display menu txts
+}; # showmenu
+
+$action{more} = [-1, sub {
+ $menu[0][0] += $set{menushow};
+ $menu[0][0] = 0 if $menu[0][0] > @{$menu[0]};
+ $_->() for @{$hook{showmenu}};
+}]; # tab
+
+unshift @{$hook{precmd}}, sub {
+ exists $falias{$_} or return; # handle function key
+ if ($falias{$_}==0) {
+ shift @menu if @menu>1; # remove current submenu
+ redraw(menu=>1);
+ return 1;
+ } # escape (go to parent)
+ $_ = $menu[0][$falias{$_}] and return; # execute found menu item instead
+ error("no such menu entry");
+ return 1;
+}; # precmd
+
+push @{$hook{showall}}, sub {
SLsmg_cls;
SLsmg_gotorc($set{height}+1, 0);
SLsmg_write_string("> "); # prompt
-}; # refresh
+}; # showall
push @{$hook{showentry}}, sub {
SLsmg_gotorc($set{height}+1, 2);
return {
author => "Shiar",
title => "slang output",
- version => "1.12",
+ version => "1.13",
};