1 /*
2 * colors.c - color and attribute definitions
3 * Copyright (c) 1998,1999 Tim Janik
4 * Jaroslav Kysela <perex@perex.cz>
5 * Copyright (c) 2009 Clemens Ladisch <clemens@ladisch.de>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "aconfig.h"
22 #include CURSESINC
23 #include "colors.h"
24
25 struct attributes attrs;
26 short background_color = -1;
27
get_color_pair(short fg,short bg)28 int get_color_pair(short fg, short bg)
29 {
30 static int color_pairs_defined = 0;
31 short i, pair_fg, pair_bg;
32
33 for (i = 1; i <= color_pairs_defined; ++i) {
34 if (OK == pair_content(i, &pair_fg, &pair_bg))
35 if (pair_fg == fg && pair_bg == bg)
36 return COLOR_PAIR(i);
37 }
38
39 if (color_pairs_defined + 1 < COLOR_PAIRS) {
40 ++color_pairs_defined;
41 init_pair(color_pairs_defined, fg, bg);
42 return COLOR_PAIR(color_pairs_defined);
43 }
44
45 return 0;
46 }
47
init_colors(int use_color)48 void init_colors(int use_color)
49 {
50 if (!!has_colors() == !!use_color) {
51 start_color();
52 use_default_colors();
53
54 get_color_pair(COLOR_CYAN, background_color); // COLOR_PAIR(1)
55 get_color_pair(COLOR_YELLOW, background_color);
56 get_color_pair(COLOR_WHITE, COLOR_GREEN);
57 get_color_pair(COLOR_RED, background_color);
58 get_color_pair(COLOR_WHITE, background_color);
59 get_color_pair(COLOR_WHITE, COLOR_BLUE);
60 get_color_pair(COLOR_RED, COLOR_BLUE);
61 get_color_pair(COLOR_GREEN, COLOR_GREEN);
62 get_color_pair(COLOR_WHITE, COLOR_RED); // COLOR_PAIR(9)
63 #ifdef TRICOLOR_VOLUME_BAR
64 get_color_pair(COLOR_WHITE, COLOR_WHITE);
65 get_color_pair(COLOR_RED, COLOR_RED);
66 #endif
67
68 attrs = (struct attributes) {
69 .mixer_frame = COLOR_PAIR(1),
70 .mixer_text = COLOR_PAIR(1),
71 .mixer_active = A_BOLD | COLOR_PAIR(2),
72 .ctl_frame = A_BOLD | COLOR_PAIR(1),
73 .ctl_mute = COLOR_PAIR(1),
74 .ctl_nomute = A_BOLD | COLOR_PAIR(3),
75 .ctl_capture = A_BOLD | COLOR_PAIR(4),
76 .ctl_nocapture = COLOR_PAIR(5),
77 .ctl_label = A_BOLD | COLOR_PAIR(6),
78 .ctl_label_focus = A_BOLD | COLOR_PAIR(7),
79 .ctl_mark_focus = A_BOLD | COLOR_PAIR(4),
80 .ctl_bar_lo = A_BOLD | COLOR_PAIR(8),
81 #ifdef TRICOLOR_VOLUME_BAR
82 .ctl_bar_mi = A_BOLD | COLOR_PAIR(10),
83 .ctl_bar_hi = A_BOLD | COLOR_PAIR(11),
84 #endif
85 .ctl_inactive = COLOR_PAIR(5),
86 .ctl_label_inactive = A_REVERSE | COLOR_PAIR(5),
87 .errormsg = A_BOLD | COLOR_PAIR(9),
88 .infomsg = A_BOLD | COLOR_PAIR(6),
89 .textbox = A_BOLD | COLOR_PAIR(6),
90 .textfield = A_REVERSE | COLOR_PAIR(5),
91 .menu = A_BOLD | COLOR_PAIR(6),
92 .menu_selected = A_REVERSE | COLOR_PAIR(6)
93 };
94 } else {
95 attrs = (struct attributes) {
96 .mixer_frame = A_NORMAL,
97 .mixer_text = A_NORMAL,
98 .mixer_active = A_BOLD,
99 .ctl_frame = A_BOLD,
100 .ctl_mute = A_NORMAL,
101 .ctl_nomute = A_BOLD,
102 .ctl_capture = A_BOLD,
103 .ctl_nocapture = A_NORMAL,
104 .ctl_label = A_REVERSE,
105 .ctl_label_focus = A_REVERSE | A_BOLD,
106 .ctl_mark_focus = A_BOLD,
107 .ctl_bar_lo = A_BOLD,
108 #ifdef TRICOLOR_VOLUME_BAR
109 .ctl_bar_mi = A_BOLD,
110 .ctl_bar_hi = A_BOLD,
111 #endif
112 .ctl_inactive = A_NORMAL,
113 .ctl_label_inactive = A_REVERSE,
114 .errormsg = A_STANDOUT,
115 .infomsg = A_NORMAL,
116 .textbox = A_NORMAL,
117 .textfield = A_REVERSE,
118 .menu = A_NORMAL,
119 .menu_selected = A_REVERSE,
120 };
121 }
122 }
123