Ticket #3145: mc-3145-truecolor-v2.patch
File mc-3145-truecolor-v2.patch, 9.2 KB (added by egmont, 9 years ago) |
---|
-
doc/man/mc.1.in
diff --git a/doc/man/mc.1.in b/doc/man/mc.1.in index e94e4e8..7a8eb0a 100644
a b with the assignment of colors, as described in Section 3632 3632 Colors\&. 3633 3633 .\"Colors" 3634 3634 .PP 3635 If your skin contains any of 256\-color definitions, you should define3636 the ' 256colors' key set to TRUE value in [skin] section.3637 3635 If your skin contains any of true\-color definitions, you should define 3636 the 'truecolors' key set to TRUE value in [skin] section. If true\-color 3637 is not used but 256\-color is, you should define '256colors' instead. 3638 3638 .PP 3639 3639 A skin\-file is searched on the following algorithm (to the first one found): 3640 3640 .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 f620ec8..180eb1b 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 923b45a..fad3492 100644
a b mc_skin_ini_file_parse (mc_skin_t * mc_skin) 188 188 189 189 mc_skin_lines_parse_ini_file (mc_skin); 190 190 mc_skin->have_256_colors = mc_config_get_bool (mc_skin->config, "skin", "256colors", FALSE); 191 mc_skin->have_true_colors = mc_config_get_bool (mc_skin->config, "skin", "truecolors", FALSE); 191 192 192 193 return TRUE; 193 194 } -
lib/tty/color-internal.c
diff --git a/lib/tty/color-internal.c b/lib/tty/color-internal.c index 5359943..3a982c8 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 1688520..7f8222f 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 b9d5a3c..9d0768d 100644
a b tty_use_256colors (void) 215 215 } 216 216 217 217 /* --------------------------------------------------------------------------------------------- */ 218 219 gboolean 220 tty_use_truecolors (GError ** error) 221 { 222 /* Ideally this should check slang's runtime version, but there's no API for that. */ 223 #if SLANG_VERSION < 20301 224 g_set_error (error, MC_ERROR, -1, _("True color not supported in this slang version.")); 225 return FALSE; 226 #else 227 char *colorterm; 228 229 /* Sanity check that at least 256 colors are supported. */ 230 if (!tty_use_256colors ()) 231 { 232 g_set_error (error, MC_ERROR, -1, 233 _("Your terminal doesn't even seem to support 256 colors.")); 234 return FALSE; 235 } 236 237 /* Duplicate slang's check so that we can pop up an error message 238 rather than silently use wrong colors. */ 239 colorterm = getenv ("COLORTERM"); 240 if (colorterm == NULL || (strcmp (colorterm, "truecolor") != 0 && strcmp (colorterm, "24bit"))) 241 { 242 g_set_error (error, MC_ERROR, -1, 243 _("Set COLORTERM=truecolor if your terminal really supports true colors.")); 244 return FALSE; 245 } 246 247 return TRUE; 248 #endif /* SLANG_VERSION */ 249 } 250 251 /* --------------------------------------------------------------------------------------------- */ -
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 dfb0fa8..caa090f 100644
a b tty_init (gboolean mouse_enable, gboolean is_xterm) 309 309 tty_reset_prog_mode (); 310 310 load_terminfo_keys (); 311 311 312 SLtt_Blink_Mode = tty_use_256colors ()? 1 : 0;312 SLtt_Blink_Mode = (tty_use_256colors () || tty_use_truecolors (NULL)) ? 1 : 0; 313 313 314 314 tty_start_interrupt_key (); 315 315