Ticket #2169: Add support for 256 colors terminals

Forget the old limit of 8 background and 16 foreground colors.
From now on Midnight Commander can use all the 256 colors,
as your favorite terminal emulator supports them - or not,
in which case it's not going to stay your favorite terminal for long.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
This commit is contained in:
Egmont Koblinger 2010-12-29 11:58:10 +02:00 committed by Slava Zanko
parent 5706b973b2
commit e593572bb9
18 changed files with 292 additions and 138 deletions

View File

@ -59,6 +59,9 @@ Anton Chumak <nightfast@yahoo.co.uk>
Antonio Palama, DOS port <palama@posso.dm.unipi.it>
DOS port.
Egmont Koblinger <egmont@gmail.com>
Support of 256 colors
Erwin van Eijk <wabbit@corner.iaf.nl>
Gerd Knorr <kraxel@cs.tu-berlin.de>

View File

@ -3417,7 +3417,7 @@ xterm=menu=magenta:marked=,magenta:markselect=,red
The format for the color definition is:
.PP
.nf
<keyword>=<foregroundcolor>,<backgroundcolor>:<keyword>= ...
<keyword>=<fgcolor>,<bgcolor>,<attributes>:<keyword>=...
.fi
.PP
The colors are optional, and the keywords are: normal, selected, disabled, marked,
@ -3481,12 +3481,22 @@ The possible colors are: black, gray, red, brightred, green,
brightgreen, brown, yellow, blue, brightblue, magenta, brightmagenta,
cyan, brightcyan, lightgray and white. And there is a special keyword
for transparent background. It is 'default'. The 'default' can only be
used for background color. Example:
used for background color. Another special keyword "base" means mc's main
colors. When 256 colors are available, they can be specified either as
color16 to color255, or as rgb000 to rgb555 and gray0 to gray23. Example:
.PP
.nf
[Colors]
base_color=normal=white,default:marked=magenta,default
.fi
.PP
Attributes can be any of bold, underline, reverse and blink, appended by a
plus sign if more than one are desired. The special word "none" means no
attributes, without attempting to fall back to base_color. Example:
.PP
.nf
menuhotsel=yellow;black;bold+underline
.fi
.\"NODE "Skins"
.SH "Skins"
@ -3727,11 +3737,12 @@ attribute
.SH " Color pair definitions"
Any parameter in skin\-file contain definition of color pair.
.PP
Color pairs described as two colors separated by ';'. First color
sets the foreground color, second color sets background color.
One of the colors may be omitted, in this case color will be
taken from default color pair (global color pair or
from default color pair of this section).
Color pairs described as two colors and the optional attributes
separated by ';'. First field sets the foreground color, second
field sets background color, third field sets the attributes.
Any of the fields may be omitted, in this case value will be
taken from default color pair (global color pair or from default
color pair of this section).
.PP
Example:
.br
@ -3739,14 +3750,15 @@ Example:
[core]
# green on black
_default_=green;black
# green (default) on blue
# green (default) on blue
selected=;blue
# yellow on black (default)
marked=yellow;
# underlined yellow on black (default)
marked=yellow;;underline
.fi
.PP
Possible colors (names) described in
Possible colors (names) and attributes are described in
.\"LINK2"
Colors\&.
.\"Colors"

View File

