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