From 5b167ccc9e7d18f9217e16c30197ee7ddff6cc99 Mon Sep 17 00:00:00 2001 From: Slava Zanko Date: Sun, 16 Jan 2011 02:13:48 +0200 Subject: [PATCH] fail back to standard skin if 256-colors skin used on non256 colors terminal Signed-off-by: Slava Zanko --- lib/skin.h | 5 +++-- lib/skin/common.c | 18 +++++++++++++++++- lib/skin/ini-file.c | 1 + lib/tty/color.c | 2 +- misc/skins/sand256.ini | 1 + misc/skins/xoria256.ini | 1 + 6 files changed, 24 insertions(+), 4 deletions(-) diff --git a/lib/skin.h b/lib/skin.h index 7ea332769..58ac915ce 100644 --- a/lib/skin.h +++ b/lib/skin.h @@ -47,8 +47,8 @@ /* Popup menu colors */ #define PMENU_ENTRY_COLOR mc_skin_color__cache[24] #define PMENU_SELECTED_COLOR mc_skin_color__cache[25] -#define PMENU_HOT_COLOR mc_skin_color__cache[26] /* unused: not implemented yet */ -#define PMENU_HOTSEL_COLOR mc_skin_color__cache[27] /* unused: not implemented yet */ +#define PMENU_HOT_COLOR mc_skin_color__cache[26] /* unused: not implemented yet */ +#define PMENU_HOTSEL_COLOR mc_skin_color__cache[27] /* unused: not implemented yet */ #define PMENU_TITLE_COLOR mc_skin_color__cache[28] #define BUTTONBAR_HOTKEY_COLOR mc_skin_color__cache[29] @@ -115,6 +115,7 @@ typedef struct mc_skin_struct gchar *description; mc_config_t *config; GHashTable *colors; + gboolean have_256_colors; } mc_skin_t; /*** global variables defined in .c file *********************************************************/ diff --git a/lib/skin/common.c b/lib/skin/common.c index d45d4c9e4..ebf85ff8a 100644 --- a/lib/skin/common.c +++ b/lib/skin/common.c @@ -31,6 +31,8 @@ #include "internal.h" +#include "lib/tty/color.h" /* tty_use_256colors(); */ + #include "src/args.h" /*** global variables ****************************************************************************/ @@ -115,11 +117,12 @@ mc_skin_init (GError ** error) { gboolean is_good_init = TRUE; + mc_skin__default.have_256_colors = FALSE; + mc_skin__default.name = mc_skin_get_default_name (); mc_skin__default.colors = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, mc_skin_hash_destroy_value); - if (!mc_skin_ini_file_load (&mc_skin__default)) { *error = g_error_new (MC_ERROR, 0, @@ -143,6 +146,19 @@ mc_skin_init (GError ** error) (void) mc_skin_ini_file_parse (&mc_skin__default); is_good_init = FALSE; } + if ( is_good_init && !tty_use_256colors () && mc_skin__default.have_256_colors ) + { + if (*error == NULL) + *error = g_error_new (MC_ERROR, 0, + _ + ("Unable to use '%s' skin with 256 colors support\non non-256 colors terminal.\nDefault skin has been loaded"), + mc_skin__default.name); + + mc_skin_try_to_load_default (); + mc_skin_colors_old_configure (&mc_skin__default); + (void) mc_skin_ini_file_parse (&mc_skin__default); + is_good_init = FALSE; + } mc_skin_is_init = TRUE; return is_good_init; } diff --git a/lib/skin/ini-file.c b/lib/skin/ini-file.c index 5adb587de..757523379 100644 --- a/lib/skin/ini-file.c +++ b/lib/skin/ini-file.c @@ -120,6 +120,7 @@ mc_skin_ini_file_parse (mc_skin_t * mc_skin) return FALSE; mc_skin_lines_parse_ini_file (mc_skin); + mc_skin->have_256_colors = mc_config_get_bool (mc_skin->config, "skin", "256colors", FALSE); return TRUE; } diff --git a/lib/tty/color.c b/lib/tty/color.c index 809139d5b..bcb553dba 100644 --- a/lib/tty/color.c +++ b/lib/tty/color.c @@ -232,7 +232,7 @@ void 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__bg); g_free (tty_color_defaults__attrs); tty_color_defaults__fg = (fgcolor != NULL) ? g_strdup (fgcolor) : NULL; diff --git a/misc/skins/sand256.ini b/misc/skins/sand256.ini index 84f56e66f..64fb56810 100644 --- a/misc/skins/sand256.ini +++ b/misc/skins/sand256.ini @@ -53,6 +53,7 @@ [skin] description=Sand skin using 256 colors + 256colors=true [Lines] horiz=─ diff --git a/misc/skins/xoria256.ini b/misc/skins/xoria256.ini index c452f1f1f..d1714227a 100644 --- a/misc/skins/xoria256.ini +++ b/misc/skins/xoria256.ini @@ -14,6 +14,7 @@ [skin] description=Xoria256 + 256colors=true # [Lines] # horiz=─