@ -33,7 +33,7 @@ Force black and white display.
Force ANSI color mode on terminals that don't seem to have color
support.
.TP
.I "\-C <keyword>=<FGcolor>,<BGcolor>:<keyword>= ..."
.I "\-C <keyword>=<fgcolor>,<bgcolor>,<attributes>:<keyword>= ..."
Specify a different color set. See the
.B Colors
section in mc(1) for more information.
@ -249,12 +249,14 @@ Each context starts with a line of the form:
.I delim
.RI [ foreground ]
.RI [ background ]
.RI [ attributes ]
.PP
The first context is an exception. It must start with the command
.PP
.B context default
.RI [ foreground ]
.RI [ background ]
.RI [ attributes ]
.PP
otherwise
.B mcedit
@ -294,6 +296,7 @@ Each rule is a line of the form:
.RB [ linestart ]
.I string foreground
.RI [ background ]
.RI [ attributes ]
.PP
Context or keyword strings are interpreted, so that you can include tabs
and spaces with the sequences \\t and \\s. Newlines and backslashes are
@ -331,8 +334,14 @@ directive to continue across multiple lines.
.PP
The possible colors are: black, gray, red, brightred, green,
brightgreen, brown, yellow, blue, brightblue, magenta, brightmagenta,
cyan, brightcyan, lightgray and white. If the syntax file is shared
with
cyan, brightcyan, lightgray and white. The special keyword "default" means
the terminal's default. Another special keyword "base" means mc's main
colors, it is useful as a placeholder if you want to specify attributes
without modifying the background color. When 256 colors are available,
they can be specified either as color16 to color255, or as rgb000 to rgb555
and gray0 to gray23.
.PP
If the syntax file is shared with
.BR cooledit ,
it is possible to specify different colors for
.B mcedit
@ -349,6 +358,9 @@ uses the color before the slash. See cooledit(1) for supported
.B cooledit
colors.
.PP
Attributes can be any of bold, underline, reverse and blink, appended by a
plus sign if more than one are desired.
.PP
Comments may be put on a separate line starting with the hash sign (#).
.PP
If you are describing case insensitive language you need to use

View File

@ -23,7 +23,7 @@ Force color mode on terminals where
.B mcview
defaults to black and white.
.TP
.I "\-C <keyword>=<FGcolor>,<BGcolor>:<keyword>= ..."
.I "\-C <keyword>=<fgcolor>,<bgcolor>,<attributes>:<keyword>= ..."
Specify a different color set. See the
.B Colors
section in mc(1) for more information.

View File

@ -2,10 +2,11 @@
Skins engine.
Work with colors - backward compability
Copyright (C) 2009 The Free Software Foundation, Inc.
Copyright (C) 2009, 2010 The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This file is part of the Midnight Commander.
@ -135,7 +136,7 @@ mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_str
for (; *colors; colors++)
{
key_val = g_strsplit_set (*colors, "=,", 3);
key_val = g_strsplit_set (*colors, "=,", 4);
if (!key_val)
continue;
@ -147,7 +148,9 @@ mc_skin_colors_old_configure_one (mc_skin_t * mc_skin, const char *the_color_str
continue;
}
if (key_val[2] != NULL)
if (key_val[3] != NULL)
skin_val = g_strdup_printf ("%s;%s;%s", key_val[1], key_val[2], key_val[3]);
else if (key_val[2] != NULL)
skin_val = g_strdup_printf ("%s;%s", key_val[1], key_val[2]);
else
skin_val = g_strdup_printf ("%s;", key_val[1]);

View File

@ -2,10 +2,11 @@
Skins engine.
Work with colors
Copyright (C) 2009 The Free Software Foundation, Inc.
Copyright (C) 2009, 2010 The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This file is part of the Midnight Commander.
@ -144,36 +145,19 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
return NULL;
}
switch (items_count)
{
case 0:
tmp = mc_skin_color_get_with_defaults (group, "_default_");
if (tmp != NULL)
{
mc_skin_color->fgcolor = g_strdup (tmp->fgcolor);
mc_skin_color->bgcolor = g_strdup (tmp->bgcolor);
}
else
{
g_strfreev (values);
g_free (mc_skin_color);
return NULL;
}
break;
case 1:
mc_skin_color->fgcolor = (values[0]) ? g_strstrip (g_strdup (values[0])) : NULL;
tmp = mc_skin_color_get_with_defaults (group, "_default_");
mc_skin_color->bgcolor = (tmp != NULL) ? g_strdup (tmp->bgcolor) : NULL;
break;
case 2:
mc_skin_color->fgcolor = (values[0]) ? g_strstrip (g_strdup (values[0])) : NULL;
mc_skin_color->bgcolor = (values[1]) ? g_strstrip (g_strdup (values[1])) : NULL;
break;
}
tmp = mc_skin_color_get_with_defaults (group, "_default_");
mc_skin_color->fgcolor = (items_count > 0 && values[0][0]) ? g_strstrip (g_strdup (values[0])) :
(tmp != NULL) ? g_strdup (tmp->fgcolor) : NULL;
mc_skin_color->bgcolor = (items_count > 1 && values[1][0]) ? g_strstrip (g_strdup (values[1])) :
(tmp != NULL) ? g_strdup (tmp->bgcolor) : NULL;
mc_skin_color->attrs = (items_count > 2 && values[2][0]) ? g_strstrip (g_strdup (values[2])) :
(tmp != NULL) ? g_strdup (tmp->attrs) : NULL;
g_strfreev (values);
mc_skin_color->pair_index =
tty_try_alloc_color_pair2 (mc_skin_color->fgcolor, mc_skin_color->bgcolor, FALSE);
tty_try_alloc_color_pair2 (mc_skin_color->fgcolor, mc_skin_color->bgcolor,
mc_skin_color->attrs, FALSE);
return mc_skin_color;
}
@ -189,8 +173,10 @@ mc_skin_color_set_default_for_terminal (mc_skin_t * mc_skin)
{
mc_skin_color->fgcolor = g_strdup ("default");
mc_skin_color->bgcolor = g_strdup ("default");
mc_skin_color->attrs = NULL;
mc_skin_color->pair_index =
tty_try_alloc_color_pair2 (mc_skin_color->fgcolor, mc_skin_color->bgcolor, FALSE);
tty_try_alloc_color_pair2 (mc_skin_color->fgcolor, mc_skin_color->bgcolor,
mc_skin_color->attrs, FALSE);
mc_skin_color_add_to_hash (mc_skin, "skin", "terminal_default_color", mc_skin_color);
}
}
@ -337,7 +323,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
if (mc_skin_color == NULL)
return FALSE;
tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor);
tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor, mc_skin_color->attrs);
mc_skin_color_add_to_hash (mc_skin, "core", "_default_", mc_skin_color);
for (; *groups != NULL; groups++)

