1 /****************************************************************************
2 * Copyright (c) 2006,2007 Free Software Foundation, Inc. *
4 * Permission is hereby granted, free of charge, to any person obtaining a *
5 * copy of this software and associated documentation files (the *
6 * "Software"), to deal in the Software without restriction, including *
7 * without limitation the rights to use, copy, modify, merge, publish, *
8 * distribute, distribute with modifications, sublicense, and/or sell *
9 * copies of the Software, and to permit persons to whom the Software is *
10 * furnished to do so, subject to the following conditions: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
18 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
23 * Except as contained in this notice, the name(s) of the above copyright *
24 * holders shall not be used in advertising or otherwise to promote the *
25 * sale, use or other dealings in this Software without prior written *
27 ****************************************************************************/
29 * $Id: chgat.c,v 1.6 2007/01/06 23:28:46 tom Exp $
31 * test-driver for chgat/wchgat/mvchgat/mvwchgat
34 #include <test.priv.h>
38 #define SHOW(n) ((n) == ERR ? "ERR" : "OK")
39 #define COLOR_DEFAULT (-1)
41 #if defined(NCURSES_VERSION_PATCH) && NCURSES_VERSION_PATCH < 20060715
42 #define touch_if_needed(win, row) touchline(win, row, 1)
44 #define touch_if_needed(win, row) /* nothing */
62 color_params(unsigned state, int *pair)
70 { 0, COLOR_DEFAULT, COLOR_DEFAULT, "default" },
71 { 1, COLOR_RED, COLOR_BLACK, "red/black" },
72 { 2, COLOR_WHITE, COLOR_BLUE, "white/blue" },
76 static bool first = TRUE;
77 const char *result = 0;
84 for (n = 0; n < SIZEOF(table); ++n) {
85 init_pair(table[n].pair, table[n].fg, table[n].bg);
88 if (state < SIZEOF(table)) {
89 *pair = table[state].pair;
90 result = table[state].msg;
97 video_params(unsigned state, int *attr)
104 { A_NORMAL, "normal" },
106 { A_REVERSE, "reverse" },
107 { A_UNDERLINE, "underline" },
108 { A_BLINK, "blink" },
112 const char *result = 0;
114 if (state < SIZEOF(table)) {
115 *attr = table[state].attr;
116 result = table[state].msg;
121 /* fill the window with a test-pattern */
123 fill_window(WINDOW *win)
129 while (waddstr(win, "0123456789 abcdefghijklmnopqrstuvwxyz ") != ERR) {
135 show_status(WINDOW *win, STATUS * sp)
141 wprintw(win, "Count %d", sp->count);
143 wprintw(win, " Video %s", sp->v_msg);
145 wprintw(win, " Color %s", sp->c_msg);
151 do_subwindow(WINDOW *win, STATUS * sp, void func(WINDOW *))
153 WINDOW *win1 = newwin(sp->y_max - 2, sp->x_max - 2,
154 sp->y_beg + 1, sp->x_beg + 1);
156 if (win1 != 0 && sp->y_max > 4 && sp->x_max > 4) {
157 WINDOW *win2 = derwin(win1, sp->y_max - 4, sp->x_max - 4, 1, 1);
176 init_status(WINDOW *win, STATUS * sp)
178 memset(sp, 0, sizeof(*sp));
186 getbegyx(win, sp->y_beg, sp->x_beg);
187 getmaxyx(win, sp->y_max, sp->x_max);
191 show_help(WINDOW *win)
193 static const char *table[] =
196 ,"Use h/j/k/l or arrow keys to move the cursor."
197 ,"Set the count parameter for chgat by entering digits 0-9."
200 ,"space toggles through the set of video attributes and colors."
201 ,"t touches (forces repaint) of the current line."
202 ,". calls *chgat at the current position with the given count."
203 ,", calls *chgat at the window beginning with the given count."
204 ,"= resets count to zero."
206 ,"? shows this help-window"
214 getmaxyx(win, y_max, x_max);
215 for (row = 0; row < (int) SIZEOF(table) && row < y_max; ++row) {
216 mvwprintw(win, row, 0, "%.*s", x_max, table[row]);
218 while (wgetch(win) != 'q')
223 update_status(WINDOW *win, STATUS * sp)
226 case ' ': /* next test-iteration */
228 if ((sp->c_msg = color_params(++(sp->c), &(sp->pair))) == 0) {
229 sp->c_msg = color_params(sp->c = 0, &(sp->pair));
230 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
231 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
235 if ((sp->v_msg = video_params(++(sp->v), &(sp->attr))) == 0) {
236 sp->v_msg = video_params(sp->v = 0, &(sp->attr));
240 show_status(win, sp);
245 wmove(win, sp->y_val, --(sp->x_val));
249 if (sp->y_val < sp->y_max)
250 wmove(win, ++(sp->y_val), sp->x_val);
255 wmove(win, --(sp->y_val), sp->x_val);
259 if (sp->x_val < sp->x_max)
260 wmove(win, sp->y_val, ++(sp->x_val));
263 touchline(win, sp->y_val, 1);
267 show_status(win, sp);
270 sp->count = -(sp->count);
271 show_status(win, sp);
274 do_subwindow(win, sp, show_help);
277 if (isdigit(sp->ch)) {
278 sp->count = (sp->count * 10) + (sp->ch - '0');
279 show_status(win, sp);
288 test_wchgat(WINDOW *win)
292 init_status(win, &st);
296 case '.': /* change from current position */
297 wchgat(win, st.count, st.attr, st.pair, (void *) 0);
298 touch_if_needed(win, st.y_val);
300 case ',': /* change from beginning of window */
301 mvwchgat(win, 0, 0, st.count, st.attr, st.pair, (void *) 0);
302 touch_if_needed(win, 0);
303 wmove(win, st.y_val, st.x_val);
306 do_subwindow(win, &st, test_wchgat);
311 update_status(win, &st);
314 } while ((st.ch = wgetch(win)) != ERR);
322 init_status(stdscr, &st);
326 case '.': /* change from current position */
327 chgat(st.count, st.attr, st.pair, (void *) 0);
328 touch_if_needed(stdscr, st.y_val);
330 case ',': /* change from beginning of window */
331 mvchgat(0, 0, st.count, st.attr, st.pair, (void *) 0);
332 touch_if_needed(stdscr, 0);
333 move(st.y_val, st.x_val);
336 do_subwindow(stdscr, &st, test_wchgat);
341 update_status(stdscr, &st);
344 } while ((st.ch = getch()) != ERR);
348 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
357 ExitProgram(EXIT_SUCCESS);
364 printf("This program requires the curses chgat function\n");
365 ExitProgram(EXIT_FAILURE);