vendor/NCURSES: Remove version tag.
[dragonfly.git] / contrib / ncurses / test / demo_keyok.c
1 /*
2  * $Id: demo_keyok.c,v 1.3 2003/05/17 23:18:34 tom Exp $
3  *
4  * Demonstrate the keyok() function.
5  * Thomas Dickey - 2002/11/23
6  */
7
8 #include <test.priv.h>
9
10 #if defined(NCURSES_VERSION) && NCURSES_EXT_FUNCS
11 int
12 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
13 {
14     int lastch = ERR;
15     int ch;
16     WINDOW *win;
17
18     initscr();
19     (void) cbreak();            /* take input chars one at a time, no wait for \n */
20     (void) noecho();            /* don't echo input */
21
22     printw("Typing any function key will disable it, but typing it twice in\n");
23     printw("a row will turn it back on (just for a demo).");
24     refresh();
25
26     win = newwin(LINES - 2, COLS, 2, 0);
27     scrollok(win, TRUE);
28     keypad(win, TRUE);
29     wmove(win, 0, 0);
30
31     while ((ch = wgetch(win)) != ERR) {
32         const char *name = keyname(ch);
33         wprintw(win, "Keycode %d, name %s\n",
34                 ch,
35                 name != 0 ? name : "<null>");
36         wclrtoeol(win);
37         wrefresh(win);
38         if (ch >= KEY_MIN) {
39             keyok(ch, FALSE);
40             lastch = ch;
41         } else if (lastch >= KEY_MIN) {
42             keyok(lastch, TRUE);
43         }
44     }
45     endwin();
46     return EXIT_SUCCESS;
47 }
48 #else
49 int
50 main(void)
51 {
52     printf("This program requires the ncurses library\n");
53     ExitProgram(EXIT_FAILURE);
54 }
55 #endif