Ticket #3711: mc-3711-color-aliases-v2.patch
File mc-3711-color-aliases-v2.patch, 11.9 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..a9b053f 100644
a b Color pair definitions 3708 3708 .\"Skins colors" 3709 3709 .br 3710 3710 .\"LINK2" 3711 Color and attribute aliases 3712 .\"Skins aliases" 3713 .br 3714 .\"LINK2" 3711 3715 Draw lines 3712 3716 .\"Skins lines" 3713 3717 .br … … Colors\&. 3915 3919 .\"Colors" 3916 3920 section. 3917 3921 3922 .\"NODE " Skins aliases" 3923 .SH " Color and attribute aliases" 3924 This optional section might define aliases for single colors (not color pairs) 3925 as well as combination of attributes; in other words, for semicolon-separated 3926 fragments of parameters. Aliases can refer to other aliases as long as they 3927 don't form a loop. 3928 .PP 3929 Example: 3930 .br 3931 .nf 3932 [aliases] 3933 myfavfg=green 3934 myfavbg=black 3935 myfavattr=bold+italic 3936 [core] 3937 _default_=myfavfg;myfavbg;myfavattr 3938 .fi 3939 3918 3940 .\"NODE " Skins lines" 3919 3941 .SH " Draw lines" 3920 3942 Lines sets in section -
lib/skin/colors.c
diff --git a/lib/skin/colors.c b/lib/skin/colors.c index 7f55684..02ef02a 100644
a b 28 28 29 29 #include <config.h> 30 30 #include <string.h> 31 #include <assert.h> 31 32 32 33 #include "internal.h" 33 34 … … mc_skin_color_get_with_defaults (const gchar * group, const gchar * name) 120 121 121 122 /* --------------------------------------------------------------------------------------------- */ 122 123 124 /* If an alias is found, alloc a new string for the resolved value and free the input parameter. 125 Otherwise it's a no-op returning the original string. */ 126 static gchar * 127 mc_skin_color_look_up_alias (mc_skin_t * mc_skin, gchar * str) 128 { 129 gsize items_count; 130 gchar **values; 131 gchar *orig = g_strdup (str); 132 gchar *str2 = g_strdup (str); 133 int hop = 0; 134 135 while (TRUE) 136 { 137 values = mc_config_get_string_list (mc_skin->config, "aliases", str, &items_count); 138 if (items_count != 1) 139 { 140 /* No such alias declaration found, that is, we've got the resolved value. */ 141 g_strfreev (values); 142 g_free (str2); 143 g_free (orig); 144 return str; 145 } 146 g_free (str); 147 str = g_strdup (values[0]); 148 g_strfreev (values); 149 150 /* str2 resolves at half speed than str. This is used for loop detection. */ 151 if (hop++ % 2 != 0) 152 { 153 values = mc_config_get_string_list (mc_skin->config, "aliases", str2, &items_count); 154 assert (items_count == 1); 155 g_free (str2); 156 str2 = g_strdup (values[0]); 157 g_strfreev (values); 158 159 if (strcmp (str, str2) == 0) 160 { 161 /* Loop detected. */ 162 fprintf (stderr, 163 "Loop detected while trying to resolve alias \"%s\" in skin \"%s\"\n", 164 orig, mc_skin->name); 165 g_free (str); 166 g_free (str2); 167 return orig; 168 } 169 } 170 } 171 } 172 173 /* --------------------------------------------------------------------------------------------- */ 174 123 175 static mc_skin_color_t * 124 176 mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const gchar * key) 125 177 { … … mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const 142 194 } 143 195 144 196 tmp = mc_skin_color_get_with_defaults (group, "_default_"); 145 mc_skin_color->fgcolor = (items_count > 0 && values[0][0]) ? g_strstrip (g_strdup (values[0])) : 197 mc_skin_color->fgcolor = (items_count > 0 && values[0][0]) ? 198 mc_skin_color_look_up_alias (mc_skin, g_strstrip (g_strdup (values[0]))) : 146 199 (tmp != NULL) ? g_strdup (tmp->fgcolor) : NULL; 147 mc_skin_color->bgcolor = (items_count > 1 && values[1][0]) ? g_strstrip (g_strdup (values[1])) : 200 mc_skin_color->bgcolor = (items_count > 1 && values[1][0]) ? 201 mc_skin_color_look_up_alias (mc_skin, g_strstrip (g_strdup (values[1]))) : 148 202 (tmp != NULL) ? g_strdup (tmp->bgcolor) : NULL; 149 mc_skin_color->attrs = (items_count > 2 && values[2][0]) ? g_strstrip (g_strdup (values[2])) : 203 mc_skin_color->attrs = (items_count > 2 && values[2][0]) ? 204 mc_skin_color_look_up_alias (mc_skin, g_strstrip (g_strdup (values[2]))) : 150 205 (tmp != NULL) ? g_strdup (tmp->attrs) : NULL; 151 206 152 207 g_strfreev (values); … … mc_skin_color_cache_init (void) 265 320 static gboolean 266 321 mc_skin_color_check_inisection (const gchar * group) 267 322 { 268 return !((strcasecmp ("skin", group) == 0) 323 return !((strcasecmp ("skin", group) == 0) || (strcasecmp ("aliases", group) == 0) 269 324 || (strcasecmp ("lines", group) == 0) || (strncasecmp ("widget-", group, 7) == 0)); 270 325 } 271 326 -
misc/skins/gray-green-purple256.ini
diff --git a/misc/skins/gray-green-purple256.ini b/misc/skins/gray-green-purple256.ini index 964b26f..f6ea39a 100644
a b 25 25 dleftmiddle = ╟ 26 26 drightmiddle = ╢ 27 27 28 [aliases] 29 bgmain = gray22 30 bgbitdarker = gray21 31 bgdarker = gray20 32 main1 = rgb141 33 main2 = rgb303 34 28 35 [core] 29 _default_ = black; gray2230 selected = ; rgb14131 marked = rgb303;;bold32 markselect = rgb303;rgb141;bold33 gauge = ; rgb14136 _default_ = black;bgmain 37 selected = ;main1 38 marked = main2;;bold 39 markselect = main2;main1;bold 40 gauge = ;main1 34 41 input = 35 42 inputunchanged = gray 36 inputmark = ; rgb14137 disabled = gray8; gray2043 inputmark = ;main1 44 disabled = gray8;bgdarker 38 45 reverse = 39 commandlinemark = ; rgb14140 header = rgb30346 commandlinemark = ;main1 47 header = main2 41 48 42 49 [dialog] 43 _default_ = black; gray2044 dfocus = ; rgb14145 dhotnormal = rgb30346 dhotfocus = rgb303;rgb14147 dtitle = rgb30350 _default_ = black;bgdarker 51 dfocus = ;main1 52 dhotnormal = main2 53 dhotfocus = main2;main1 54 dtitle = main2 48 55 49 56 [error] 50 57 # "white" might change color when going bold, so use "rgb555" instead 51 58 _default_ = rgb555;rgb400;bold 52 errdfocus = ; rgb30353 errdhotnormal = rgb14154 errdhotfocus = rgb141;rgb30355 errdtitle = rgb14159 errdfocus = ;main2 60 errdhotnormal = main1 61 errdhotfocus = main1;main2 62 errdtitle = main1 56 63 57 64 [filehighlight] 58 65 directory = … … 72 79 database = rgb421 73 80 74 81 [menu] 75 _default_ = black; gray2076 menusel = ; rgb14177 menuhot = rgb30378 menuhotsel = rgb303;rgb14182 _default_ = black;bgdarker 83 menusel = ;main1 84 menuhot = main2 85 menuhotsel = main2;main1 79 86 menuinactive = 80 87 81 88 [popupmenu] 82 _default_ = black; gray2083 menusel = ; rgb14184 menutitle = rgb30389 _default_ = black;bgdarker 90 menusel = ;main1 91 menutitle = main2 85 92 86 93 [buttonbar] 87 hotkey = black; gray2288 button = black; gray2094 hotkey = black;bgmain 95 button = black;bgdarker 89 96 90 97 [statusbar] 91 _default_ = black; gray2098 _default_ = black;bgdarker 92 99 93 100 [help] 94 _default_ = black; gray20101 _default_ = black;bgdarker 95 102 helpitalic = rgb020 96 103 helpbold = rgb300 97 helplink = rgb303;;underline98 helpslink = gray20;rgb30399 helptitle = rgb303104 helplink = main2;;underline 105 helpslink = bgdarker;main2 106 helptitle = main2 100 107 101 108 [editor] 102 _default_ = black; gray22109 _default_ = black;bgmain 103 110 editbold = rgb400 104 editmarked = ; rgb141105 editwhitespace = rgb400; gray20106 editlinestate = ; gray20111 editmarked = ;main1 112 editwhitespace = rgb400;bgdarker 113 editlinestate = ;bgdarker 107 114 bookmark = ;rgb531 108 bookmarkfound = ; rgb303109 editrightmargin = rgb400; gray20115 bookmarkfound = ;main2 116 editrightmargin = rgb400;bgdarker 110 117 # editbg = 111 editframe = rgb303;118 editframe = main2; 112 119 editframeactive = black; 113 120 editframedrag = rgb400; 114 121 window-state-char = ↕ 115 122 window-close-char = ✕ 116 123 117 124 [viewer] 118 _default_ = black; gray22125 _default_ = black;bgmain 119 126 # "black" might change color when going bold, so use "rgb000" instead 120 127 viewbold = rgb000;;bold 121 128 viewunderline = ;;underline 122 viewselected = rgb303;rgb141;bold129 viewselected = main2;main1;bold 123 130 124 131 [diffviewer] 125 132 added = ;rgb340 126 changedline = ; gray20127 changednew = rgb303;gray20128 changed = ; gray21133 changedline = ;bgdarker 134 changednew = main2;bgdarker 135 changed = ;bgbitdarker 129 136 removed = ;rgb511 130 137 # "white" might change color when going bold, so use "rgb555" instead 131 138 error = rgb555;rgb400;bold -
misc/skins/gray-orange-blue256.ini
diff --git a/misc/skins/gray-orange-blue256.ini b/misc/skins/gray-orange-blue256.ini index f8426f1..027b679 100644
a b 25 25 dleftmiddle = ╟ 26 26 drightmiddle = ╢ 27 27 28 [aliases] 29 bgmain = gray22 30 bgbitdarker = gray21 31 bgdarker = gray20 32 main1 = rgb530 33 main2 = rgb004 34 28 35 [core] 29 _default_ = black; gray2230 selected = ; rgb53031 marked = rgb004;;bold32 markselect = rgb004;rgb530;bold33 gauge = ; rgb53036 _default_ = black;bgmain 37 selected = ;main1 38 marked = main2;;bold 39 markselect = main2;main1;bold 40 gauge = ;main1 34 41 input = 35 42 inputunchanged = gray 36 inputmark = ; rgb53037 disabled = gray8; gray2043 inputmark = ;main1 44 disabled = gray8;bgdarker 38 45 reverse = 39 commandlinemark = ; rgb53040 header = rgb00446 commandlinemark = ;main1 47 header = main2 41 48 42 49 [dialog] 43 _default_ = black; gray2044 dfocus = ; rgb53045 dhotnormal = rgb00446 dhotfocus = rgb004;rgb53047 dtitle = rgb00450 _default_ = black;bgdarker 51 dfocus = ;main1 52 dhotnormal = main2 53 dhotfocus = main2;main1 54 dtitle = main2 48 55 49 56 [error] 50 57 # "white" might change color when going bold, so use "rgb555" instead 51 58 _default_ = rgb555;rgb400;bold 52 errdfocus = ; rgb00453 errdhotnormal = rgb53054 errdhotfocus = rgb530;rgb00455 errdtitle = rgb53059 errdfocus = ;main2 60 errdhotnormal = main1 61 errdhotfocus = main1;main2 62 errdtitle = main1 56 63 57 64 [filehighlight] 58 65 directory = … … 72 79 database = rgb421 73 80 74 81 [menu] 75 _default_ = black; gray2076 menusel = ; rgb53077 menuhot = rgb00478 menuhotsel = rgb004;rgb53082 _default_ = black;bgdarker 83 menusel = ;main1 84 menuhot = main2 85 menuhotsel = main2;main1 79 86 menuinactive = 80 87 81 88 [popupmenu] 82 _default_ = black; gray2083 menusel = ; rgb53084 menutitle = rgb00489 _default_ = black;bgdarker 90 menusel = ;main1 91 menutitle = main2 85 92 86 93 [buttonbar] 87 hotkey = black; gray2288 button = black; gray2094 hotkey = black;bgmain 95 button = black;bgdarker 89 96 90 97 [statusbar] 91 _default_ = black; gray2098 _default_ = black;bgdarker 92 99 93 100 [help] 94 _default_ = black; gray20101 _default_ = black;bgdarker 95 102 helpitalic = rgb020 96 103 helpbold = rgb300 97 helplink = rgb004;;underline98 helpslink = gray20;rgb00499 helptitle = rgb004104 helplink = main2;;underline 105 helpslink = bgdarker;main2 106 helptitle = main2 100 107 101 108 [editor] 102 _default_ = black; gray22109 _default_ = black;bgmain 103 110 editbold = rgb400 104 editmarked = ; rgb530105 editwhitespace = rgb400; gray20106 editlinestate = ; gray20111 editmarked = ;main1 112 editwhitespace = rgb400;bgdarker 113 editlinestate = ;bgdarker 107 114 bookmark = ;rgb531 108 bookmarkfound = ; rgb004109 editrightmargin = rgb400; gray20115 bookmarkfound = ;main2 116 editrightmargin = rgb400;bgdarker 110 117 # editbg = 111 editframe = rgb004;118 editframe = main2; 112 119 editframeactive = black; 113 120 editframedrag = rgb400; 114 121 window-state-char = ↕ 115 122 window-close-char = ✕ 116 123 117 124 [viewer] 118 _default_ = black; gray22125 _default_ = black;bgmain 119 126 # "black" might change color when going bold, so use "rgb000" instead 120 127 viewbold = rgb000;;bold 121 128 viewunderline = ;;underline 122 viewselected = rgb004;rgb530;bold129 viewselected = main2;main1;bold 123 130 124 131 [diffviewer] 125 132 added = ;rgb340 126 changedline = ; gray20127 changednew = rgb004;gray20128 changed = ; gray21133 changedline = ;bgdarker 134 changednew = main2;bgdarker 135 changed = ;bgbitdarker 129 136 removed = ;rgb511 130 137 # "white" might change color when going bold, so use "rgb555" instead 131 138 error = rgb555;rgb400;bold