1 /****************************************************************************
2 * Copyright 2021 Thomas E. Dickey *
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: back_ground.c,v 1.5 2021/02/20 12:23:21 tom Exp $
32 #include <test.priv.h>
36 #define NEED_COLOR_CODE 1
37 #define NEED_COLOR_NAME 1
38 #include <color_name.h>
39 #include <dump_window.h>
41 static int default_bg = COLOR_BLACK;
42 static int default_fg = COLOR_WHITE;
43 static wchar_t wide_fill = L' ';
46 decode_wchar(const char *value)
52 if (!strncmp(value, "U+", 2)) {
56 result = strtol(value, &next, radix);
57 if (next == value || (next == NULL || *next != '\0')) {
58 fprintf(stderr, "decoding wchar_t: %s\n", value);
61 return (wchar_t) result;
74 if (pair_content(0, &f, &b) == ERR) {
75 printw("pair 0 contains no data\n");
77 printw("pair 0 contains (%d,%d)\n", (int) f, (int) b);
84 printw("Initializing pair 1 to red/%s\n", color_name(default_bg));
85 init_pair(1, COLOR_RED, (NCURSES_COLOR_T) default_bg);
86 setcchar(&data, blank, A_NORMAL, 1, NULL);
88 printw("RED/BLACK\n");
91 printw("Initializing pair 2 to %s/blue\n", color_name(default_fg));
92 init_pair(2, (NCURSES_COLOR_T) default_fg, COLOR_BLUE);
93 setcchar(&data, blank, A_NORMAL, 2, NULL);
95 printw("This line should be %s/blue\n", color_name(default_fg));
98 printw("Initializing pair 3 to %s/cyan (ACS_HLINE)\n", color_name(default_fg));
99 init_pair(3, (NCURSES_COLOR_T) default_fg, COLOR_CYAN);
100 printw("...and drawing a box which should be followed by lines\n");
101 graphics[0] = ACS_HLINE & A_CHARTEXT;
103 setcchar(&data, graphics, A_ALTCHARSET, 3, NULL);
106 * Characters from vt100 line-drawing should be mapped to line-drawing,
107 * since A_ALTCHARSET is set in the background, and the character part
108 * of the background is replaced by the nonblank characters written.
110 * Characters not in the line-drawing range are usually sent as-is.
112 * With SVr4 curses it is possible to rely on this to mix uppercase text
113 * with the (lowercase) line-drawing characters. ncurses uses some of
114 * the uppercase characters for encoding thick- and double-lines.
117 mvprintw(row++, 10, "l");
118 for (chr = 0; chr < 32; ++chr)
124 mvprintw(row++, 10, "x");
125 AddCh((chr == 127) ? ' ' : chr);
126 if ((++chr % 32) == 0)
129 mvprintw(row++, 10, "m");
130 for (chr = 0; chr < 32; ++chr)
135 setcchar(&data, blank, A_NORMAL, 0, NULL);
137 printw("Default Colors\n");
140 printw("Resetting colors to pair 1\n");
141 setcchar(&data, blank, A_NORMAL, 1, NULL);
143 printw("This line should be red/%s\n", color_name(default_bg));
146 printw("Setting screen to pair 0\n");
147 setcchar(&data, blank, A_NORMAL, 0, NULL);
151 printw("Setting screen to pair 1\n");
152 setcchar(&data, blank, A_NORMAL, 1, NULL);
156 printw("Setting screen to pair 2\n");
157 setcchar(&data, blank, A_NORMAL, 2, NULL);
161 printw("Setting screen to pair 3\n");
162 setcchar(&data, blank, A_NORMAL, 3, NULL);
166 printw("Setting screen to pair 0\n");
167 setcchar(&data, blank, A_NORMAL, 0, NULL);
175 static const char *msg[] =
177 "Usage: background [options]"
180 #if HAVE_ASSUME_DEFAULT_COLORS
181 ," -a invoke assume_default_colors, repeat to use in init_pair"
183 ," -b XXX specify background color"
184 #if HAVE_USE_DEFAULT_COLORS
185 ," -d invoke use_default_colors, repeat to use in init_pair"
187 ," -f XXX specify foreground color"
188 ," -l FILE log window-dumps to this file"
189 ," -w fill background with stipple pattern"
190 ," -W CODE fill background with this Unicode value"
194 for (n = 0; n < SIZEOF(msg); n++)
195 fprintf(stderr, "%s\n", msg[n]);
197 ExitProgram(EXIT_FAILURE);
201 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
203 #if HAVE_ASSUME_DEFAULT_COLORS
206 #if HAVE_USE_DEFAULT_COLORS
211 setlocale(LC_ALL, "");
213 while ((n = getopt(argc, argv, "ab:df:l:wW:")) != -1) {
215 #if HAVE_ASSUME_DEFAULT_COLORS
221 default_bg = color_code(optarg);
223 #if HAVE_USE_DEFAULT_COLORS
229 default_fg = color_code(optarg);
232 if (!open_dump(optarg))
236 wide_fill = L'\u2591';
239 wide_fill = decode_wchar(optarg);
245 #if HAVE_USE_DEFAULT_COLORS && HAVE_ASSUME_DEFAULT_COLORS
246 if (a_option && d_option) {
247 fprintf(stderr, "Use either -a or -d option, but not both\n");
248 ExitProgram(EXIT_FAILURE);
259 #if HAVE_USE_DEFAULT_COLORS
261 printw("Using default colors...\n");
262 use_default_colors();
269 #if HAVE_ASSUME_DEFAULT_COLORS
271 printw("Using assumed colors %s/%s...\n",
272 color_name(default_fg),
273 color_name(default_bg));
274 assume_default_colors(default_fg, default_bg);
285 printw("This demo requires a color terminal");
290 ExitProgram(EXIT_SUCCESS);
297 printf("This program requires the wide-curses library\n");
298 ExitProgram(EXIT_FAILURE);
300 #endif /* USE_WIDEC_SUPPORT */