]> ncurses.scripts.mit.edu Git - ncurses.git/blob - test/lrtest.c
ncurses 6.2 - patch 20200509
[ncurses.git] / test / lrtest.c
1 /****************************************************************************
2  * Copyright 2019,2020 Thomas E. Dickey                                     *
3  * Copyright 1998-2010,2017 Free Software Foundation, Inc.                  *
4  *                                                                          *
5  * Permission is hereby granted, free of charge, to any person obtaining a  *
6  * copy of this software and associated documentation files (the            *
7  * "Software"), to deal in the Software without restriction, including      *
8  * without limitation the rights to use, copy, modify, merge, publish,      *
9  * distribute, distribute with modifications, sublicense, and/or sell       *
10  * copies of the Software, and to permit persons to whom the Software is    *
11  * furnished to do so, subject to the following conditions:                 *
12  *                                                                          *
13  * The above copyright notice and this permission notice shall be included  *
14  * in all copies or substantial portions of the Software.                   *
15  *                                                                          *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
19  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
20  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
21  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
22  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
23  *                                                                          *
24  * Except as contained in this notice, the name(s) of the above copyright   *
25  * holders shall not be used in advertising or otherwise to promote the     *
26  * sale, use or other dealings in this Software without prior written       *
27  * authorization.                                                           *
28  ****************************************************************************/
29 /*
30  * Test lower-right-hand corner access
31  *
32  * originally by Eric S. Raymond <esr@thyrsus.com>, written for animation
33  * and resizing -T.Dickey
34  *
35  * This can't be part of the ncurses test-program, because ncurses rips off the
36  * bottom line to do labels.
37  *
38  * $Id: lrtest.c,v 1.27 2020/02/02 23:34:34 tom Exp $
39  */
40
41 #include <test.priv.h>
42
43 typedef struct {
44     int y, x, mode, dir, inc;
45     chtype value;
46 } MARK;
47
48 /*
49  * Make a couple of markers go 'round the border to demonstrate that we can
50  * really write to all positions properly.
51  */
52 static void
53 show(MARK *m)
54 {
55     MvAddCh(m->y, m->x, m->value);
56     if (m->mode == 0) {         /* along the x-direction */
57         m->x += m->inc;
58         if (m->x >= COLS) {
59             m->x = COLS - 1;
60             m->inc = -m->dir * m->inc;
61             m->y += m->inc;
62             m->mode = 1;
63         } else if (m->x < 0) {
64             m->x = 0;
65             m->inc = -m->dir * m->inc;
66             m->y += m->inc;
67             m->mode = 1;
68         }
69     } else {                    /* along the y-direction */
70         m->y += m->inc;
71         if (m->y >= LINES) {
72             m->y = LINES - 1;
73             m->inc = m->dir * m->inc;
74             m->x += m->inc;
75             m->mode = 0;
76         } else if (m->y < 0) {
77             m->y = 0;
78             m->inc = m->dir * m->inc;
79             m->x += m->inc;
80             m->mode = 0;
81         }
82     }
83 }
84
85 int
86 main(
87         int argc GCC_UNUSED,
88         char *argv[]GCC_UNUSED)
89 {
90     static MARK marks[] =
91     {
92         {0, 0, 0, -1, 1, '+' | A_BOLD},
93         {0, 0, 1, 1, 2, 'X'},
94         {0, 0, 1, -1, 3, 'Y'},
95         {0, 8, 0, -1, 1, '+' | A_BOLD},
96         {0, 9, 0, -1, 1, '+' | A_BOLD},
97         {1, 0, 1, 1, 1, '*' | A_REVERSE},
98         {2, 0, 1, 1, 1, '*' | A_REVERSE}
99     };
100
101     setlocale(LC_ALL, "");
102
103     initscr();
104     noecho();
105     cbreak();
106     nodelay(stdscr, TRUE);
107     curs_set(0);
108
109 #ifdef KEY_RESIZE
110     keypad(stdscr, TRUE);
111   restart:
112 #endif
113     move(LINES / 2 - 1, 4);
114     if (!(has_ic()
115 #if HAVE_SETUPTERM
116     /* see PutCharLR() */
117           || auto_right_margin
118           || (enter_am_mode && exit_am_mode)
119 #endif
120         )) {
121         addstr("Your terminal lacks the capabilities needed to address the\n");
122         move(LINES / 2, 4);
123         addstr("lower-right-hand corner of the screen.\n");
124     } else {
125         addstr("This is a test of access to the lower right corner.\n");
126         move(LINES / 2, 4);
127         addstr("If the top of the box is missing, the test failed.\n");
128         move(LINES / 2 + 1, 4);
129         addstr("Please report this (with a copy of your terminfo entry).\n");
130         move(LINES / 2 + 2, 4);
131         addstr("to the ncurses maintainers, at bug-ncurses@gnu.org.\n");
132     }
133
134     for (;;) {
135         int ch;
136         unsigned n;
137
138         box(stdscr, 0, 0);
139         for (n = 0; n < SIZEOF(marks); n++) {
140             show(&marks[n]);
141         }
142
143         if ((ch = getch()) > 0) {
144             if (ch == 'q')
145                 break;
146             else if (ch == 's')
147                 nodelay(stdscr, FALSE);
148             else if (ch == ' ')
149                 nodelay(stdscr, TRUE);
150 #ifdef TRACE
151             else if (ch == 'T')
152                 curses_trace(0);
153             else if (ch == 't')
154                 curses_trace(TRACE_CALLS | TRACE_ICALLS | TRACE_UPDATE);
155 #endif
156 #ifdef KEY_RESIZE
157             else if (ch == KEY_RESIZE) {
158                 for (n = 0; n < SIZEOF(marks); n++) {
159                     if (marks[n].mode == 0) {   /* moving along x-direction */
160                         if (marks[n].y)
161                             marks[n].y = LINES - 1;
162                     } else {
163                         if (marks[n].x)
164                             marks[n].x = COLS - 1;
165                     }
166                 }
167                 flash();
168                 erase();
169                 wrefresh(curscr);
170                 goto restart;
171             }
172 #endif
173         }
174         napms(50);
175         refresh();
176     }
177
178     stop_curses();
179     ExitProgram(EXIT_SUCCESS);
180 }
181
182 /* lrtest.c ends here */