File: cdemo.c

package info (click to toggle)
libcurses-perl 1.28-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze, wheezy
  • size: 888 kB
  • ctags: 1,323
  • sloc: ansic: 8,743; perl: 1,298; makefile: 7
file content (135 lines) | stat: -rw-r--r-- 2,482 bytes parent folder | download | duplicates (5)
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/*  cdemo.c
**
**  Copyright (c) 1994-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.
*/

#include "CursesDef.h"
#include "c-config.h"
#ifdef VMS
#include <unistd.h>  /* not in perl.h ??? */
#endif
#ifdef WIN32
#include <Windows.h>
#endif

static void
sleepSeconds(unsigned int seconds) {

#ifdef WIN32
    Sleep(seconds * 1000);
#else
    sleep(seconds);
#endif
}



int
main(unsigned int  const argc,
     const char ** const argv) {

    WINDOW *b;
    chtype ch;
    char str[250];
    int m, n;

    initscr();
    b = subwin(stdscr, 10, 20, 3, 3);

    noecho();
    cbreak();

    move(0, 0);
    addstr("ref b = <something C won't do>");
    move(1, 1);
    addstr("fooalpha");

#ifdef C_ATTRON
#  ifdef A_BOLD
    attron(A_BOLD);
#  endif
#endif
    move(2, 5);
    addstr("bold  ");
#ifdef C_ATTRON
#  ifdef A_REVERSE
    attron(A_REVERSE);
#  endif
#endif
    addstr("bold+reverse");
#ifdef C_ATTRSET
#  ifdef A_NORMAL
    attrset(A_NORMAL);
#  endif
#endif
    addstr("  normal  (if your curses can do these modes)");

    move(6, 1);
    addstr("do12345678901234567890n't worry be happy");
#ifdef C_BOX
    box(b, '|', '-');
#endif
    wstandout(b);
    move(2, 2);
    waddstr(b, "ping");
    wstandend(b);
    move(4, 4);
    waddstr(b, "pong");

    wmove(b, 3, 3);
    move(6, 3);
    wdeleteln(b);
    insertln();

    move(4, 5);
    wdelch(b);
    move(7, 8);
    insch('a');

#ifdef C_KEYPAD
    keypad(stdscr, 1);
#endif
    move(14, 0);
    addstr("hit a key: ");
    refresh();
    ch = getch();
    move(15, 0);
    printw("you typed: >>%c<<", ch);
    move(17, 0);
    addstr("enter string: ");
    refresh();
    getstr(str);

    move(18, 0);
    printw("you typed: >>%s<<", str);
    getyx(stdscr, m, n);
    move(19, 4);
    printw("y == %d (should be 18), x == %d", m, n);

    ch = mvinch(19, 7);
    move(20, 0);
    printw("The character at (19,7) is an '%c' (should be an '=')", ch);

    move(21, 0);
    addstr("testing KEY_*.  Hit the up arrow on your keyboard: ");
    refresh();
    ch = getch();

#ifdef KEY_UP
    if (ch == KEY_UP) { mvaddstr(22, 0, "KEY_UP was pressed!");         }
    else              { mvaddstr(22, 0, "Something else was pressed."); }
#else
    move(22, 0);
    addstr("You don't seem to have the KEY_UP macro");
#endif

    move(LINES - 1, 0);
    refresh();

    sleepSeconds(5);

    endwin();
}