File: demo2

package info (click to toggle)
libcurses-perl 1.37-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 932 kB
  • sloc: ansic: 9,143; perl: 1,432; makefile: 12
file content (78 lines) | stat: -rwxr-xr-x 1,744 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#! /usr/bin/perl
##
##  demo2  -- play around with some weird stuff, use object model
##
##  Copyright (c) 2000  William Setzer
##
##  You may distribute under the terms of either the Artistic License
##  or the GNU General Public License, as specified in the README file.

use ExtUtils::testlib;
use Curses;

sub message {
    my $win = shift;

    $win->addstr(0, 0, "@_\n");
    $win->addstr(3, 4, "-->");
    $win->move($LINES - 1, 0);
    $win->refresh();
    sleep 2;
}

my $win = Curses->new  or die "Can't get new window\n";

##  You have to pack chtypes.  Be sure to get that trailing zero.
#
eval {
    my $chstr = pack "I*",
        ACS_BLOCK, ord(A), ACS_CKBOARD, ord(B), ACS_PLMINUS, 0;

    $win->addchstr(3, 8, $chstr);
    message $win, "addchstr: block, A, checkerboard, B, plus/minus";
};

$win->clrtoeol(3, 8);

##  Attrs
#
eval {
    $win->attron(A_BOLD|A_UNDERLINE);
    $win->addstr(3, 8, "hello");
    $win->attrset(0);
    message $win, "attr: BOLD|UNDERLINE";
    $win->attron(A_BOLD|A_UNDERLINE);
    $win->attroff(A_BOLD);
    $win->addstr(3, 8, "hello");
    $win->attrset(0);
    message $win, "attr: UNDERLINE";
};

$win->clrtoeol(3, 8);

##  Color
#
eval {
    start_color;
    init_pair 1, COLOR_GREEN,  COLOR_BLACK;
    init_pair 2, COLOR_RED,    COLOR_BLACK;

    my $GREEN = COLOR_PAIR(1);
    my $RED   = COLOR_PAIR(2);

    $win->attron($RED);
    $win->addstr(3, 8, "hello");
    $win->attroff($RED);
    message $win, "color: red";
    $win->attron($GREEN);
    $win->addstr(3, 8, "hello");
    $win->attroff($GREEN);
    message $win, "color: green";

    my $chstr = $RED | ACS_CKBOARD;
    $win->clrtoeol(3, 8);
    $win->addch(3, 8, $chstr);
    message $win, "addch: red checkerboard";
};

endwin();