View File

@ -2,10 +2,11 @@
Skins engine.
Interface functions
Copyright (C) 2009 The Free Software Foundation, Inc.
Copyright (C) 2009, 2010 The Free Software Foundation, Inc.
Written by:
Slava Zanko <slavazanko@gmail.com>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This file is part of the Midnight Commander.
@ -54,6 +55,7 @@ mc_skin_hash_destroy_value (gpointer data)
mc_skin_color_t *mc_skin_color = (mc_skin_color_t *) data;
g_free (mc_skin_color->fgcolor);
g_free (mc_skin_color->bgcolor);
g_free (mc_skin_color->attrs);
g_free (mc_skin_color);
}

View File

@ -14,6 +14,7 @@ typedef struct mc_skin_color_struct
{
gchar *fgcolor;
gchar *bgcolor;
gchar *attrs;
int pair_index;
} mc_skin_color_t;

View File

@ -1,10 +1,11 @@
/* Internal stuff of color setup
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009.
Andrew Borodin <aborodin@vmail.ru>, 2009
Slava Zanko <slavazanko@gmail.com>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -49,21 +50,21 @@ typedef struct mc_tty_color_table_struct
mc_tty_color_table_t const color_table[] = {
{"black", COLOR_BLACK},
{"gray", COLOR_BLACK | A_BOLD},
{"gray", COLOR_BLACK + 8},
{"red", COLOR_RED},
{"brightred", COLOR_RED | A_BOLD},
{"brightred", COLOR_RED + 8},
{"green", COLOR_GREEN},
{"brightgreen", COLOR_GREEN | A_BOLD},
{"brightgreen", COLOR_GREEN + 8},
{"brown", COLOR_YELLOW},
{"yellow", COLOR_YELLOW | A_BOLD},
{"yellow", COLOR_YELLOW + 8},
{"blue", COLOR_BLUE},
{"brightblue", COLOR_BLUE | A_BOLD},
{"brightblue", COLOR_BLUE + 8},
{"magenta", COLOR_MAGENTA},
{"brightmagenta", COLOR_MAGENTA | A_BOLD},
{"brightmagenta", COLOR_MAGENTA + 8},
{"cyan", COLOR_CYAN},
{"brightcyan", COLOR_CYAN | A_BOLD},
{"brightcyan", COLOR_CYAN + 8},
{"lightgray", COLOR_WHITE},
{"white", COLOR_WHITE | A_BOLD},
{"white", COLOR_WHITE + 8},
{"default", -1}, /* default color of the terminal */
/* special colors */
{"A_REVERSE", SPEC_A_REVERSE},
@ -74,24 +75,71 @@ mc_tty_color_table_t const color_table[] = {
{NULL, 0}
};
mc_tty_color_table_t const attributes_table[] = {
{"bold", A_BOLD},
{"underline", A_UNDERLINE},
{"reverse", A_REVERSE},
{"blink", A_BLINK},
/* End of list */
{NULL, 0}
};
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static int
parse_256_color_name (const char *color_name)
{
int i;
char dummy;
if (sscanf (color_name, "color%d%c", &i, &dummy) == 1 && i >= 0 && i < 256)
{
return i;
}
if (sscanf (color_name, "gray%d%c", &i, &dummy) == 1 && i >= 0 && i < 24)
{
return 232 + i;
}
if (strncmp (color_name, "rgb", 3) == 0 &&
color_name[3] >= '0' && color_name[3] < '6' &&
color_name[4] >= '0' && color_name[4] < '6' &&
color_name[5] >= '0' && color_name[5] < '6' && color_name[6] == '\0')
{
return 16 + 36 * (color_name[3] - '0') + 6 * (color_name[4] - '0') + (color_name[5] - '0');
}
return -1;
}
/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
const char *
tty_color_get_valid_name (const char *color_name)
tty_color_get_name_by_index (int idx)
{
static char **color_N_names = NULL;
int i;
if (color_name != NULL)
/* Find the real English name of the first 16 colors, */
/* as well as the A_* special values. */
for (i = 0; color_table[i].name != NULL; i++)
if (idx == color_table[i].value)
return color_table[i].name;
/* Create and return the strings "color16" to "color255". */
if (idx >= 16 && idx < 256)
{
size_t i;
for (i = 0; color_table[i].name != NULL; i++)
if (strcmp (color_name, color_table[i].name) == 0)
return color_table[i].name;
if (color_N_names == NULL)
{
color_N_names = g_try_malloc0 (240 * sizeof (char *));
}
if (color_N_names[idx - 16] == NULL)
{
color_N_names[idx - 16] = g_try_malloc (9);
sprintf (color_N_names[idx - 16], "color%d", idx);
}
return color_N_names[idx - 16];
}
return NULL;
return "default";
}
/* --------------------------------------------------------------------------------------------- */
@ -106,8 +154,37 @@ tty_color_get_index_by_name (const char *color_name)
for (i = 0; color_table[i].name != NULL; i++)
if (strcmp (color_name, color_table[i].name) == 0)
return color_table[i].value;
return parse_256_color_name (color_name);
}
return -1;
}
/* --------------------------------------------------------------------------------------------- */
int
tty_attr_get_bits (const char *attrs)
{
int attr_bits = 0;
gchar **attr_list;
int i, j;
if (attrs != NULL)
{
attr_list = g_strsplit (attrs, "+", -1);
for (i = 0; attr_list[i] != NULL; i++)
{
for (j = 0; attributes_table[j].name != NULL; j++)
{
if (strcmp (attr_list[i], attributes_table[j].name) == 0)
{
attr_bits |= attributes_table[j].value;
break;
}
}
}
g_strfreev (attr_list);
}
return attr_bits;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -33,11 +33,10 @@ typedef enum {
typedef struct mc_color_pair_struct
{
const char *cfg;
const char *cbg;
int ifg;
int ibg;
int pair_index;
int attr;
size_t pair_index;
gboolean is_temp;
} tty_color_pair_t;
@ -48,8 +47,9 @@ extern gboolean mc_tty_color_disable;
/*** declarations of public functions ************************************************************/
const char *tty_color_get_valid_name (const char *);
const char *tty_color_get_name_by_index (int);
int tty_color_get_index_by_name (const char *);
int tty_attr_get_bits (const char *);
void tty_color_init_lib (gboolean, gboolean);
void tty_color_deinit_lib (void);

View File

@ -1,9 +1,11 @@
/* Color setup for NCurses screen library
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
Andrew Borodin <aborodin@vmail.ru>, 2009
Slava Zanko <slavazanko@gmail.com>, 2010
Egmont Koblinger <egmont@gmail.com>, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -57,28 +59,25 @@ mc_tty_color_attr_destroy_cb (gpointer data)
/* --------------------------------------------------------------------------------------------- */
static int
mc_tty_color_save_attr_lib (int color_pair, int color_attr)
static void
mc_tty_color_save_attr (int color_pair, int color_attr)
{
int *attr, *key;
attr = g_try_new0 (int, 1);
if (attr == NULL)
return color_attr;
return;
key = g_try_new (int, 1);
if (key == NULL)
{
g_free (attr);
return color_attr;
return;
}
*key = color_pair;
*attr = color_attr;
if (color_attr != -1)
*attr = color_attr & (A_BOLD | A_REVERSE | A_UNDERLINE);
g_hash_table_replace (mc_tty_color_color_pair_attrs, (gpointer) key, (gpointer) attr);
return color_attr & (~(*attr));
}
/* --------------------------------------------------------------------------------------------- */
@ -97,14 +96,13 @@ color_get_attr (int color_pair)
static void
mc_tty_color_pair_init_special (tty_color_pair_t * mc_color_pair,
int fg1, int bg1, int fg2, int bg2, int mask)
int fg1, int bg1, int fg2, int bg2, int attr)
{
if (has_colors () && !mc_tty_color_disable)
init_pair (mc_color_pair->pair_index,
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg1 | mask), bg1);
init_pair (mc_color_pair->pair_index, fg1, bg1);
else
init_pair (mc_color_pair->pair_index,
mc_tty_color_save_attr_lib (mc_color_pair->pair_index, fg2 | mask), bg2);
init_pair (mc_color_pair->pair_index, fg2, bg2);
mc_tty_color_save_attr (mc_color_pair->pair_index, attr);
}
/* --------------------------------------------------------------------------------------------- */
@ -141,6 +139,7 @@ tty_color_deinit_lib (void)
void
tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
{
if (mc_color_pair->ifg <= (int) SPEC_A_REVERSE)
{
switch (mc_color_pair->ifg)
@ -169,13 +168,21 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
}
else
{
int mask_fg = (mc_color_pair->ifg == -1) ? mc_color_pair->ifg : 0xff;
int mask_bg = (mc_color_pair->ibg == -1) ? mc_color_pair->ibg : 0xff;
int ifg, ibg, attr;
init_pair (mc_color_pair->pair_index,
mc_tty_color_save_attr_lib (mc_color_pair->pair_index,
mc_color_pair->ifg) & mask_fg,
mc_color_pair->ibg & mask_bg);
ifg = mc_color_pair->ifg;
ibg = mc_color_pair->ibg;
attr = mc_color_pair->attr;
/* In 8 color mode, change bright colors into bold */
if (COLORS == 8 && ifg >= 8 && ifg < 16)
{
ifg &= 0x07;
attr |= A_BOLD;
}
init_pair (mc_color_pair->pair_index, ifg, ibg);
mc_tty_color_save_attr (mc_color_pair->pair_index, attr);
}
}

