Ticket #3145: mc-3145-truecolor-v3.patch
File mc-3145-truecolor-v3.patch, 9.5 KB (added by egmont, 8 years ago) |
---|
-
doc/man/mc.1.in
diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index 2413b1e..ff46bb7 100644
a b with the assignment of colors, as described in Section 3654 3654 Colors\&. 3655 3655 .\"Colors" 3656 3656 .PP 3657 If your skin contains any of 256\-color definitions, you should define3658 the ' 256colors' key set to TRUE value in [skin] section.3659 3657 If your skin contains any true\-color definitions, you should define 3658 the 'truecolors' key set to TRUE value in [skin] section. If true\-color 3659 is not used but 256\-color is, you should define '256colors' instead. 3660 3660 .PP 3661 3661 A skin\-file is searched on the following algorithm (to the first one found): 3662 3662 .IP -
lib/skin.h
diff --git a/lib/skin.h b/lib/skin.h index 8d32180..747a504 100644
a b typedef struct mc_skin_struct 120 120 mc_config_t *config; 121 121 GHashTable *colors; 122 122 gboolean have_256_colors; 123 gboolean have_true_colors; 123 124 } mc_skin_t; 124 125 125 126 /*** global variables defined in .c file *********************************************************/ -
lib/skin/common.c
diff --git a/lib/skin/common.c b/lib/skin/common.c index 46a5c3e..fa37e2a 100644
a b gboolean 114 114 mc_skin_init (const gchar * skin_override, GError ** mcerror) 115 115 { 116 116 gboolean is_good_init = TRUE; 117 GError *error = NULL; 117 118 118 119 mc_return_val_if_error (mcerror, FALSE); 119 120 120 121 mc_skin__default.have_256_colors = FALSE; 122 mc_skin__default.have_true_colors = FALSE; 121 123 122 124 mc_skin__default.name = 123 125 skin_override != NULL ? g_strdup (skin_override) : mc_skin_get_default_name (); … … mc_skin_init (const gchar * skin_override, GError ** mcerror) 145 147 (void) mc_skin_ini_file_parse (&mc_skin__default); 146 148 is_good_init = FALSE; 147 149 } 150 if (is_good_init && !tty_use_truecolors (&error) && mc_skin__default.have_true_colors) 151 { 152 mc_propagate_error (mcerror, 0, 153 _ 154 ("Unable to use '%s' skin with true colors support:\n%s\nDefault skin has been loaded"), 155 mc_skin__default.name, error->message); 156 g_error_free (error); 157 mc_skin_try_to_load_default (); 158 mc_skin_colors_old_configure (&mc_skin__default); 159 (void) mc_skin_ini_file_parse (&mc_skin__default); 160 is_good_init = FALSE; 161 } 148 162 if (is_good_init && !tty_use_256colors () && mc_skin__default.have_256_colors) 149 163 { 150 164 mc_propagate_error (mcerror, 0, -
lib/skin/ini-file.c
diff --git a/lib/skin/ini-file.c b/lib/skin/ini-file.c index a29167d..b4dc314 100644
a b mc_skin_ini_file_parse (mc_skin_t * mc_skin) 187 187 188 188 mc_skin_lines_parse_ini_file (mc_skin); 189 189 mc_skin->have_256_colors = mc_config_get_bool (mc_skin->config, "skin", "256colors", FALSE); 190 mc_skin->have_true_colors = mc_config_get_bool (mc_skin->config, "skin", "truecolors", FALSE); 190 191 191 192 return TRUE; 192 193 } -
lib/tty/color-internal.c
diff --git a/lib/tty/color-internal.c b/lib/tty/color-internal.c index 13ee10e..d9bf3cd 100644
a b static mc_tty_color_table_t const attributes_table[] = { 96 96 /*** file scope functions ************************************************************************/ 97 97 /* --------------------------------------------------------------------------------------------- */ 98 98 99 static inline int 100 parse_hex_digit (char c) 101 { 102 if (c >= '0' && c <= '9') 103 return c - '0'; 104 c |= 0x20; 105 if (c >= 'a' && c <= 'f') 106 return c - 'a' + 10; 107 return -1; 108 } 109 99 110 static int 100 parse_256_ color_name (const char *color_name)111 parse_256_or_true_color_name (const char *color_name) 101 112 { 102 113 int i; 103 114 char dummy; … … parse_256_color_name (const char *color_name) 119 130 { 120 131 return 16 + 36 * (color_name[3] - '0') + 6 * (color_name[4] - '0') + (color_name[5] - '0'); 121 132 } 133 if (color_name[0] == '#') 134 { 135 int h[6]; 136 color_name++; 137 if (strlen (color_name) != 3 && strlen (color_name) != 6) 138 return -1; 139 for (i = 0; color_name[i] != '\0'; i++) 140 { 141 h[i] = parse_hex_digit (color_name[i]); 142 if (h[i] == -1) 143 return -1; 144 } 145 if (i == 3) 146 i = (h[0] << 20) | (h[0] << 16) | (h[1] << 12) | (h[1] << 8) | (h[2] << 4) | h[2]; 147 else 148 i = (h[0] << 20) | (h[1] << 16) | (h[2] << 12) | (h[3] << 8) | (h[4] << 4) | h[5]; 149 return (1 << 24) | i; 150 } 122 151 return -1; 123 152 } 124 153 … … tty_color_get_name_by_index (int idx) 136 165 for (i = 0; color_table[i].name != NULL; i++) 137 166 if (idx == color_table[i].value) 138 167 return color_table[i].name; 139 /* Create and return the strings "color16" to "color255". */140 if ( idx >= 16 && idx < 256)168 /* Create and return the strings in "colorNNN" or "#rrggbb" format. */ 169 if ((idx >= 16 && idx < 256) || idx & (1 << 24)) 141 170 { 142 static char **color_N_names = NULL; 143 144 if (color_N_names == NULL) 145 { 146 color_N_names = g_try_malloc0 (240 * sizeof (char *)); 147 } 148 if (color_N_names[idx - 16] == NULL) 149 { 150 color_N_names[idx - 16] = g_try_malloc (9); 151 sprintf (color_N_names[idx - 16], "color%d", idx); 152 } 153 return color_N_names[idx - 16]; 171 char name[9]; 172 if (idx < 256) 173 sprintf (name, "color%d", idx); 174 else 175 sprintf (name, "#%06X", idx & 0xFFFFFF); 176 return g_intern_string (name); 154 177 } 155 178 return "default"; 156 179 } … … tty_color_get_index_by_name (const char *color_name) 167 190 for (i = 0; color_table[i].name != NULL; i++) 168 191 if (strcmp (color_name, color_table[i].name) == 0) 169 192 return color_table[i].value; 170 return parse_256_ color_name (color_name);193 return parse_256_or_true_color_name (color_name); 171 194 } 172 195 return -1; 173 196 } -
lib/tty/color-ncurses.c
diff --git a/lib/tty/color-ncurses.c b/lib/tty/color-ncurses.c index f26927c..48ed521 100644
a b tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair) 180 180 ibg = mc_color_pair->ibg; 181 181 attr = mc_color_pair->attr; 182 182 183 /* In non-256color mode, change bright colors into bold */184 if (!tty_use_256colors () )183 /* In legacy color mode, change bright colors into bold */ 184 if (!tty_use_256colors () && !tty_use_truecolors (NULL)) 185 185 { 186 186 if (ifg >= 8 && ifg < 16) 187 187 { … … tty_use_256colors (void) 234 234 } 235 235 236 236 /* --------------------------------------------------------------------------------------------- */ 237 238 gboolean 239 tty_use_truecolors (GError ** error) 240 { 241 /* Not yet supported in ncurses */ 242 g_set_error (error, MC_ERROR, -1, _("True color not supported with ncurses.")); 243 return FALSE; 244 } 245 246 /* --------------------------------------------------------------------------------------------- */ -
lib/tty/color-slang.c
diff --git a/lib/tty/color-slang.c b/lib/tty/color-slang.c index d8646ca..38fd4e0 100644
a b tty_use_256colors (void) 215 215 } 216 216 217 217 /* --------------------------------------------------------------------------------------------- */ 218 219 gboolean 220 tty_use_truecolors (GError ** error) 221 { 222 char *colorterm; 223 224 /* True color is supported since slang-2.3.1 on 64-bit machines, 225 and expected to be supported from slang-3 on 32-bit machines: 226 http://lists.jedsoft.org/lists/slang-users/2016/0000014.html. 227 Check for sizeof (long) being 8, exactly as slang does. */ 228 if (SLang_Version < 20301 || (sizeof (long) != 8 && SLang_Version < 30000)) 229 { 230 g_set_error (error, MC_ERROR, -1, 231 _("True color not supported in this slang version.")); 232 return FALSE; 233 } 234 235 /* Sanity check that at least 256 colors are supported. */ 236 if (!tty_use_256colors ()) 237 { 238 g_set_error (error, MC_ERROR, -1, 239 _("Your terminal doesn't even seem to support 256 colors.")); 240 return FALSE; 241 } 242 243 /* Duplicate slang's check so that we can pop up an error message 244 rather than silently use wrong colors. */ 245 colorterm = getenv ("COLORTERM"); 246 if (colorterm == NULL || (strcmp (colorterm, "truecolor") != 0 && strcmp (colorterm, "24bit") != 0)) 247 { 248 g_set_error (error, MC_ERROR, -1, 249 _("Set COLORTERM=truecolor if your terminal really supports true colors.")); 250 return FALSE; 251 } 252 253 return TRUE; 254 } 255 256 /* --------------------------------------------------------------------------------------------- */ -
lib/tty/color.h
diff --git a/lib/tty/color.h b/lib/tty/color.h index 00ce671..1a9f573 100644
a b void tty_set_normal_attrs (void); 48 48 void tty_color_set_defaults (const char *, const char *, const char *); 49 49 50 50 extern gboolean tty_use_256colors (void); 51 extern gboolean tty_use_truecolors (GError **); 51 52 52 53 /*** inline functions ****************************************************************************/ 53 54 #endif /* MC_COLOR_H */ -
lib/tty/tty-slang.c
diff --git a/lib/tty/tty-slang.c b/lib/tty/tty-slang.c index 0427903..1341b14 100644
a b tty_init (gboolean mouse_enable, gboolean is_xterm) 316 316 tty_reset_prog_mode (); 317 317 load_terminfo_keys (); 318 318 319 SLtt_Blink_Mode = tty_use_256colors ()? 1 : 0;319 SLtt_Blink_Mode = (tty_use_256colors () || tty_use_truecolors (NULL)) ? 1 : 0; 320 320 321 321 tty_start_interrupt_key (); 322 322