tty: refactoring of color pairs definition.

Rename structure mc_skin_color_t -> tty_color_pair_t and move to lib/tty/color.h.
Rename members.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2023-09-10 12:57:40 +03:00
parent 2c01bd53cb
commit 4a116608d4
4 changed files with 35 additions and 34 deletions

View File

@ -49,11 +49,11 @@ int mc_skin_color__cache[MC_SKIN_COLOR_CACHE_COUNT];
/*** file scope functions ************************************************************************/
/* --------------------------------------------------------------------------------------------- */
static mc_skin_color_t *
static tty_color_pair_t *
mc_skin_color_get_from_hash (mc_skin_t * mc_skin, const gchar * group, const gchar * key)
{
gchar kname[BUF_TINY];
mc_skin_color_t *mc_skin_color;
tty_color_pair_t *mc_skin_color;
if (group == NULL || key == NULL)
return NULL;
@ -62,7 +62,7 @@ mc_skin_color_get_from_hash (mc_skin_t * mc_skin, const gchar * group, const gch
mc_skin = &mc_skin__default;
g_snprintf (kname, sizeof (kname), "%s.%s", group, key);
mc_skin_color = (mc_skin_color_t *) g_hash_table_lookup (mc_skin->colors, (gpointer) kname);
mc_skin_color = (tty_color_pair_t *) g_hash_table_lookup (mc_skin->colors, (gpointer) kname);
return mc_skin_color;
}
@ -89,7 +89,7 @@ mc_skin_color_remove_from_hash (mc_skin_t * mc_skin, const gchar * group, const
static void
mc_skin_color_add_to_hash (mc_skin_t * mc_skin, const gchar * group, const gchar * key,
mc_skin_color_t * mc_skin_color)
tty_color_pair_t * mc_skin_color)
{
gchar *kname;
@ -105,10 +105,10 @@ mc_skin_color_add_to_hash (mc_skin_t * mc_skin, const gchar * group, const gchar
/* --------------------------------------------------------------------------------------------- */
static mc_skin_color_t *
static tty_color_pair_t *
mc_skin_color_get_with_defaults (const gchar * group, const gchar * name)
{
mc_skin_color_t *mc_skin_color;
tty_color_pair_t *mc_skin_color;
mc_skin_color = mc_skin_color_get_from_hash (NULL, group, name);
if (mc_skin_color != NULL)
@ -179,12 +179,12 @@ mc_skin_color_look_up_alias (mc_skin_t * mc_skin, gchar * str)
/* --------------------------------------------------------------------------------------------- */
static mc_skin_color_t *
static tty_color_pair_t *
mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const gchar * key)
{
gsize items_count;
gchar **values;
mc_skin_color_t *mc_skin_color, *tmp;
tty_color_pair_t *mc_skin_color, *tmp;
values = mc_config_get_string_list (mc_skin->config, group, key, &items_count);
if (values == NULL || values[0] == NULL)
@ -193,7 +193,7 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
return NULL;
}
mc_skin_color = g_try_new0 (mc_skin_color_t, 1);
mc_skin_color = g_try_new0 (tty_color_pair_t, 1);
if (mc_skin_color == NULL)
{
g_strfreev (values);
@ -201,12 +201,12 @@ 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_");
mc_skin_color->fgcolor = (items_count > 0 && values[0][0]) ?
mc_skin_color->fg = (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;
mc_skin_color->bgcolor = (items_count > 1 && values[1][0]) ?
(tmp != NULL) ? g_strdup (tmp->fg) : NULL;
mc_skin_color->bg = (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->bg) : NULL;
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;
@ -214,8 +214,8 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
g_strfreev (values);
mc_skin_color->pair_index =
tty_try_alloc_color_pair2 (mc_skin_color->fgcolor, mc_skin_color->bgcolor,
mc_skin_color->attrs, FALSE);
tty_try_alloc_color_pair2 (mc_skin_color->fg, mc_skin_color->bg, mc_skin_color->attrs,
FALSE);
return mc_skin_color;
}
@ -225,15 +225,15 @@ mc_skin_color_get_from_ini_file (mc_skin_t * mc_skin, const gchar * group, const
static void
mc_skin_color_set_default_for_terminal (mc_skin_t * mc_skin)
{
mc_skin_color_t *mc_skin_color;
mc_skin_color = g_try_new0 (mc_skin_color_t, 1);
tty_color_pair_t *mc_skin_color;
mc_skin_color = g_try_new0 (tty_color_pair_t, 1);
if (mc_skin_color != NULL)
{
mc_skin_color->fgcolor = g_strdup ("default");
mc_skin_color->bgcolor = g_strdup ("default");
mc_skin_color->fg = g_strdup ("default");
mc_skin_color->bg = 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,
tty_try_alloc_color_pair2 (mc_skin_color->fg, mc_skin_color->bg,
mc_skin_color->attrs, FALSE);
mc_skin_color_add_to_hash (mc_skin, "skin", "terminal_default_color", mc_skin_color);
}
@ -363,7 +363,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
gboolean ret = FALSE;
gsize items_count;
gchar **groups, **orig_groups;
mc_skin_color_t *mc_skin_color;
tty_color_pair_t *mc_skin_color;
mc_skin_color_check_bw_mode (mc_skin);
@ -377,7 +377,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
if (mc_skin_color == NULL)
goto ret;
tty_color_set_defaults (mc_skin_color->fgcolor, mc_skin_color->bgcolor, mc_skin_color->attrs);
tty_color_set_defaults (mc_skin_color->fg, mc_skin_color->bg, mc_skin_color->attrs);
mc_skin_color_add_to_hash (mc_skin, "core", "_default_", mc_skin_color);
for (groups = orig_groups; *groups != NULL; groups++)
@ -412,7 +412,7 @@ mc_skin_color_parse_ini_file (mc_skin_t * mc_skin)
int
mc_skin_color_get (const gchar * group, const gchar * name)
{
mc_skin_color_t *mc_skin_color;
tty_color_pair_t *mc_skin_color;
mc_skin_color = mc_skin_color_get_with_defaults (group, name);

View File

@ -54,9 +54,10 @@ static gboolean mc_skin_is_init = FALSE;
static void
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);
tty_color_pair_t *mc_skin_color = (tty_color_pair_t *) data;
g_free (mc_skin_color->fg);
g_free (mc_skin_color->bg);
g_free (mc_skin_color->attrs);
g_free (mc_skin_color);
}

View File

@ -10,14 +10,6 @@
/*** structures declarations (and typedefs of structures)*****************************************/
typedef struct mc_skin_color_struct
{
gchar *fgcolor;
gchar *bgcolor;
gchar *attrs;
int pair_index;
} mc_skin_color_t;
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/

View File

@ -21,6 +21,14 @@
/*** typedefs(not structures) and defined constants **********************************************/
typedef struct
{
char *fg;
char *bg;
char *attrs;
size_t pair_index;
} tty_color_pair_t;
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/