Skip to content

Commit b6349a8

Browse files
committed
slang: Use index-based color identifiers
Don't pass color names like "black", "red" to slang, instead pass index-based identifiers like "color0", "color1" etc. This is in preparation for the next commit in which mc will diverge from slang's color names. Signed-off-by: Egmont Koblinger <egmont@gmail.com>
1 parent 2e67e99 commit b6349a8

3 files changed

Lines changed: 18 additions & 28 deletions

File tree

lib/tty/color-internal.c

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -161,33 +161,6 @@ parse_256_or_true_color_name (const char *color_name)
161161
/*** public functions ****************************************************************************/
162162
/* --------------------------------------------------------------------------------------------- */
163163

164-
const char *
165-
tty_color_get_name_by_index (int idx)
166-
{
167-
int i;
168-
169-
// Find the real English name of the first 16 colors,
170-
// as well as the A_* special values.
171-
for (i = 0; color_table[i].name != NULL; i++)
172-
if (idx == color_table[i].value)
173-
return color_table[i].name;
174-
175-
// Create and return the strings in "colorNNN" or "#rrggbb" format.
176-
if ((idx >= 16 && idx < 256) || (idx & FLAG_TRUECOLOR) != 0)
177-
{
178-
char name[9];
179-
180-
if (idx < 256)
181-
g_snprintf (name, sizeof (name), "color%d", idx);
182-
else
183-
g_snprintf (name, sizeof (name), "#%06X", (unsigned int) idx & 0xFFFFFF);
184-
return g_intern_string (name);
185-
}
186-
return "default";
187-
}
188-
189-
/* --------------------------------------------------------------------------------------------- */
190-
191164
int
192165
tty_color_get_index_by_name (const char *color_name)
193166
{

lib/tty/color-internal.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ extern gboolean need_convert_256color;
4343

4444
/*** declarations of public functions ************************************************************/
4545

46-
const char *tty_color_get_name_by_index (int idx);
4746
int tty_color_get_index_by_name (const char *color_name);
4847
int tty_attr_get_bits (const char *attrs);
4948
int convert_256color_to_truecolor (int color);

lib/tty/color-slang.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,24 @@ tty_color_deinit_lib (void)
128128

129129
/* --------------------------------------------------------------------------------------------- */
130130

131+
static const char *
132+
tty_color_get_name_by_index (int idx)
133+
{
134+
if (idx >= 0 && (idx < 256 || (idx & FLAG_TRUECOLOR) != 0))
135+
{
136+
char name[9];
137+
138+
if (idx < 256)
139+
g_snprintf (name, sizeof (name), "color%d", idx);
140+
else
141+
g_snprintf (name, sizeof (name), "#%06X", (unsigned int) idx & 0xFFFFFF);
142+
return g_intern_string (name);
143+
}
144+
return "default";
145+
}
146+
147+
/* --------------------------------------------------------------------------------------------- */
148+
131149
void
132150
tty_color_try_alloc_lib_pair (tty_color_lib_pair_t *mc_color_pair)
133151
{

0 commit comments

Comments
 (0)