2 Copyright (C) 1994 Miguel de Icaza.
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
24 #include "setup.h" /* For the externs */
30 /* To avoid excessive calls to ncurses' has_colors () */
33 /* Set to force black and white display at program startup */
34 int disable_colors
= 0;
36 /* Set if we are actually using colors */
39 int dialog_colors
[4];
41 #define ELEMENTS(arr) ( sizeof(arr) / sizeof((arr)[0]) )
46 # define CTYPE GdkColor *
47 void init_pair (int, CTYPE
, CTYPE
);
53 # define color_map_fg(n) (color_map[n].fg % COLORS)
54 # define color_map_bg(n) (color_map[n].bg % COLORS)
59 char *name
; /* Name of the entry */
60 CTYPE fg
; /* foreground color */
61 CTYPE bg
; /* background color */
65 # define color_map_fg(n) color_map[n].fg
66 # define color_map_bg(n) color_map[n].bg
69 struct colorpair color_map
[] = {
70 { "normal=", 0, 0 }, /* normal */
71 { "selected=", 0, 0 }, /* selected */
72 { "marked=", 0, 0 }, /* marked */
73 { "markselect=", 0, 0 }, /* marked/selected */
74 { "errors=", 0, 0 }, /* errors */
75 { "menu=", 0, 0 }, /* menu entry */
76 { "reverse=", 0, 0 }, /* reverse */
79 { "dnormal=", 0, 0 }, /* Dialog normal */
80 { "dfocus=", 0, 0 }, /* Dialog focused */
81 { "dhotnormal=", 0, 0 }, /* Dialog normal/hot */
82 { "dhotfocus=", 0, 0 }, /* Dialog focused/hot */
84 { "viewunderline=", 0, 0 }, /* _\b? sequence in view */
85 { "menusel=", 0, 0 }, /* Menu selected color */
86 { "menuhot=", 0, 0 }, /* Color for menu hotkeys */
87 { "menuhotsel=", 0, 0 }, /* Menu hotkeys/selected entry */
89 { "helpnormal=", 0, 0 }, /* Help normal */
90 { "helpitalic=", 0, 0 }, /* Italic in help */
91 { "helpbold=", 0, 0 }, /* Bold in help */
92 { "helplink=", 0, 0 }, /* Not selected hyperlink */
93 { "helpslink=", 0, 0 }, /* Selected hyperlink */
95 { "gauge=", 0, 0 }, /* Color of the progress bar (percentage) */
98 /* Per file types colors */
99 { "directory=", 0, 0 },
100 { "execute=", 0, 0 },
103 { "special=", 0, 0 },
107 struct color_table_s
{
113 struct color_table_s color_table
[] = {
114 { "black", COLOR_BLACK
},
115 { "gray", COLOR_BLACK
| A_BOLD
},
116 { "red", COLOR_RED
},
117 { "brightred", COLOR_RED
| A_BOLD
},
118 { "green", COLOR_GREEN
},
119 { "brightgreen", COLOR_GREEN
| A_BOLD
},
120 { "brown", COLOR_YELLOW
},
121 { "yellow", COLOR_YELLOW
| A_BOLD
},
122 { "blue", COLOR_BLUE
},
123 { "brightblue", COLOR_BLUE
| A_BOLD
},
124 { "magenta", COLOR_MAGENTA
},
125 { "brightmagenta", COLOR_MAGENTA
| A_BOLD
},
126 { "cyan", COLOR_CYAN
},
127 { "brightcyan", COLOR_CYAN
| A_BOLD
},
128 { "lightgray", COLOR_WHITE
},
129 { "white", COLOR_WHITE
| A_BOLD
}
133 void get_color (char *cpp
, CTYPE
*colp
);
136 # define color_value(i) color_table [i].name
137 # define color_name(i) color_table [i].name
139 # define color_value(i) color_table [i].value
140 # define color_name(i) color_table [i].name
143 static void get_color (char *cpp
, CTYPE
*colp
)
147 for (i
= 0; i
< ELEMENTS(color_table
); i
++){
148 if (strcmp (cpp
, color_name (i
)) == 0){
149 *colp
= color_value (i
);
154 #endif /* HAVE_GNOME */
156 static void get_two_colors (char **cpp
, struct colorpair
*colorpairp
)
166 get_color (*cpp
, state
? &colorpairp
->bg
: &colorpairp
->fg
);
175 get_color (*cpp
, &colorpairp
->fg
);
180 get_color (*cpp
, state
? &colorpairp
->bg
: &colorpairp
->fg
);
183 void configure_colors_string (char *the_color_string
)
185 char *color_string
, *p
;
188 if (!the_color_string
)
191 p
= color_string
= strdup (the_color_string
);
192 while (color_string
&& *color_string
){
193 while (*color_string
== ' ' || *color_string
== '\t')
197 for (i
= 0; i
< ELEMENTS(color_map
); i
++){
198 int klen
= strlen (color_map
[i
].name
);
200 if (strncmp (color_string
, color_map
[i
].name
, klen
) == 0){
201 color_string
+= klen
;
202 get_two_colors (&color_string
, &color_map
[i
]);
207 while (*color_string
&& *color_string
!= ':')
216 static void configure_colors (void)
218 extern char *command_line_colors
;
221 extern char *default_edition_colors
;
223 configure_colors_string (default_edition_colors
);
226 configure_colors_string (setup_color_string
);
227 configure_colors_string (term_color_string
);
228 configure_colors_string (getenv ("MC_COLOR_TABLE"));
229 configure_colors_string (command_line_colors
);
234 int attr_pairs
[MAX_PAIRS
];
238 load_dialog_colors (void)
240 dialog_colors
[0] = COLOR_NORMAL
;
241 dialog_colors
[1] = COLOR_FOCUS
;
242 dialog_colors
[2] = COLOR_HOT_NORMAL
;
243 dialog_colors
[3] = COLOR_HOT_FOCUS
;
255 for (i
= 0; i
< ELEMENTS (color_map
); i
++)
256 init_pair (i
+1, color_map_fg(i
), color_map_bg(i
));
257 load_dialog_colors ();
260 void init_colors (void)
264 hascolors
= has_colors ();
266 if (!disable_colors
&& hascolors
){
275 if (ELEMENTS (color_map
) > MAX_PAIRS
){
276 /* This message should only be seen by the developers */
278 "Too many defined colors, resize MAX_PAIRS on color.c");
283 #if defined HAVE_SLANG && !defined(OS2_NT)
284 if (use_colors
) { /* Hack to make COLOR_PAIR(31) be the default fg/bg
286 char *Norm_Vid
= SLtt_tgetstr ("me");
288 if (Norm_Vid
== NULL
)
289 Norm_Vid
= SLtt_tgetstr ("se");
290 if (Norm_Vid
== NULL
)
291 Norm_Vid
= "\033[0m";
292 SLtt_set_color_esc (31, Norm_Vid
);
296 for (i
= 0; i
< ELEMENTS (color_map
); i
++){
297 init_pair (i
+1, color_map_fg(i
), color_map_bg(i
));
301 * As a convenience, for the SVr4 curses configuration, we have
302 * OR'd the A_BOLD attribute to the color number. We'll need that
303 * later, to set the attribute with the colors.
305 attr_pairs
[i
+1] = color_map
[i
].fg
& A_BOLD
;
309 load_dialog_colors ();
313 void toggle_color_mode (void)
316 use_colors
= !use_colors
;