|
38 | 38 |
|
39 | 39 | #include "lib/global.h" |
40 | 40 |
|
| 41 | +#include "tty.h" |
41 | 42 | #include "tty-ncurses.h" |
42 | 43 | #include "color.h" // variables |
43 | 44 | #include "color-internal.h" |
|
53 | 54 | /*** file scope variables ************************************************************************/ |
54 | 55 |
|
55 | 56 | static GHashTable *mc_tty_color_color_pair_attrs = NULL; |
| 57 | +static int overlay_colors = 0; |
56 | 58 |
|
57 | 59 | /* --------------------------------------------------------------------------------------------- */ |
58 | 60 | /*** file scope functions ************************************************************************/ |
@@ -179,23 +181,40 @@ tty_color_try_alloc_lib_pair (tty_color_lib_pair_t *mc_color_pair) |
179 | 181 | ibg = mc_color_pair->bg; |
180 | 182 | attr = mc_color_pair->attr; |
181 | 183 |
|
182 | | - // In legacy color mode, change bright colors into bold |
183 | | - if (!tty_use_256colors (NULL) && !tty_use_truecolors (NULL)) |
| 184 | + // Change basic bright colors into bold |
| 185 | + if (ifg >= 8 && ifg < 16) |
184 | 186 | { |
185 | | - if (ifg >= 8 && ifg < 16) |
186 | | - { |
187 | | - ifg &= 0x07; |
188 | | - attr |= A_BOLD; |
189 | | - } |
190 | | - |
191 | | - if (ibg >= 8 && ibg < 16) |
192 | | - { |
193 | | - ibg &= 0x07; |
194 | | - // attr | = A_BOLD | A_REVERSE ; |
195 | | - } |
| 187 | + ifg &= 0x07; |
| 188 | + attr |= A_BOLD; |
196 | 189 | } |
197 | 190 |
|
| 191 | + if (ibg >= 8 && ibg < 16) |
| 192 | + { |
| 193 | + ibg &= 0x07; |
| 194 | + // attr | = A_BOLD | A_REVERSE ; |
| 195 | + } |
| 196 | + |
| 197 | + // Shady trick: if we don't have the exact color, because it is overlaid by backwards |
| 198 | + // compatibility indexed values, just borrow one degree of red. The user won't notice :) |
| 199 | + if ((ifg & FLAG_TRUECOLOR) != 0) |
| 200 | + { |
| 201 | + ifg &= ~FLAG_TRUECOLOR; |
| 202 | + if (ifg != 0 && ifg <= overlay_colors) |
| 203 | + ifg += (1 << 16); |
| 204 | + } |
| 205 | + |
| 206 | + if ((ibg & FLAG_TRUECOLOR) != 0) |
| 207 | + { |
| 208 | + ibg &= ~FLAG_TRUECOLOR; |
| 209 | + if (ibg != 0 && ibg <= overlay_colors) |
| 210 | + ibg += (1 << 16); |
| 211 | + } |
| 212 | + |
| 213 | +#if NCURSES_VERSION_PATCH >= 20170401 |
| 214 | + init_extended_pair (mc_color_pair->pair_index, ifg, ibg); |
| 215 | +#else |
198 | 216 | init_pair (mc_color_pair->pair_index, ifg, ibg); |
| 217 | +#endif |
199 | 218 | mc_tty_color_save_attr (mc_color_pair->pair_index, attr); |
200 | 219 | } |
201 | 220 | } |
@@ -231,17 +250,50 @@ tty_use_256colors (GError **error) |
231 | 250 | { |
232 | 251 | (void) error; |
233 | 252 |
|
234 | | - return (COLORS == 256); |
| 253 | + overlay_colors = tty_tigetnum ("CO", NULL); |
| 254 | + |
| 255 | + if (COLORS != 256 && !(COLORS > 256 && overlay_colors == 256)) |
| 256 | + { |
| 257 | + g_set_error (error, MC_ERROR, -1, |
| 258 | + _ ("\nIf your terminal supports 256 colors, you need to set your TERM\n" |
| 259 | + "environment variable to match your terminal, perhaps using\n" |
| 260 | + "a *-256color or *-direct256 variant. Use the 'toe -a'\n" |
| 261 | + "command to list all available variants on your system.\n")); |
| 262 | + return FALSE; |
| 263 | + } |
| 264 | + |
| 265 | + return TRUE; |
235 | 266 | } |
236 | 267 |
|
237 | 268 | /* --------------------------------------------------------------------------------------------- */ |
238 | 269 |
|
239 | 270 | gboolean |
240 | 271 | tty_use_truecolors (GError **error) |
241 | 272 | { |
242 | | - // Not yet supported in ncurses |
243 | | - g_set_error (error, MC_ERROR, -1, _ ("True color not supported with ncurses.")); |
| 273 | + // Low level true color is supported since ncurses 6.0 patch 20170401 preceding release |
| 274 | + // of ncurses 6.1 |
| 275 | +#if NCURSES_VERSION_PATCH < 20170401 |
| 276 | + g_set_error (error, MC_ERROR, -1, |
| 277 | + _ ("You need version 6.1 or later of the ncurses library\n" |
| 278 | + "for true color support. Please upgrade your system.\n")); |
244 | 279 | return FALSE; |
| 280 | +#else |
| 281 | + // We support only bool RGB cap configuration (8:8:8 bits), but the other variants are so rare |
| 282 | + // that we don't need to bother. |
| 283 | + if (!(tty_tigetflag ("RGB", NULL) && COLORS == COLORS_TRUECOLOR)) |
| 284 | + { |
| 285 | + g_set_error ( |
| 286 | + error, MC_ERROR, -1, |
| 287 | + _ ("\nIf your terminal supports true colors, you need to set your TERM\n" |
| 288 | + "environment variable to a *-direct256, *-direct16, or *-direct variant.\n" |
| 289 | + "Use the 'toe -a' command to list all available variants on your system.\n")); |
| 290 | + return FALSE; |
| 291 | + } |
| 292 | + |
| 293 | + overlay_colors = tty_tigetnum ("CO", NULL); |
| 294 | + |
| 295 | + return TRUE; |
| 296 | +#endif |
245 | 297 | } |
246 | 298 |
|
247 | 299 | /* --------------------------------------------------------------------------------------------- */ |
0 commit comments