1 /****************************************************************************
2 * Copyright (c) 2003-2006,2011 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.9 2011/04/23 21:16:38 tom Exp $
32 #define NEED_COLOR_CODE 1
33 #define NEED_COLOR_NAME 1
34 #include <color_name.h>
36 static int default_bg = COLOR_BLACK;
37 static int default_fg = COLOR_WHITE;
44 pair_content(0, &f, &b);
45 printw("pair 0 contains (%d,%d)\n", f, b);
48 printw("Initializing pair 1 to red/%s\n", color_name(default_bg));
49 init_pair(1, COLOR_RED, (short) default_bg);
50 bkgdset(' ' | COLOR_PAIR(1));
51 printw("RED/BLACK\n");
54 printw("Initializing pair 2 to %s/blue\n", color_name(default_fg));
55 init_pair(2, (short) default_fg, COLOR_BLUE);
56 bkgdset(' ' | COLOR_PAIR(2));
57 printw("This line should be %s/blue\n", color_name(default_fg));
60 printw("Resetting colors to pair 0\n");
61 bkgdset(' ' | COLOR_PAIR(0));
62 printw("Default Colors\n");
65 printw("Resetting colors to pair 1\n");
66 bkgdset(' ' | COLOR_PAIR(1));
67 printw("This line should be red/%s\n", color_name(default_bg));
70 printw("Setting screen to pair 0\n");
71 bkgd(' ' | COLOR_PAIR(0));
74 printw("Setting screen to pair 1\n");
75 bkgd(' ' | COLOR_PAIR(1));
78 printw("Setting screen to pair 2\n");
79 bkgd(' ' | COLOR_PAIR(2));
82 printw("Setting screen to pair 0\n");
83 bkgd(' ' | COLOR_PAIR(0));
90 static const char *msg[] =
92 "Usage: background [options]"
95 #if HAVE_ASSUME_DEFAULT_COLORS
96 ," -a invoke assume_default_colors, repeat to use in init_pair"
98 ," -b XXX specify background color"
99 #if HAVE_USE_DEFAULT_COLORS
100 ," -d invoke use_default_colors, repeat to use in init_pair"
102 ," -f XXX specify foreground color"
106 for (n = 0; n < SIZEOF(msg); n++)
107 fprintf(stderr, "%s\n", msg[n]);
109 ExitProgram(EXIT_FAILURE);
113 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
115 #if HAVE_ASSUME_DEFAULT_COLORS
118 #if HAVE_USE_DEFAULT_COLORS
123 while ((n = getopt(argc, argv, "ab:df:")) != -1) {
125 #if HAVE_ASSUME_DEFAULT_COLORS
131 default_bg = color_code(optarg);
133 #if HAVE_USE_DEFAULT_COLORS
139 default_fg = color_code(optarg);
145 #if HAVE_USE_DEFAULT_COLORS && HAVE_ASSUME_DEFAULT_COLORS
146 if (a_option && d_option) {
147 fprintf(stderr, "Use either -a or -d option, but not both\n");
148 ExitProgram(EXIT_FAILURE);
159 #if HAVE_USE_DEFAULT_COLORS
161 printw("Using default colors...\n");
162 use_default_colors();
169 #if HAVE_ASSUME_DEFAULT_COLORS
171 printw("Using assumed colors %s/%s...\n",
172 color_name(default_fg),
173 color_name(default_bg));
174 assume_default_colors(default_fg, default_bg);
185 printw("This demo requires a color terminal");
190 ExitProgram(EXIT_SUCCESS);