aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/kconfig/lxdialog/util.c
diff options
context:
space:
mode:
authorSam Ravnborg <sam@mars.ravnborg.org>2006-07-24 15:40:46 -0400
committerSam Ravnborg <sam@neptun.ravnborg.org>2006-09-30 05:19:19 -0400
commit98e5a1579e7d34fe3803240750a1c48efcd9cb15 (patch)
tree433f6b354eb0bb6fa01f325237f9f4651bf5ac9f /scripts/kconfig/lxdialog/util.c
parentbf603625660b1742004bf86432ce3c210d14d4fd (diff)
kconfig/lxdialog: refactor color support
Clean up and refactor color support. All color support are now in util.c including color definitions. In the process introduced a global variable named 'dlg' which is used all over to set color - thats the reason why all files are changed. Signed-off-by: Sam Ravnborg <sam@ravnborg.org>
Diffstat (limited to 'scripts/kconfig/lxdialog/util.c')
-rw-r--r--scripts/kconfig/lxdialog/util.c259
1 files changed, 147 insertions, 112 deletions
diff --git a/scripts/kconfig/lxdialog/util.c b/scripts/kconfig/lxdialog/util.c
index f82cebb9ff06..08f98b1c4bb3 100644
--- a/scripts/kconfig/lxdialog/util.c
+++ b/scripts/kconfig/lxdialog/util.c
@@ -21,85 +21,141 @@
21 21
22#include "dialog.h" 22#include "dialog.h"
23 23
24/* use colors by default? */ 24struct dialog_info dlg;
25bool use_colors = 1;
26 25
27const char *backtitle = NULL; 26static void set_mono_theme(void)
27{
28 dlg.screen.atr = A_NORMAL;
29 dlg.shadow.atr = A_NORMAL;
30 dlg.dialog.atr = A_NORMAL;
31 dlg.title.atr = A_BOLD;
32 dlg.border.atr = A_NORMAL;
33 dlg.button_active.atr = A_REVERSE;
34 dlg.button_inactive.atr = A_DIM;
35 dlg.button_key_active.atr = A_REVERSE;
36 dlg.button_key_inactive.atr = A_BOLD;
37 dlg.button_label_active.atr = A_REVERSE;
38 dlg.button_label_inactive.atr = A_NORMAL;
39 dlg.inputbox.atr = A_NORMAL;
40 dlg.inputbox_border.atr = A_NORMAL;
41 dlg.searchbox.atr = A_NORMAL;
42 dlg.searchbox_title.atr = A_BOLD;
43 dlg.searchbox_border.atr = A_NORMAL;
44 dlg.position_indicator.atr = A_BOLD;
45 dlg.menubox.atr = A_NORMAL;
46 dlg.menubox_border.atr = A_NORMAL;
47 dlg.item.atr = A_NORMAL;
48 dlg.item_selected.atr = A_REVERSE;
49 dlg.tag.atr = A_BOLD;
50 dlg.tag_selected.atr = A_REVERSE;
51 dlg.tag_key.atr = A_BOLD;
52 dlg.tag_key_selected.atr = A_REVERSE;
53 dlg.check.atr = A_BOLD;
54 dlg.check_selected.atr = A_REVERSE;
55 dlg.uarrow.atr = A_BOLD;
56 dlg.darrow.atr = A_BOLD;
57}
28 58
29/* 59#define DLG_COLOR(dialog, f, b, h) \
30 * Attribute values, default is for mono display 60do { \
31 */ 61 dlg.dialog.fg = (f); \
32chtype attributes[] = { 62 dlg.dialog.bg = (b); \
33 A_NORMAL, /* screen_attr */ 63 dlg.dialog.hl = (h); \
34 A_NORMAL, /* shadow_attr */ 64} while (0)
35 A_NORMAL, /* dialog_attr */ 65
36 A_BOLD, /* title_attr */ 66static void set_classic_theme(void)
37 A_NORMAL, /* border_attr */ 67{
38 A_REVERSE, /* button_active_attr */ 68 DLG_COLOR(screen, COLOR_CYAN, COLOR_BLUE, true);
39 A_DIM, /* button_inactive_attr */ 69 DLG_COLOR(shadow, COLOR_BLACK, COLOR_BLACK, true);
40 A_REVERSE, /* button_key_active_attr */ 70 DLG_COLOR(dialog, COLOR_BLACK, COLOR_WHITE, false);
41 A_BOLD, /* button_key_inactive_attr */ 71 DLG_COLOR(title, COLOR_YELLOW, COLOR_WHITE, true);
42 A_REVERSE, /* button_label_active_attr */ 72 DLG_COLOR(border, COLOR_WHITE, COLOR_WHITE, true);
43 A_NORMAL, /* button_label_inactive_attr */ 73 DLG_COLOR(button_active, COLOR_WHITE, COLOR_BLUE, true);
44 A_NORMAL, /* inputbox_attr */ 74 DLG_COLOR(button_inactive, COLOR_BLACK, COLOR_WHITE, false);
45 A_NORMAL, /* inputbox_border_attr */ 75 DLG_COLOR(button_key_active, COLOR_WHITE, COLOR_BLUE, true);
46 A_NORMAL, /* searchbox_attr */ 76 DLG_COLOR(button_key_inactive, COLOR_RED, COLOR_WHITE, false);
47 A_BOLD, /* searchbox_title_attr */ 77 DLG_COLOR(button_label_active, COLOR_YELLOW, COLOR_BLUE, true);
48 A_NORMAL, /* searchbox_border_attr */ 78 DLG_COLOR(button_label_inactive, COLOR_BLACK, COLOR_WHITE, true);
49 A_BOLD, /* position_indicator_attr */ 79 DLG_COLOR(inputbox, COLOR_BLACK, COLOR_WHITE, false);
50 A_NORMAL, /* menubox_attr */ 80 DLG_COLOR(inputbox_border, COLOR_BLACK, COLOR_WHITE, false);
51 A_NORMAL, /* menubox_border_attr */ 81 DLG_COLOR(searchbox, COLOR_BLACK, COLOR_WHITE, false);
52 A_NORMAL, /* item_attr */ 82 DLG_COLOR(searchbox_title, COLOR_YELLOW, COLOR_WHITE, true);
53 A_REVERSE, /* item_selected_attr */ 83 DLG_COLOR(searchbox_border, COLOR_WHITE, COLOR_WHITE, true);
54 A_BOLD, /* tag_attr */ 84 DLG_COLOR(position_indicator, COLOR_YELLOW, COLOR_WHITE, true);
55 A_REVERSE, /* tag_selected_attr */ 85 DLG_COLOR(menubox, COLOR_BLACK, COLOR_WHITE, false);
56 A_BOLD, /* tag_key_attr */ 86 DLG_COLOR(menubox_border, COLOR_WHITE, COLOR_WHITE, true);
57 A_REVERSE, /* tag_key_selected_attr */ 87 DLG_COLOR(item, COLOR_BLACK, COLOR_WHITE, false);
58 A_BOLD, /* check_attr */ 88 DLG_COLOR(item_selected, COLOR_WHITE, COLOR_BLUE, true);
59 A_REVERSE, /* check_selected_attr */ 89 DLG_COLOR(tag, COLOR_YELLOW, COLOR_WHITE, true);
60 A_BOLD, /* uarrow_attr */ 90 DLG_COLOR(tag_selected, COLOR_YELLOW, COLOR_BLUE, true);
61 A_BOLD /* darrow_attr */ 91 DLG_COLOR(tag_key, COLOR_YELLOW, COLOR_WHITE, true);
62}; 92 DLG_COLOR(tag_key_selected, COLOR_YELLOW, COLOR_BLUE, true);
63 93 DLG_COLOR(check, COLOR_BLACK, COLOR_WHITE, false);
64#include "colors.h" 94 DLG_COLOR(check_selected, COLOR_WHITE, COLOR_BLUE, true);
95 DLG_COLOR(uarrow, COLOR_GREEN, COLOR_WHITE, true);
96 DLG_COLOR(darrow, COLOR_GREEN, COLOR_WHITE, true);
97}
98
99static void init_one_color(struct dialog_color *color)
100{
101 static int pair = 0;
102
103 pair++;
104 init_pair(pair, color->fg, color->bg);
105 if (color->hl)
106 color->atr = A_BOLD | COLOR_PAIR(pair);
107 else
108 color->atr = COLOR_PAIR(pair);
109}
110
111static void init_dialog_colors(void)
112{
113 init_one_color(&dlg.screen);
114 init_one_color(&dlg.shadow);
115 init_one_color(&dlg.dialog);
116 init_one_color(&dlg.title);
117 init_one_color(&dlg.border);
118 init_one_color(&dlg.button_active);
119 init_one_color(&dlg.button_inactive);
120 init_one_color(&dlg.button_key_active);
121 init_one_color(&dlg.button_key_inactive);
122 init_one_color(&dlg.button_label_active);
123 init_one_color(&dlg.button_label_inactive);
124 init_one_color(&dlg.inputbox);
125 init_one_color(&dlg.inputbox_border);
126 init_one_color(&dlg.searchbox);
127 init_one_color(&dlg.searchbox_title);
128 init_one_color(&dlg.searchbox_border);
129 init_one_color(&dlg.position_indicator);
130 init_one_color(&dlg.menubox);
131 init_one_color(&dlg.menubox_border);
132 init_one_color(&dlg.item);
133 init_one_color(&dlg.item_selected);
134 init_one_color(&dlg.tag);
135 init_one_color(&dlg.tag_selected);
136 init_one_color(&dlg.tag_key);
137 init_one_color(&dlg.tag_key_selected);
138 init_one_color(&dlg.check);
139 init_one_color(&dlg.check_selected);
140 init_one_color(&dlg.uarrow);
141 init_one_color(&dlg.darrow);
142}
65 143
66/* 144/*
67 * Table of color values 145 * Setup for color display
68 */ 146 */
69int color_table[][3] = { 147static void color_setup(void)
70 {SCREEN_FG, SCREEN_BG, SCREEN_HL}, 148{
71 {SHADOW_FG, SHADOW_BG, SHADOW_HL}, 149 if (has_colors()) { /* Terminal supports color? */
72 {DIALOG_FG, DIALOG_BG, DIALOG_HL}, 150 start_color();
73 {TITLE_FG, TITLE_BG, TITLE_HL}, 151 set_classic_theme();
74 {BORDER_FG, BORDER_BG, BORDER_HL}, 152 init_dialog_colors();
75 {BUTTON_ACTIVE_FG, BUTTON_ACTIVE_BG, BUTTON_ACTIVE_HL}, 153 }
76 {BUTTON_INACTIVE_FG, BUTTON_INACTIVE_BG, BUTTON_INACTIVE_HL}, 154 else
77 {BUTTON_KEY_ACTIVE_FG, BUTTON_KEY_ACTIVE_BG, BUTTON_KEY_ACTIVE_HL}, 155 {
78 {BUTTON_KEY_INACTIVE_FG, BUTTON_KEY_INACTIVE_BG, 156 set_mono_theme();
79 BUTTON_KEY_INACTIVE_HL}, 157 }
80 {BUTTON_LABEL_ACTIVE_FG, BUTTON_LABEL_ACTIVE_BG, 158}
81 BUTTON_LABEL_ACTIVE_HL},
82 {BUTTON_LABEL_INACTIVE_FG, BUTTON_LABEL_INACTIVE_BG,
83 BUTTON_LABEL_INACTIVE_HL},
84 {INPUTBOX_FG, INPUTBOX_BG, INPUTBOX_HL},
85 {INPUTBOX_BORDER_FG, INPUTBOX_BORDER_BG, INPUTBOX_BORDER_HL},
86 {SEARCHBOX_FG, SEARCHBOX_BG, SEARCHBOX_HL},
87 {SEARCHBOX_TITLE_FG, SEARCHBOX_TITLE_BG, SEARCHBOX_TITLE_HL},
88 {SEARCHBOX_BORDER_FG, SEARCHBOX_BORDER_BG, SEARCHBOX_BORDER_HL},
89 {POSITION_INDICATOR_FG, POSITION_INDICATOR_BG, POSITION_INDICATOR_HL},
90 {MENUBOX_FG, MENUBOX_BG, MENUBOX_HL},
91 {MENUBOX_BORDER_FG, MENUBOX_BORDER_BG, MENUBOX_BORDER_HL},
92 {ITEM_FG, ITEM_BG, ITEM_HL},
93 {ITEM_SELECTED_FG, ITEM_SELECTED_BG, ITEM_SELECTED_HL},
94 {TAG_FG, TAG_BG, TAG_HL},
95 {TAG_SELECTED_FG, TAG_SELECTED_BG, TAG_SELECTED_HL},
96 {TAG_KEY_FG, TAG_KEY_BG, TAG_KEY_HL},
97 {TAG_KEY_SELECTED_FG, TAG_KEY_SELECTED_BG, TAG_KEY_SELECTED_HL},
98 {CHECK_FG, CHECK_BG, CHECK_HL},
99 {CHECK_SELECTED_FG, CHECK_SELECTED_BG, CHECK_SELECTED_HL},
100 {UARROW_FG, UARROW_BG, UARROW_HL},
101 {DARROW_FG, DARROW_BG, DARROW_HL},
102}; /* color_table */
103 159
104/* 160/*
105 * Set window to attribute 'attr' 161 * Set window to attribute 'attr'
@@ -119,13 +175,13 @@ void attr_clear(WINDOW * win, int height, int width, chtype attr)
119 175
120void dialog_clear(void) 176void dialog_clear(void)
121{ 177{
122 attr_clear(stdscr, LINES, COLS, screen_attr); 178 attr_clear(stdscr, LINES, COLS, dlg.screen.atr);
123 /* Display background title if it exists ... - SLH */ 179 /* Display background title if it exists ... - SLH */
124 if (backtitle != NULL) { 180 if (dlg.backtitle != NULL) {
125 int i; 181 int i;
126 182
127 wattrset(stdscr, screen_attr); 183 wattrset(stdscr, dlg.screen.atr);
128 mvwaddstr(stdscr, 0, 1, (char *)backtitle); 184 mvwaddstr(stdscr, 0, 1, (char *)dlg.backtitle);
129 wmove(stdscr, 1, 1); 185 wmove(stdscr, 1, 1);
130 for (i = 1; i < COLS - 1; i++) 186 for (i = 1; i < COLS - 1; i++)
131 waddch(stdscr, ACS_HLINE); 187 waddch(stdscr, ACS_HLINE);
@@ -142,34 +198,11 @@ void init_dialog(void)
142 keypad(stdscr, TRUE); 198 keypad(stdscr, TRUE);
143 cbreak(); 199 cbreak();
144 noecho(); 200 noecho();
145 201 color_setup();
146 if (use_colors) /* Set up colors */
147 color_setup();
148
149 dialog_clear(); 202 dialog_clear();
150} 203}
151 204
152/* 205/*
153 * Setup for color display
154 */
155void color_setup(void)
156{
157 int i;
158
159 if (has_colors()) { /* Terminal supports color? */
160 start_color();
161
162 /* Initialize color pairs */
163 for (i = 0; i < ATTRIBUTE_COUNT; i++)
164 init_pair(i + 1, color_table[i][0], color_table[i][1]);
165
166 /* Setup color attributes */
167 for (i = 0; i < ATTRIBUTE_COUNT; i++)
168 attributes[i] = C_ATTR(color_table[i][2], i + 1);
169 }
170}
171
172/*
173 * End using dialog functions. 206 * End using dialog functions.
174 */ 207 */
175void end_dialog(void) 208void end_dialog(void)
@@ -184,7 +217,7 @@ void print_title(WINDOW *dialog, const char *title, int width)
184{ 217{
185 if (title) { 218 if (title) {
186 int tlen = MIN(width - 2, strlen(title)); 219 int tlen = MIN(width - 2, strlen(title));
187 wattrset(dialog, title_attr); 220 wattrset(dialog, dlg.title.atr);
188 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' '); 221 mvwaddch(dialog, 0, (width - tlen) / 2 - 1, ' ');
189 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen); 222 mvwaddnstr(dialog, 0, (width - tlen)/2, title, tlen);
190 waddch(dialog, ' '); 223 waddch(dialog, ' ');
@@ -264,21 +297,23 @@ void print_button(WINDOW * win, const char *label, int y, int x, int selected)
264 int i, temp; 297 int i, temp;
265 298
266 wmove(win, y, x); 299 wmove(win, y, x);
267 wattrset(win, selected ? button_active_attr : button_inactive_attr); 300 wattrset(win, selected ? dlg.button_active.atr
301 : dlg.button_inactive.atr);
268 waddstr(win, "<"); 302 waddstr(win, "<");
269 temp = strspn(label, " "); 303 temp = strspn(label, " ");
270 label += temp; 304 label += temp;
271 wattrset(win, selected ? button_label_active_attr 305 wattrset(win, selected ? dlg.button_label_active.atr
272 : button_label_inactive_attr); 306 : dlg.button_label_inactive.atr);
273 for (i = 0; i < temp; i++) 307 for (i = 0; i < temp; i++)
274 waddch(win, ' '); 308 waddch(win, ' ');
275 wattrset(win, selected ? button_key_active_attr 309 wattrset(win, selected ? dlg.button_key_active.atr
276 : button_key_inactive_attr); 310 : dlg.button_key_inactive.atr);
277 waddch(win, label[0]); 311 waddch(win, label[0]);
278 wattrset(win, selected ? button_label_active_attr 312 wattrset(win, selected ? dlg.button_label_active.atr
279 : button_label_inactive_attr); 313 : dlg.button_label_inactive.atr);
280 waddstr(win, (char *)label + 1); 314 waddstr(win, (char *)label + 1);
281 wattrset(win, selected ? button_active_attr : button_inactive_attr); 315 wattrset(win, selected ? dlg.button_active.atr
316 : dlg.button_inactive.atr);
282 waddstr(win, ">"); 317 waddstr(win, ">");
283 wmove(win, y, x + temp + 1); 318 wmove(win, y, x + temp + 1);
284} 319}
@@ -326,7 +361,7 @@ void draw_shadow(WINDOW * win, int y, int x, int height, int width)
326 int i; 361 int i;
327 362
328 if (has_colors()) { /* Whether terminal supports color? */ 363 if (has_colors()) { /* Whether terminal supports color? */
329 wattrset(win, shadow_attr); 364 wattrset(win, dlg.shadow.atr);
330 wmove(win, y + height, x + 2); 365 wmove(win, y + height, x + 2);
331 for (i = 0; i < width; i++) 366 for (i = 0; i < width; i++)
332 waddch(win, winch(win) & A_CHARTEXT); 367 waddch(win, winch(win) & A_CHARTEXT);