1 # s-lang output for DCT, by Shiar
3 # 1.13.0 200411042100 - menu i/o functions
4 # - refresh hook renamed to showall
5 # 1.12.0 200411032145 - define main loop
6 # - use slang key reading functions
7 # 1.11.0 200410291300 - basic output using Term::Slang (ported from Curses)
12 use Term::Slang qw(:all);
14 use vars qw(%falias $path);
15 require $path."termcommon.pm";
17 push @{$hook{init}}, sub {
18 SLtt_get_terminfo and exit;
19 SLang_init_tty(-1, 0, 1);
21 SLtt_set_color(1, 0, 'black', 'lightgray');
23 END { SLsmg_reset_smg; SLang_reset_tty; } # shutdown display system
25 # where are $SLtt_Screen_Rows and $SLtt_Screen_Cols?
26 ($set{height}, $set{width}) = SLtt_get_screen_size;
28 $set{menushow} = int($set{width}/(4+$set{width}/20))+1; # menu items to show simultaneously
31 push @{$hook{showerror}}, sub {
33 SLsmg_draw_box(0, 0, 3, length($error)+4);
35 SLsmg_write_string(" $error ");
38 SLang_getkey; # wait for confirm
39 SLang_getkey while SLang_input_pending(0)==1; # clear key buffer
42 push @{$hook{showstack}}, sub {
44 SLsmg_gotorc($set{height}-$_, 1);
45 SLsmg_write_string("$_: ".showval($stack[$_], $set{base})); # prompt
48 SLsmg_gotorc($set{height}-@stack, 1);
52 push @{$hook{showmenu}}, sub {
53 SLsmg_gotorc($set{height}+2, 1);
56 for (grep exists $menu[0][$_], $menu[0][0]+1..$menu[0][0]+$set{menushow}) {
58 next unless defined $menu[0][$_];
59 my $sub = (my $s = $menu[0][$_]) =~ s/>[\w ]+$//;
60 SLsmg_gotorc($set{height}+2, $set{width}/$set{menushow}*$nr);
61 SLsmg_write_string($_);
62 SLsmg_reverse_video; # reverse
63 SLsmg_write_string($s);
65 SLsmg_write_string('>') if $sub; # indicate submenu
69 $action{more} = [-1, sub {
70 $menu[0][0] += $set{menushow};
71 $menu[0][0] = 0 if $menu[0][0] > @{$menu[0]};
72 $_->() for @{$hook{showmenu}};
75 unshift @{$hook{precmd}}, sub {
76 exists $falias{$_} or return; # handle function key
78 shift @menu if @menu>1; # remove current submenu
81 } # escape (go to parent)
82 $_ = $menu[0][$falias{$_}] and return; # execute found menu item instead
83 error("no such menu entry");
87 push @{$hook{showall}}, sub {
89 SLsmg_gotorc($set{height}+1, 0);
90 SLsmg_write_string("> "); # prompt
93 push @{$hook{showentry}}, sub {
94 SLsmg_gotorc($set{height}+1, 2);
95 SLsmg_write_string($_[0]);
104 my $key = chr SLang_getkey; # wait for user input
105 if ($key eq chr 27) {
106 $key .= chr SLang_getkey while SLang_input_pending(0)==1; # read additional keys
108 # error(join " ", map ord, split //, $key); #debug
115 title => "slang output",