]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/lrtest.c
ncurses 5.2
[ncurses.git] / test / lrtest.c
1 /*
2  * Test lower-right-hand corner access
3  *
4  * by Eric S. Raymond <esr@thyrsus.com>
5  *
6  * This can't be part of the ncurses test-program, because ncurses rips off the
7  * bottom line to do labels.
8  *
9  * $Id: lrtest.c,v 0.14 1999/10/23 19:44:35 tom Exp $
10  */
11
12 #include <test.priv.h>
13 #include <term.h>
14
15 typedef struct {
16     int y, x, mode, dir, inc;
17     chtype value;
18 } MARK;
19
20 /*
21  * Make a couple of markers go 'round the border to demonstrate that we can
22  * really write to all positions properly.
23  */
24 static void
25 show(MARK * m)
26 {
27     mvaddch(m->y, m->x, m->value);
28     if (m->mode == 0) {         /* along the x-direction */
29         m->x += m->inc;
30         if (m->x >= COLS) {
31             m->x = COLS - 1;
32             m->inc = -m->dir * m->inc;
33             m->y += m->inc;
34             m->mode = 1;
35         } else if (m->x < 0) {
36             m->x = 0;
37             m->inc = -m->dir * m->inc;
38             m->y += m->inc;
39             m->mode = 1;
40         }
41     } else {                    /* along the y-direction */
42         m->y += m->inc;
43         if (m->y >= LINES) {
44             m->y = LINES - 1;
45             m->inc = m->dir * m->inc;
46             m->x += m->inc;
47             m->mode = 0;
48         } else if (m->y < 0) {
49             m->y = 0;
50             m->inc = m->dir * m->inc;
51             m->x += m->inc;
52             m->mode = 0;
53         }
54     }
55 }
56
57 int
58 main(
59     int argc GCC_UNUSED,
60     char *argv[]GCC_UNUSED)
61 {
62     static MARK marks[] =
63     {
64         {0, 0, 0, -1, 1, '+' | A_BOLD},
65         {0, 0, 1, 1, 2, 'X'},
66         {0, 0, 1, -1, 3, 'Y'},
67         {0, 8, 0, -1, 1, '+' | A_BOLD},
68         {0, 9, 0, -1, 1, '+' | A_BOLD},
69         {1, 0, 1, 1, 1, '*' | A_REVERSE},
70         {2, 0, 1, 1, 1, '*' | A_REVERSE}
71     };
72
73     initscr();
74     noecho();
75     cbreak();
76     nodelay(stdscr, TRUE);
77     curs_set(0);
78
79 #ifdef KEY_RESIZE
80     keypad(stdscr, TRUE);
81   restart:
82 #endif
83     move(LINES / 2 - 1, 4);
84     if (!(has_ic()
85     /* see PutCharLR() */
86             || auto_right_margin
87             || (enter_am_mode && exit_am_mode))) {
88         addstr("Your terminal lacks the capabilities needed to address the\n");
89         move(LINES / 2, 4);
90         addstr("lower-right-hand corner of the screen.\n");
91     } else {
92         addstr("This is a test of access to the lower right corner.\n");
93         move(LINES / 2, 4);
94         addstr("If the top of the box is missing, the test failed.\n");
95         move(LINES / 2 + 1, 4);
96         addstr("Please report this (with a copy of your terminfo entry).\n");
97         move(LINES / 2 + 2, 4);
98         addstr("to the ncurses maintainers, at bug-ncurses@gnu.org.\n");
99     }
100
101     for (;;) {
102         int ch;
103         unsigned n;
104
105         box(stdscr, 0, 0);
106         for (n = 0; n < sizeof(marks) / sizeof(marks[0]); n++) {
107             show(&marks[n]);
108         }
109
110         if ((ch = getch()) > 0) {
111             if (ch == 'q')
112                 break;
113             else if (ch == 's')
114                 nodelay(stdscr, FALSE);
115             else if (ch == ' ')
116                 nodelay(stdscr, TRUE);
117 #ifdef KEY_RESIZE
118             else if (ch == KEY_RESIZE) {
119                 erase();
120                 goto restart;
121             }
122 #endif
123         }
124         napms(50);
125     }
126
127     curs_set(1);
128     endwin();
129     return 0;
130 }
131
132 /* lrtest.c ends here */