Debian Codegraph @

demo2

raw
1 #! /usr/bin/perl
2 ##
3 ## demo2 -- play around with some weird stuff, use object model
4 ##
5 ## Copyright (c) 2000 William Setzer
6 ##
7 ## You may distribute under the terms of either the Artistic License
8 ## or the GNU General Public License, as specified in the README file.
9
10 use ExtUtils::testlib;
11 use Curses;
12
13 sub message {
14 my $win = shift;
15
16 $win->addstr(0, 0, "@_\n");
17 $win->addstr(3, 4, "-->");
18 $win->move($LINES - 1, 0);
19 $win->refresh();
20 sleep 2;
21 }
22
23 my $win = Curses->new or die "Can't get new window\n";
24
25 ## You have to pack chtypes. Be sure to get that trailing zero.
26 #
27 eval {
28 my $chstr = pack "I*",
29 ACS_BLOCK, ord(A), ACS_CKBOARD, ord(B), ACS_PLMINUS, 0;
30
31 $win->addchstr(3, 8, $chstr);
32 message $win, "addchstr: block, A, checkerboard, B, plus/minus";
33 };
34
35 $win->clrtoeol(3, 8);
36
37 ## Attrs
38 #
39 eval {
40 $win->attron(A_BOLD|A_UNDERLINE);
41 $win->addstr(3, 8, "hello");
42 $win->attrset(0);
43 message $win, "attr: BOLD|UNDERLINE";
44 $win->attron(A_BOLD|A_UNDERLINE);
45 $win->attroff(A_BOLD);
46 $win->addstr(3, 8, "hello");
47 $win->attrset(0);
48 message $win, "attr: UNDERLINE";
49 };
50
51 $win->clrtoeol(3, 8);
52
53 ## Color
54 #
55 eval {
56 start_color;
57 init_pair 1, COLOR_GREEN, COLOR_BLACK;
58 init_pair 2, COLOR_RED, COLOR_BLACK;
59
60 my $GREEN = COLOR_PAIR(1);
61 my $RED = COLOR_PAIR(2);
62
63 $win->attron($RED);
64 $win->addstr(3, 8, "hello");
65 $win->attroff($RED);
66 message $win, "color: red";
67 $win->attron($GREEN);
68 $win->addstr(3, 8, "hello");
69 $win->attroff($GREEN);
70 message $win, "color: green";
71
72 my $chstr = $RED | ACS_CKBOARD;
73 $win->clrtoeol(3, 8);
74 $win->addch(3, 8, $chstr);
75 message $win, "addch: red checkerboard";
76 };
77
78 endwin();