View File

@ -1,9 +1,10 @@
/* Color setup for S_Lang screen library
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
Andrew Borodin <aborodin@vmail.ru>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -168,9 +169,10 @@ tty_color_try_alloc_pair_lib (tty_color_pair_t * mc_color_pair)
}
else
{
fg = (mc_color_pair->cfg) ? mc_color_pair->cfg : "default";
bg = (mc_color_pair->cbg) ? mc_color_pair->cbg : "default";
fg = tty_color_get_name_by_index(mc_color_pair->ifg);
bg = tty_color_get_name_by_index(mc_color_pair->ibg);
SLtt_set_color (mc_color_pair->pair_index, (char *) "", (char *) fg, (char *) bg);
SLtt_add_color_attribute (mc_color_pair->pair_index, mc_color_pair->attr);
}
}

View File

@ -11,12 +11,21 @@
/*** typedefs(not structures) and defined constants **********************************************/
/* When using Slang with color, we have all the indexes free but
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BOLD_REVERSE)
* those defined here (A_BOLD, A_UNDERLINE, A_REVERSE, A_BLINK)
*/
#ifndef A_BOLD
#define A_BOLD SLTT_BOLD_MASK
#endif /* A_BOLD */
#ifndef A_UNDERLINE
#define A_UNDERLINE SLTT_ULINE_MASK
#endif /* A_UNDERLINE */
#ifndef A_REVERSE
#define A_REVERSE SLTT_REV_MASK
#endif /* A_REVERSE */
#ifndef A_BLINK
#define A_BLINK SLTT_BLINK_MASK
#endif /* A_BLINK */
/*** enums ***************************************************************************************/

