release 1.11.2
[descalc.git] / 05_disp_curses.pm
1 # ncurses output for DCT, by Shiar
2
3 # 1.11.0 200410152225 - uses class in filename instead of $set{display} check
4 # 1.10.0 200410140120 - all output functions seperated from main
5
6 use strict;
7 use warnings;
8
9 use Curses;
10
11 push @{$hook{init}}, sub {
12         initscr;
13         END { endwin; } # restore terminal on quit
14
15         $set{height} = $LINES-2 if $LINES>=3;
16         $set{width} = $COLS if $COLS;
17 }; # init
18
19 push @{$hook{showerror}}, sub {
20         attron(A_REVERSE);
21         addstr(0, 0, shift);
22         attroff(A_REVERSE);
23         clrtoeol;
24         refresh;
25
26         ReadKey; # wait for confirm
27         1 while defined ReadKey(-1); # clear key buffer
28 }; # showerror
29
30 push @{$hook{showstack}}, sub {
31         for (0..@stack-1) {
32                 addstr($set{height}-$_, 1, "$_: ".showval($stack[$_], $set{base}));
33                 clrtoeol;
34         } # show stack
35         clrtoeol($set{height}-@stack, 1);
36 }; # showstack
37
38 push @{$hook{refresh}}, sub {
39         clear;
40         addstr($set{height}+1, 0, "> ");  # prompt
41 }; # refresh
42
43 push @{$hook{showentry}}, sub {
44         addstr($set{height}+1, 2, $_[0]);
45         clrtoeol;
46         refresh;
47 }; # showentry
48
49 return {
50         author  => "Shiar",
51         title   => "curses output",
52         version => "1.11",
53 };
54