1 /****************************************************************************
2 * Copyright (c) 2003-2017,2018 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: background.c,v 1.18 2018/11/24 20:28:45 tom Exp $
32 #define NEED_COLOR_CODE 1
33 #define NEED_COLOR_NAME 1
34 #include <color_name.h>
35 #include <dump_window.h>
37 static int default_bg = COLOR_BLACK;
38 static int default_fg = COLOR_WHITE;
47 if (pair_content(0, &f, &b) == ERR) {
48 printw("pair 0 contains no data\n");
50 printw("pair 0 contains (%d,%d)\n", (int) f, (int) b);
54 printw("Initializing pair 1 to red/%s\n", color_name(default_bg));
55 init_pair(1, COLOR_RED, (NCURSES_COLOR_T) default_bg);
56 bkgdset((chtype) (' ' | COLOR_PAIR(1)));
57 printw("RED/BLACK\n");
60 printw("Initializing pair 2 to %s/blue\n", color_name(default_fg));
61 init_pair(2, (NCURSES_COLOR_T) default_fg, COLOR_BLUE);
62 bkgdset((chtype) (' ' | COLOR_PAIR(2)));
63 printw("This line should be %s/blue\n", color_name(default_fg));
66 printw("Initializing pair 3 to %s/cyan (ACS_HLINE)\n", color_name(default_fg));
67 init_pair(3, (NCURSES_COLOR_T) default_fg, COLOR_CYAN);
68 printw("...and drawing a box which should be followed by lines\n");
69 bkgdset(ACS_HLINE | (chtype) COLOR_PAIR(3));
71 * Characters from vt100 line-drawing should be mapped to line-drawing,
72 * since A_ALTCHARSET is set in the background, and the character part
73 * of the background is replaced by the nonblank characters written.
75 * Characters not in the line-drawing range are usually sent as-is.
77 * With SVr4 curses it is possible to rely on this to mix uppercase text
78 * with the (lowercase) line-drawing characters. ncurses uses some of
79 * the uppercase characters for encoding thick- and double-lines.
82 mvprintw(row++, 10, "l");
83 for (chr = 0; chr < 32; ++chr)
89 mvprintw(row++, 10, "x");
90 AddCh((chr == 127) ? ' ' : chr);
91 if ((++chr % 32) == 0)
94 mvprintw(row++, 10, "m");
95 for (chr = 0; chr < 32; ++chr)
100 bkgdset((chtype) (' ' | COLOR_PAIR(0)));
101 printw("Default Colors\n");
104 printw("Resetting colors to pair 1\n");
105 bkgdset((chtype) (' ' | COLOR_PAIR(1)));
106 printw("This line should be red/%s\n", color_name(default_bg));
109 printw("Setting screen to pair 0\n");
110 bkgd((chtype) (' ' | COLOR_PAIR(0)));
113 printw("Setting screen to pair 1\n");
114 bkgd((chtype) (' ' | COLOR_PAIR(1)));
117 printw("Setting screen to pair 2\n");
118 bkgd((chtype) (' ' | COLOR_PAIR(2)));
121 printw("Setting screen to pair 3\n");
122 bkgd((chtype) (' ' | COLOR_PAIR(3)));
125 printw("Setting screen to pair 0\n");
126 bkgd((chtype) (' ' | COLOR_PAIR(0)));
133 static const char *msg[] =
135 "Usage: background [options]"
138 #if HAVE_ASSUME_DEFAULT_COLORS
139 ," -a invoke assume_default_colors, repeat to use in init_pair"
141 ," -b XXX specify background color"
142 #if HAVE_USE_DEFAULT_COLORS
143 ," -d invoke use_default_colors, repeat to use in init_pair"
145 ," -f XXX specify foreground color"
149 for (n = 0; n < SIZEOF(msg); n++)
150 fprintf(stderr, "%s\n", msg[n]);
152 ExitProgram(EXIT_FAILURE);
156 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
158 #if HAVE_ASSUME_DEFAULT_COLORS
161 #if HAVE_USE_DEFAULT_COLORS
166 setlocale(LC_ALL, "");
168 while ((n = getopt(argc, argv, "ab:df:l:")) != -1) {
170 #if HAVE_ASSUME_DEFAULT_COLORS
176 default_bg = color_code(optarg);
178 #if HAVE_USE_DEFAULT_COLORS
184 default_fg = color_code(optarg);
187 if (!open_dump(optarg))
194 #if HAVE_USE_DEFAULT_COLORS && HAVE_ASSUME_DEFAULT_COLORS
195 if (a_option && d_option) {
196 fprintf(stderr, "Use either -a or -d option, but not both\n");
197 ExitProgram(EXIT_FAILURE);
208 #if HAVE_USE_DEFAULT_COLORS
210 printw("Using default colors...\n");
211 use_default_colors();
218 #if HAVE_ASSUME_DEFAULT_COLORS
220 printw("Using assumed colors %s/%s...\n",
221 color_name(default_fg),
222 color_name(default_bg));
223 assume_default_colors(default_fg, default_bg);
234 printw("This demo requires a color terminal");
239 ExitProgram(EXIT_SUCCESS);