View File

@ -2,11 +2,13 @@
Interface functions.
Copyright (C) 1994, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005,
2007, 2008, 2009 Free Software Foundation, Inc.
2007, 2008, 2009, 2010 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
Slava Zanko <slavazanko@gmail.com>, 2009.
Andrew Borodin <aborodin@vmail.ru>, 2009
Slava Zanko <slavazanko@gmail.com>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -46,6 +48,7 @@ char *command_line_colors = NULL;
static char *tty_color_defaults__fg = NULL;
static char *tty_color_defaults__bg = NULL;
static char *tty_color_defaults__attrs = NULL;
/* Set if we are actually using colors */
gboolean use_colors = FALSE;
@ -87,7 +90,7 @@ tty_color_free_all (gboolean is_temp_color)
static gboolean
tty_color_get_next_cpn_cb (gpointer key, gpointer value, gpointer user_data)
{
int cp;
size_t cp;
tty_color_pair_t *mc_color_pair;
(void) key;
@ -99,7 +102,7 @@ tty_color_get_next_cpn_cb (gpointer key, gpointer value, gpointer user_data)
/* --------------------------------------------------------------------------------------------- */
static int
static size_t
tty_color_get_next__color_pair_number (void)
{
const size_t cp_count = g_hash_table_size (mc_tty_color__hashtable);
@ -132,6 +135,7 @@ tty_colors_done (void)
tty_color_deinit_lib ();
g_free (tty_color_defaults__fg);
g_free (tty_color_defaults__bg);
g_free (tty_color_defaults__attrs);
g_hash_table_destroy (mc_tty_color__hashtable);
}
@ -147,21 +151,25 @@ tty_use_colors (void)
/* --------------------------------------------------------------------------------------------- */
int
tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_color)
tty_try_alloc_color_pair2 (const char *fg, const char *bg, const char *attrs,
gboolean is_temp_color)
{
gchar *color_pair;
tty_color_pair_t *mc_color_pair;
const char *c_fg, *c_bg;
int ifg, ibg, attr;
if (fg == NULL)
if (fg == NULL || !strcmp (fg, "base"))
fg = tty_color_defaults__fg;
if (bg == NULL)
if (bg == NULL || !strcmp (bg, "base"))
bg = tty_color_defaults__bg;
if (attrs == NULL || !strcmp (attrs, "base"))
attrs = tty_color_defaults__attrs;
c_fg = tty_color_get_valid_name (fg);
c_bg = tty_color_get_valid_name (bg);
ifg = tty_color_get_index_by_name (fg);
ibg = tty_color_get_index_by_name (bg);
attr = tty_attr_get_bits (attrs);
color_pair = g_strdup_printf ("%s.%s", c_fg, c_bg);
color_pair = g_strdup_printf ("%d.%d.%d", ifg, ibg, attr);
if (color_pair == NULL)
return 0;
@ -182,10 +190,9 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo
}
mc_color_pair->is_temp = is_temp_color;
mc_color_pair->cfg = c_fg;
mc_color_pair->cbg = c_bg;
mc_color_pair->ifg = tty_color_get_index_by_name (c_fg);
mc_color_pair->ibg = tty_color_get_index_by_name (c_bg);
mc_color_pair->ifg = ifg;
mc_color_pair->ibg = ibg;
mc_color_pair->attr = attr;
mc_color_pair->pair_index = tty_color_get_next__color_pair_number ();
tty_color_try_alloc_pair_lib (mc_color_pair);
@ -198,9 +205,9 @@ tty_try_alloc_color_pair2 (const char *fg, const char *bg, gboolean is_temp_colo
/* --------------------------------------------------------------------------------------------- */
int
tty_try_alloc_color_pair (const char *fg, const char *bg)
tty_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs)
{
return tty_try_alloc_color_pair2 (fg, bg, TRUE);
return tty_try_alloc_color_pair2 (fg, bg, attrs, TRUE);
}
/* --------------------------------------------------------------------------------------------- */
@ -222,13 +229,15 @@ tty_color_free_all_non_tmp (void)
/* --------------------------------------------------------------------------------------------- */
void
tty_color_set_defaults (const char *fgcolor, const char *bgcolor)
tty_color_set_defaults (const char *fgcolor, const char *bgcolor, const char *attrs)
{
g_free (tty_color_defaults__fg);
g_free (tty_color_defaults__fg);
g_free (tty_color_defaults__attrs);
tty_color_defaults__fg = (fgcolor != NULL) ? g_strdup (fgcolor) : NULL;
tty_color_defaults__bg = (bgcolor != NULL) ? g_strdup (bgcolor) : NULL;
tty_color_defaults__attrs = (attrs != NULL) ? g_strdup (attrs) : NULL;
}
/* --------------------------------------------------------------------------------------------- */

