X-Git-Url: http://git.shiar.net/descalc.git/blobdiff_plain/7db84757c6ba80836bc8c2cc9de326f16862a2cd:/08_disp_stdout.pm..4e1d9535fda6685e53ce570ca4e4cd6c260f55d3:/05_disp_stdout.pm diff --git a/08_disp_stdout.pm b/05_disp_stdout.pm similarity index 73% rename from 08_disp_stdout.pm rename to 05_disp_stdout.pm index 41614e1..07be1da 100644 --- a/08_disp_stdout.pm +++ b/05_disp_stdout.pm @@ -1,5 +1,6 @@ # console output for DCT, by Shiar +# 1.12.0 200411032130 - handle input via Term::ReadKey; define main loop # 1.11.0 200410152225 - class in file name, so check is not needed anymore # 1.10.1 200410142200 - startup message omitted (now shown by main) # 1.10.0 200410140120 - never clear screen (just let it scroll) @@ -10,13 +11,17 @@ use strict; use warnings; -#return 0 if $set{display}; -#$set{display} = "stdout"; +use Term::ReadKey; push @{$hook{init}}, sub { + ReadMode 3; # cbreak mode + # print "\ec"; # reset (clear screen, go home) # print "\e[4mDCT $::VERSION\e[24m "; # print intro (underlined) - END { print "\n"; } + END { + ReadMode 0; + print "\n"; + } $set{height} = $ENV{LINES}-2 if $ENV{LINES} and $ENV{LINES}>=3; $set{width} = $ENV{COLUMNS} if $ENV{COLUMNS}; @@ -37,9 +42,21 @@ push @{$hook{showentry}}, sub { print "\e[3G\e[K", $_[0]; # cursor to column #3; erase line }; # showentry +$hook{main} = sub { + while (1) { + draw(); + + my $key = ReadKey; # wait for user input + if ($key eq chr 27) { + $key .= $_ while defined ($_ = ReadKey(-1)); # read additional keys + } # escape sequence + onkey($key); + } # input loop +}; # main + return { author => "Shiar", title => "console output", - version => "1.11", + version => "1.12", };