1 # s-lang output for DCT, by Shiar
3 # 1.14.0 200508261255 - SIGWINCH handler to redraw on screen resize
4 # 1.13.0 200411042100 - menu i/o functions
5 # - refresh hook renamed to showall
6 # 1.12.0 200411032145 - define main loop
7 # - use slang key reading functions
8 # 1.11.0 200410291300 - basic output using Term::Slang (ported from Curses)
13 use Term::Slang qw(:all);
15 use vars qw(%falias $path);
16 require $path."termcommon.pm";
19 ($set{height}, $set{width}) = @_;
21 $set{menushow} = int($set{width}/(4+$set{width}/20))+1; # menu items to show simultaneously
24 push @{$hook{init}}, sub {
25 SLtt_get_terminfo and exit;
26 SLang_init_tty(-1, 0, 1);
28 SLtt_set_color(1, 0, 'black', 'lightgray');
30 END { SLsmg_reset_smg; SLang_reset_tty; } # shutdown display system
33 #xxx: no signal until keypress?
34 setsize(SLtt_get_screen_size); # get new screen size
35 SLsmg_reinit_smg; # reinitialize to use new size
36 redraw(all=>1); # queue complete refresh
37 draw(); # redraw rightnow
38 }; # window change (resize)
40 # where are $SLtt_Screen_Rows and $SLtt_Screen_Cols?
41 setsize(SLtt_get_screen_size);
44 push @{$hook{showerror}}, sub {
46 SLsmg_draw_box(0, 0, 3, length($error)+4);
48 SLsmg_write_string(" $error ");
51 SLang_getkey; # wait for confirm
52 SLang_getkey while SLang_input_pending(0)==1; # clear key buffer
55 push @{$hook{showstack}}, sub {
57 SLsmg_gotorc($set{height}-$_, 1);
58 SLsmg_write_string("$_: ".showval($stack[$_], $set{base})); # prompt
61 SLsmg_gotorc($set{height}-@stack, 1);
65 push @{$hook{showmenu}}, sub {
66 SLsmg_gotorc($set{height}+2, 1);
69 for (grep exists $menu[0][$_], $menu[0][0]+1..$menu[0][0]+$set{menushow}) {
71 next unless defined $menu[0][$_];
72 my $sub = (my $s = $menu[0][$_]) =~ s/>[\w ]+$//;
73 SLsmg_gotorc($set{height}+2, $set{width}/$set{menushow}*$nr);
74 SLsmg_write_string($_);
75 SLsmg_reverse_video; # reverse
76 SLsmg_write_string($s);
78 SLsmg_write_string('>') if $sub; # indicate submenu
82 $action{more} = [-1, sub {
83 $menu[0][0] += $set{menushow};
84 $menu[0][0] = 0 if $menu[0][0] > @{$menu[0]};
85 $_->() for @{$hook{showmenu}};
88 unshift @{$hook{precmd}}, sub {
89 exists $falias{$_} or return; # handle function key
91 shift @menu if @menu>1; # remove current submenu
94 } # escape (go to parent)
95 $_ = $menu[0][$falias{$_}] and return; # execute found menu item instead
96 error("no such menu entry");
100 push @{$hook{showall}}, sub {
102 SLsmg_gotorc($set{height}+1, 0);
103 SLsmg_write_string("> "); # prompt
106 push @{$hook{showentry}}, sub {
107 SLsmg_gotorc($set{height}+1, 2);
108 SLsmg_write_string($_[0]);
117 my $key = chr SLang_getkey; # wait for user input
118 if ($key eq chr 27) {
119 $key .= chr SLang_getkey while SLang_input_pending(0)==1; # read additional keys
121 # error(join " ", map ord, split //, $key); #debug
128 title => "slang output",