View File

@ -38,8 +38,8 @@ void tty_init_colors (gboolean disable, gboolean force);
void tty_colors_done (void);
gboolean tty_use_colors (void);
int tty_try_alloc_color_pair (const char *, const char *);
int tty_try_alloc_color_pair2 (const char *, const char *, gboolean);
int tty_try_alloc_color_pair (const char *, const char *, const char *);
int tty_try_alloc_color_pair2 (const char *, const char *, const char *, gboolean);
void tty_color_free_all_tmp (void);
void tty_color_free_all_non_tmp (void);
@ -48,7 +48,7 @@ void tty_setcolor (int color);
void tty_lowlevel_setcolor (int color);
void tty_set_normal_attrs (void);
void tty_color_set_defaults (const char *, const char *);
void tty_color_set_defaults (const char *, const char *, const char *);
/*** inline functions ****************************************************************************/
#endif /* MC_COLOR_H */

View File

@ -2,10 +2,11 @@
Interface to the terminal controlling library.
Slang wrapper.
Copyright (C) 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
Copyright (C) 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc.
Written by:
Andrew Borodin <aborodin@vmail.ru>, 2009.
Andrew Borodin <aborodin@vmail.ru>, 2009
Egmont Koblinger <egmont@gmail.com>, 2010
This file is part of the Midnight Commander.
@ -291,7 +292,7 @@ tty_init (gboolean slow, gboolean ugly_lines)
tty_reset_prog_mode ();
load_terminfo_keys ();
SLtt_Blink_Mode = 0;
SLtt_Blink_Mode = 1;
tty_start_interrupt_key ();

