]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/lrtest.c
ncurses 5.3
[ncurses.git] / test / lrtest.c
1 /*
2  * Test lower-right-hand corner access
3  *
4  * originally by Eric S. Raymond <esr@thyrsus.com>, written for animation
5  * and resizing -TD
6  *
7  * This can't be part of the ncurses test-program, because ncurses rips off the
8  * bottom line to do labels.
9  *
10  * $Id: lrtest.c,v 1.19 2002/07/13 16:55:50 tom Exp $
11  */
12
13 #include <test.priv.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     setlocale(LC_ALL, "");
74
75     initscr();
76     noecho();
77     cbreak();
78     nodelay(stdscr, TRUE);
79     curs_set(0);
80
81 #ifdef KEY_RESIZE
82     keypad(stdscr, TRUE);
83   restart:
84 #endif
85     move(LINES / 2 - 1, 4);
86     if (!(has_ic()
87     /* see PutCharLR() */
88           || auto_right_margin
89           || (enter_am_mode && exit_am_mode))) {
90         addstr("Your terminal lacks the capabilities needed to address the\n");
91         move(LINES / 2, 4);
92         addstr("lower-right-hand corner of the screen.\n");
93     } else {
94         addstr("This is a test of access to the lower right corner.\n");
95         move(LINES / 2, 4);
96         addstr("If the top of the box is missing, the test failed.\n");
97         move(LINES / 2 + 1, 4);
98         addstr("Please report this (with a copy of your terminfo entry).\n");
99         move(LINES / 2 + 2, 4);
100         addstr("to the ncurses maintainers, at bug-ncurses@gnu.org.\n");
101     }
102
103     for (;;) {
104         int ch;
105         unsigned n;
106
107         box(stdscr, 0, 0);
108         for (n = 0; n < SIZEOF(marks); n++) {
109             show(&marks[n]);
110         }
111
112         if ((ch = getch()) > 0) {
113             if (ch == 'q')
114                 break;
115             else if (ch == 's')
116                 nodelay(stdscr, FALSE);
117             else if (ch == ' ')
118                 nodelay(stdscr, TRUE);
119 #ifdef TRACE
120             else if (ch == 'T')
121                 trace(0);
122             else if (ch == 't')
123                 trace(TRACE_CALLS|TRACE_ICALLS|TRACE_UPDATE);
124 #endif
125 #ifdef KEY_RESIZE
126             else if (ch == KEY_RESIZE) {
127                 for (n = 0; n < SIZEOF(marks); n++) {
128                     if (marks[n].mode == 0) {   /* moving along x-direction */
129                         if (marks[n].y)
130                             marks[n].y = LINES - 1;
131                     } else {
132                         if (marks[n].x)
133                             marks[n].x = COLS - 1;
134                     }
135                 }
136                 flash();
137                 erase();
138                 wrefresh(curscr);
139                 goto restart;
140             }
141 #endif
142         }
143         napms(50);
144         refresh();
145     }
146
147     curs_set(1);
148     endwin();
149     ExitProgram(EXIT_SUCCESS);
150 }
151
152 /* lrtest.c ends here */