Ticket #3711: support color aliases in skin files.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Egmont Koblinger 2016-11-14 13:51:19 +03:00 committed by Andrew Borodin
parent fc3d153b67
commit 0cceb99c2e
4 changed files with 186 additions and 92 deletions

View File

@ -3708,6 +3708,10 @@ Color pair definitions
.\"Skins colors" .\"Skins colors"
.br .br
.\"LINK2" .\"LINK2"
Color and attribute aliases
.\"Skins aliases"
.br
.\"LINK2"
Draw lines Draw lines
.\"Skins lines" .\"Skins lines"
.br .br
@ -3915,6 +3919,24 @@ Colors\&.
.\"Colors" .\"Colors"
section. section.
.\"NODE " Skins aliases"
.SH " Color and attribute aliases"
This optional section might define aliases for single colors (not color pairs)
as well as combination of attributes; in other words, for semicolon\-separated
fragments of parameters. Aliases can refer to other aliases as long as they
don't form a loop.
.PP
Example:
.br
.nf
[aliases]
myfavfg=green
myfavbg=black
myfavattr=bold+italic
[core]
_default_=myfavfg;myfavbg;myfavattr
.fi
.\"NODE " Skins lines" .\"NODE " Skins lines"
.SH " Draw lines" .SH " Draw lines"
Lines sets in section Lines sets in section

View File

@ -120,6 +120,61 @@ mc_skin_color_get_with_defaults (const gchar * group, const gchar * name)
/* --------------------------------------------------------------------------------------------- */ /* --------------------------------------------------------------------------------------------- */
/* If an alias is found, alloc a new string for the resolved value and free the input parameter.
Otherwise it's a no-op returning the original string. */
static gchar *
mc_skin_color_look_up_alias (mc_skin_t * mc_skin, gchar * str)
{
gchar *orig, *str2;
int hop = 0;
orig = g_strdup (str);
str2 = g_strdup (str);
while (TRUE)
{
gchar **values;
gsize items_count;
values = mc_config_get_string_list (mc_skin->config, "aliases", str, &items_count);
if (items_count != 1)
{
/* No such alias declaration found, that is, we've got the resolved value. */
g_strfreev (values);
g_free (str2);
g_free (orig);
return str;
}
g_free (str);
str = g_strdup (values[0]);
g_strfreev (values);
/* str2 resolves at half speed than str. This is used for loop detection. */
if (hop++ % 2 != 0)
{
values = mc_config_get_string_list (mc_skin->config, "aliases", str2, &items_count);
g_assert (items_count == 1);
g_free (str2);
str2 = g_strdup (values[0]);
g_strfreev (values);
if (strcmp (str, str2) == 0)
{
/* Loop detected. */
fprintf (stderr,
"Loop detected while trying to resolve alias \"%s\" in skin \"%s\"\n",
orig, mc_skin->name);
g_free (str);
g_free (str2);
return orig;
}
}
}
}
/* --------------------------------------------------------------------------------------------- */
static mc_skin_color_t * static mc_skin_color_t *
mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const gchar * key) mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const gchar * key)
{ {
@ -142,11 +197,14 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
} }
tmp = mc_skin_color_get_with_defaults (group, "_default_"); 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])) : mc_skin_color->fgcolor = (items_count > 0 && values[0][0]) ?
mc_skin_color_look_up_alias (mc_skin, g_strstrip (g_strdup (values[0]))) :
(tmp != NULL) ? g_strdup (tmp->fgcolor) : NULL; (tmp != NULL) ? g_strdup (tmp->fgcolor) : NULL;
mc_skin_color->bgcolor = (items_count > 1 && values[1][0]) ? g_strstrip (g_strdup (values[1])) : mc_skin_color->bgcolor = (items_count > 1 && values[1][0]) ?
mc_skin_color_look_up_alias (mc_skin, g_strstrip (g_strdup (values[1]))) :
(tmp != NULL) ? g_strdup (tmp->bgcolor) : NULL; (tmp != NULL) ? g_strdup (tmp->bgcolor) : NULL;
mc_skin_color->attrs = (items_count > 2 && values[2][0]) ? g_strstrip (g_strdup (values[2])) : mc_skin_color->attrs = (items_count > 2 && values[2][0]) ?
mc_skin_color_look_up_alias (mc_skin, g_strstrip (g_strdup (values[2]))) :
(tmp != NULL) ? g_strdup (tmp->attrs) : NULL; (tmp != NULL) ? g_strdup (tmp->attrs) : NULL;
g_strfreev (values); g_strfreev (values);
@ -265,7 +323,7 @@ mc_skin_color_cache_init (void)
static gboolean static gboolean
mc_skin_color_check_inisection (const gchar * group) mc_skin_color_check_inisection (const gchar * group)
{ {
return !((strcasecmp ("skin", group) == 0) return !((strcasecmp ("skin", group) == 0) || (strcasecmp ("aliases", group) == 0)
|| (strcasecmp ("lines", group) == 0) || (strncasecmp ("widget-", group, 7) == 0)); || (strcasecmp ("lines", group) == 0) || (strncasecmp ("widget-", group, 7) == 0));
} }