View File

@ -322,8 +322,8 @@ mc_args_new_color_group (void)
/* FIXME: to preserve translations, lines should be split. */
mc_args__loc__colors_string = g_strdup_printf ("%s\n%s",
/* TRANSLATORS: don't translate keywords */
_("--colors KEYWORD={FORE},{BACK}\n\n"
"{FORE} and {BACK} can be omitted, and the default will be used\n"
_("--colors KEYWORD={FORE},{BACK},{ATTR}:KEYWORD2=...\n\n"
"{FORE}, {BACK} and {ATTR} can be omitted, and the default will be used\n"
"\n Keywords:\n"
" Global: errors, disabled, reverse, gauge, viewunderline\n"
" input, inputmark, inputunchanged, commandlinemark\n"
@ -337,11 +337,16 @@ mc_args_new_color_group (void)
" editlinestate\n"
" Viewer: viewunderline\n"
" Help: helpnormal, helpitalic, helpbold, helplink, helpslink\n"),
/* TRANSLATORS: don't translate color names */
_("Colors:\n"
/* TRANSLATORS: don't translate color names and attributes */
_("Standard Colors:\n"
" black, gray, red, brightred, green, brightgreen, brown,\n"
" yellow, blue, brightblue, magenta, brightmagenta, cyan,\n"
" brightcyan, lightgray and white\n\n"));
" brightcyan, lightgray and white\n\n"
"Extended colors, when 256 colors are available:\n"
" color16 to color255, or rgb000 to rgb555 and gray0 to gray23\n\n"
"Attributes:\n"
" bold, underline, reverse, blink; append more with '+'\n")
);
return g_option_group_new ("color", mc_args__loc__colors_string,
_("Color options"), NULL, NULL);

