1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-12-04 14:46:47 -05:00

[colors] One function instead of two for COLOR_MODE_16

This commit is contained in:
Witold Filipczyk 2022-03-20 15:24:15 +01:00
parent 1b9072307a
commit 411b25cecc
3 changed files with 28 additions and 47 deletions

View File

@ -57,8 +57,8 @@ get_bfu_mono_node(unsigned int node_number)
return &entry->mono;
}
unsigned char *
get_bfu_background_color16_node(unsigned int node_number)
struct screen_char *
get_bfu_color16_node(unsigned int node_number)
{
struct bfu_color_entry *entry = node_entries[node_number];
@ -67,20 +67,7 @@ get_bfu_background_color16_node(unsigned int node_number)
entry->was_color16 = 1;
}
return &entry->c16.c.color[0];
}
unsigned char *
get_bfu_foreground_color16_node(unsigned int node_number)
{
struct bfu_color_entry *entry = node_entries[node_number];
if (!entry->was_color16) {
set_term_color(&entry->c16, &entry->colors, 0, COLOR_MODE_16);
entry->was_color16 = 1;
}
return &entry->c16.c.color[0];
return &entry->c16;
}
unsigned char
@ -183,6 +170,7 @@ get_bfu_color_common(struct terminal *term, const char *stylename)
last_color_mode = color_mode;
} else if (color_mode != last_color_mode) {
#if 0
int i;
/* Change mode by emptying the cache so mono/color colors
@ -192,7 +180,7 @@ get_bfu_color_common(struct terminal *term, const char *stylename)
item = item->prev;
del_hash_item(bfu_colors, item->next);
}
#endif
last_color_mode = color_mode;
}

View File

@ -29,8 +29,7 @@ get_bfu_color(struct terminal *term, const char *stylename);
unsigned int get_bfu_color_node(struct terminal *term, const char *stylename);
struct screen_char *get_bfu_mono_node(unsigned int node_number);
unsigned char *get_bfu_background_color16_node(unsigned int node_number);
unsigned char *get_bfu_foreground_color16_node(unsigned int node_number);
struct screen_char *get_bfu_color16_node(unsigned int node_number);
unsigned char get_bfu_background_color88_node(unsigned int node_number);
unsigned char get_bfu_foreground_color88_node(unsigned int node_number);
unsigned char get_bfu_background_color256_node(unsigned int node_number);

View File

@ -444,9 +444,7 @@ static const struct screen_driver_opt *const screen_driver_opts[] = {
static INIT_LIST_OF(struct screen_driver, active_screen_drivers);
static struct screen_char *get_mono_from_node(struct screen_char *ch);
static unsigned char *get_foreground_color16_from_node(struct screen_char *ch);
static unsigned char *get_background_color16_from_node(struct screen_char *ch);
static struct screen_char *get_color16_from_node(struct screen_char *ch);
/** Set screen_driver.opt according to screen_driver.type and @a term_spec.
* Other members of @a *driver need not have been initialized.
@ -879,10 +877,20 @@ static inline void
add_char16(struct string *screen, struct screen_driver *driver,
struct screen_char *ch, struct screen_state *state)
{
if ((driver->opt.color_mode == COLOR_MODE_MONO) && ch->is_node) {
struct screen_char *ch2 = get_mono_from_node(ch);
struct screen_char copy;
ch->attr |= ch2->attr;
if (ch->is_node) {
copy = *ch;
copy.is_node = 0;
if (driver->opt.color_mode == COLOR_MODE_MONO) {
struct screen_char *ch2 = get_mono_from_node(ch);
copy.attr |= ch2->attr;
} else {
struct screen_char *ch2 = get_color16_from_node(ch);
copy.c.color[0] = ch2->c.color[0];
}
ch = ©
}
unsigned char border = (ch->attr & SCREEN_ATTR_FRAME);
@ -967,8 +975,8 @@ add_char16(struct string *screen, struct screen_driver *driver,
#ifdef CONFIG_TERMINFO
if (driver->opt.terminfo) {
add_to_string(screen, terminfo_set_bold(bold));
add_to_string(screen, terminfo_set_foreground(TERM_COLOR_FOREGROUND_16(get_foreground_color16_from_node(ch))));
add_to_string(screen, terminfo_set_background(TERM_COLOR_BACKGROUND_16(get_background_color16_from_node(ch))));
add_to_string(screen, terminfo_set_foreground(TERM_COLOR_FOREGROUND_16(ch->c.color)));
add_to_string(screen, terminfo_set_background(TERM_COLOR_BACKGROUND_16(ch->c.color)));
if (italic)
add_to_string(screen, terminfo_set_italics(italic));
@ -991,9 +999,9 @@ add_char16(struct string *screen, struct screen_driver *driver,
* - An unsupported color mode. Use 16 colors. */
if (driver->opt.color_mode != COLOR_MODE_MONO) {
char code[] = ";30;40";
unsigned char bgcolor = TERM_COLOR_BACKGROUND_16(get_background_color16_from_node(ch));
unsigned char bgcolor = TERM_COLOR_BACKGROUND_16(ch->c.color);
code[2] += TERM_COLOR_FOREGROUND_16(get_foreground_color16_from_node(ch));
code[2] += TERM_COLOR_FOREGROUND_16(ch->c.color);
if (!driver->opt.transparent || bgcolor != 0) {
code[5] += bgcolor;
@ -1139,32 +1147,18 @@ get_mono_from_node(struct screen_char *ch)
return ch;
}
static unsigned char *
get_background_color16_from_node(struct screen_char *ch)
static struct screen_char *
get_color16_from_node(struct screen_char *ch)
{
if (ch->is_node) {
unsigned int node_number = ch->c.node_number;
if (node_number < 1024) {
return get_bfu_background_color16_node(node_number);
return get_bfu_color16_node(node_number);
}
}
return &ch->c.color[0];
}
static unsigned char *
get_foreground_color16_from_node(struct screen_char *ch)
{
if (ch->is_node) {
unsigned int node_number = ch->c.node_number;
if (node_number < 1024) {
return get_bfu_foreground_color16_node(node_number);
}
}
return &ch->c.color[0];
return ch;
}
static inline void