View File

@ -25,34 +25,41 @@
dleftmiddle = dleftmiddle =
drightmiddle = drightmiddle =
[aliases]
bgmain = gray22
bgbitdarker = gray21
bgdarker = gray20
main1 = rgb141
main2 = rgb303
[core] [core]
_default_ = black;gray22 _default_ = black;bgmain
selected = ;rgb141 selected = ;main1
marked = rgb303;;bold marked = main2;;bold
markselect = rgb303;rgb141;bold markselect = main2;main1;bold
gauge = ;rgb141 gauge = ;main1
input = input =
inputunchanged = gray inputunchanged = gray
inputmark = ;rgb141 inputmark = ;main1
disabled = gray8;gray20 disabled = gray8;bgdarker
reverse = reverse =
commandlinemark = ;rgb141 commandlinemark = ;main1
header = rgb303 header = main2
[dialog] [dialog]
_default_ = black;gray20 _default_ = black;bgdarker
dfocus = ;rgb141 dfocus = ;main1
dhotnormal = rgb303 dhotnormal = main2
dhotfocus = rgb303;rgb141 dhotfocus = main2;main1
dtitle = rgb303 dtitle = main2
[error] [error]
# "white" might change color when going bold, so use "rgb555" instead # "white" might change color when going bold, so use "rgb555" instead
_default_ = rgb555;rgb400;bold _default_ = rgb555;rgb400;bold
errdfocus = ;rgb303 errdfocus = ;main2
errdhotnormal = rgb141 errdhotnormal = main1
errdhotfocus = rgb141;rgb303 errdhotfocus = main1;main2
errdtitle = rgb141 errdtitle = main1
[filehighlight] [filehighlight]
directory = directory =
@ -72,60 +79,60 @@
database = rgb421 database = rgb421
[menu] [menu]
_default_ = black;gray20 _default_ = black;bgdarker
menusel = ;rgb141 menusel = ;main1
menuhot = rgb303 menuhot = main2
menuhotsel = rgb303;rgb141 menuhotsel = main2;main1
menuinactive = menuinactive =
[popupmenu] [popupmenu]
_default_ = black;gray20 _default_ = black;bgdarker
menusel = ;rgb141 menusel = ;main1
menutitle = rgb303 menutitle = main2
[buttonbar] [buttonbar]
hotkey = black;gray22 hotkey = black;bgmain
button = black;gray20 button = black;bgdarker
[statusbar] [statusbar]
_default_ = black;gray20 _default_ = black;bgdarker
[help] [help]
_default_ = black;gray20 _default_ = black;bgdarker
helpitalic = rgb020 helpitalic = rgb020
helpbold = rgb300 helpbold = rgb300
helplink = rgb303;;underline helplink = main2;;underline
helpslink = gray20;rgb303 helpslink = bgdarker;main2
helptitle = rgb303 helptitle = main2
[editor] [editor]
_default_ = black;gray22 _default_ = black;bgmain
editbold = rgb400 editbold = rgb400
editmarked = ;rgb141 editmarked = ;main1
editwhitespace = rgb400;gray20 editwhitespace = rgb400;bgdarker
editlinestate = ;gray20 editlinestate = ;bgdarker
bookmark = ;rgb531 bookmark = ;rgb531
bookmarkfound = ;rgb303 bookmarkfound = ;main2
editrightmargin = rgb400;gray20 editrightmargin = rgb400;bgdarker
# editbg = # editbg =
editframe = rgb303; editframe = main2;
editframeactive = black; editframeactive = black;
editframedrag = rgb400; editframedrag = rgb400;
window-state-char = window-state-char =
window-close-char = window-close-char =
[viewer] [viewer]
_default_ = black;gray22 _default_ = black;bgmain
# "black" might change color when going bold, so use "rgb000" instead # "black" might change color when going bold, so use "rgb000" instead
viewbold = rgb000;;bold viewbold = rgb000;;bold
viewunderline = ;;underline viewunderline = ;;underline
viewselected = rgb303;rgb141;bold viewselected = main2;main1;bold
[diffviewer] [diffviewer]
added = ;rgb340 added = ;rgb340
changedline = ;gray20 changedline = ;bgdarker
changednew = rgb303;gray20 changednew = main2;bgdarker
changed = ;gray21 changed = ;bgbitdarker
removed = ;rgb511 removed = ;rgb511
# "white" might change color when going bold, so use "rgb555" instead # "white" might change color when going bold, so use "rgb555" instead
error = rgb555;rgb400;bold error = rgb555;rgb400;bold

