1 # console output for DCT, by Shiar
3 # 1.12.0 200411032130 - handle input via Term::ReadKey; define main loop
4 # 1.11.0 200410152225 - class in file name, so check is not needed anymore
5 # 1.10.1 200410142200 - startup message omitted (now shown by main)
6 # 1.10.0 200410140120 - never clear screen (just let it scroll)
7 # - try to get width/height from environment vars
8 # - use escape sequences for clear/reposition/invert
9 # - print everything to STDOUT
16 push @{$hook{init}}, sub {
17 ReadMode 3; # cbreak mode
19 # print "\e[4mDCT $::VERSION\e[24m "; # print intro (underlined)
25 $set{height} = $ENV{LINES}-2 if $ENV{LINES} and $ENV{LINES}>=3;
26 $set{width} = $ENV{COLUMNS} if $ENV{COLUMNS};
29 push @{$hook{showerror}}, sub {
30 print "\n\a\e[7m$_[0]\e[27m"; # bell and reverse video
33 push @{$hook{showstack}}, sub {
34 for (reverse 0..@stack-1) {
35 print "\n$_: ", showval($stack[$_], $set{base});
37 print "\n> "; # prompt
40 push @{$hook{showmenu}}, sub {
42 for (grep exists $menu[0][$_], $menu[0][0]+1..$menu[0][0]+$set{menushow}) {
44 next unless defined $menu[0][$_];
45 my $sub = (my $s = $menu[0][$_]) =~ s/>[\w ]+$//;
47 print ">" if $sub; # indicate submenu
52 push @{$hook{showall}}, sub {
53 # print "\ec"; # reset (clear screen, go home)
56 push @{$hook{showentry}}, sub {
57 print "\e[3G\e[K", $_[0]; # cursor to column #3; erase line
64 my $key = ReadKey; # wait for user input
66 $key .= $_ while defined ($_ = ReadKey(-1)); # read additional keys
74 title => "console output",