View File

@ -1,9 +1,11 @@
/* editor syntax highlighting.
Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2004, 2005, 2006,
2007 Free Software Foundation, Inc.
2007, 2010 Free Software Foundation, Inc.
Authors: 1998 Paul Sheer
Authors:
1998 Paul Sheer
Egmont Koblinger <egmont@gmail.com>, 2010
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@ -762,14 +764,16 @@ get_args (char *l, char **args, int args_size)
/* --------------------------------------------------------------------------------------------- */
static int
this_try_alloc_color_pair (const char *fg, const char *bg)
this_try_alloc_color_pair (const char *fg, const char *bg, const char *attrs)
{
char f[80], b[80], *p;
char f[80], b[80], a[80], *p;
if (bg != NULL && *bg == '\0')
bg = NULL;
if (fg != NULL && *fg == '\0')
fg = NULL;
if (attrs != NULL && *attrs == '\0')
attrs = NULL;
if ((fg == NULL) && (bg == NULL))
return EDITOR_NORMAL_COLOR;
@ -820,7 +824,19 @@ this_try_alloc_color_pair (const char *fg, const char *bg)
g_free (editnormal);
}
return tty_try_alloc_color_pair (fg, bg);
if (attrs != NULL)
{
g_strlcpy (a, attrs, sizeof (a));
p = strchr (a, '/');
if (p != NULL)
*p = '\0';
/* get_args() mangles the + signs, unmangle 'em */
p = a;
while ((p = strchr (p, SYNTAX_TOKEN_PLUS)) != NULL)
*p++ = '+';
attrs = a;
}
return tty_try_alloc_color_pair (fg, bg, attrs);
}
/* --------------------------------------------------------------------------------------------- */
@ -873,8 +889,8 @@ static int
edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
{
FILE *g = NULL;
char *fg, *bg;
char last_fg[32] = "", last_bg[32] = "";
char *fg, *bg, *attrs;
char last_fg[32] = "", last_bg[32] = "", last_attrs[64] = "";
char whole_right[512];
char whole_left[512];
char *l = 0;
@ -1051,11 +1067,15 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
if (*a)
a++;
bg = *a;
if (*a)
a++;
attrs = *a;
if (*a)
a++;
g_strlcpy (last_fg, fg ? fg : "", sizeof (last_fg));
g_strlcpy (last_bg, bg ? bg : "", sizeof (last_bg));
c->keyword[0]->color = this_try_alloc_color_pair (fg, bg);
g_strlcpy (last_attrs, attrs ? attrs : "", sizeof (last_attrs));
c->keyword[0]->color = this_try_alloc_color_pair (fg, bg, attrs);
c->keyword[0]->keyword = g_strdup (" ");
check_not_a;
@ -1120,13 +1140,18 @@ edit_read_syntax_rules (WEdit * edit, FILE * f, char **args, int args_size)
if (*a)
a++;
bg = *a;
if (*a)
a++;
attrs = *a;
if (*a)
a++;
if (!fg)
fg = last_fg;
if (!bg)
bg = last_bg;
k->color = this_try_alloc_color_pair (fg, bg);
if (!attrs)
attrs = last_attrs;
k->color = this_try_alloc_color_pair (fg, bg, attrs);
check_not_a;
if (++num_words >= alloc_words_per_context)