View File

@ -25,34 +25,41 @@
dleftmiddle = dleftmiddle =
drightmiddle = drightmiddle =
[aliases]
bgmain = gray22
bgbitdarker = gray21
bgdarker = gray20
main1 = rgb530
main2 = rgb004
[core] [core]
_default_ = black;gray22 _default_ = black;bgmain
selected = ;rgb530 selected = ;main1
marked = rgb004;;bold marked = main2;;bold
markselect = rgb004;rgb530;bold markselect = main2;main1;bold
gauge = ;rgb530 gauge = ;main1
input = input =
inputunchanged = gray inputunchanged = gray
inputmark = ;rgb530 inputmark = ;main1
disabled = gray8;gray20 disabled = gray8;bgdarker
reverse = reverse =
commandlinemark = ;rgb530 commandlinemark = ;main1
header = rgb004 header = main2
[dialog] [dialog]
_default_ = black;gray20 _default_ = black;bgdarker
dfocus = ;rgb530 dfocus = ;main1
dhotnormal = rgb004 dhotnormal = main2
dhotfocus = rgb004;rgb530 dhotfocus = main2;main1
dtitle = rgb004 dtitle = main2
[error] [error]
# "white" might change color when going bold, so use "rgb555" instead # "white" might change color when going bold, so use "rgb555" instead
_default_ = rgb555;rgb400;bold _default_ = rgb555;rgb400;bold
errdfocus = ;rgb004 errdfocus = ;main2
errdhotnormal = rgb530 errdhotnormal = main1
errdhotfocus = rgb530;rgb004 errdhotfocus = main1;main2
errdtitle = rgb530 errdtitle = main1
[filehighlight] [filehighlight]
directory = directory =
@ -72,60 +79,60 @@
database = rgb421 database = rgb421
[menu] [menu]
_default_ = black;gray20 _default_ = black;bgdarker
menusel = ;rgb530 menusel = ;main1
menuhot = rgb004 menuhot = main2
menuhotsel = rgb004;rgb530 menuhotsel = main2;main1
menuinactive = menuinactive =
[popupmenu] [popupmenu]
_default_ = black;gray20 _default_ = black;bgdarker
menusel = ;rgb530 menusel = ;main1
menutitle = rgb004 menutitle = main2
[buttonbar] [buttonbar]
hotkey = black;gray22 hotkey = black;bgmain
button = black;gray20 button = black;bgdarker
[statusbar] [statusbar]
_default_ = black;gray20 _default_ = black;bgdarker
[help] [help]
_default_ = black;gray20 _default_ = black;bgdarker
helpitalic = rgb020 helpitalic = rgb020
helpbold = rgb300 helpbold = rgb300
helplink = rgb004;;underline helplink = main2;;underline
helpslink = gray20;rgb004 helpslink = bgdarker;main2
helptitle = rgb004 helptitle = main2
[editor] [editor]
_default_ = black;gray22 _default_ = black;bgmain
editbold = rgb400 editbold = rgb400
editmarked = ;rgb530 editmarked = ;main1
editwhitespace = rgb400;gray20 editwhitespace = rgb400;bgdarker
editlinestate = ;gray20 editlinestate = ;bgdarker
bookmark = ;rgb531 bookmark = ;rgb531
bookmarkfound = ;rgb004 bookmarkfound = ;main2
editrightmargin = rgb400;gray20 editrightmargin = rgb400;bgdarker
# editbg = # editbg =
editframe = rgb004; editframe = main2;
editframeactive = black; editframeactive = black;
editframedrag = rgb400; editframedrag = rgb400;
window-state-char = window-state-char =
window-close-char = window-close-char =
[viewer] [viewer]
_default_ = black;gray22 _default_ = black;bgmain
# "black" might change color when going bold, so use "rgb000" instead # "black" might change color when going bold, so use "rgb000" instead
viewbold = rgb000;;bold viewbold = rgb000;;bold
viewunderline = ;;underline viewunderline = ;;underline
viewselected = rgb004;rgb530;bold viewselected = main2;main1;bold
[diffviewer] [diffviewer]
added = ;rgb340 added = ;rgb340
changedline = ;gray20 changedline = ;bgdarker
changednew = rgb004;gray20 changednew = main2;bgdarker
changed = ;gray21 changed = ;bgbitdarker
removed = ;rgb511 removed = ;rgb511
# "white" might change color when going bold, so use "rgb555" instead # "white" might change color when going bold, so use "rgb555" instead
error = rgb555;rgb400;bold error = rgb555;rgb400;bold