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

[colors] COLOR_MODE_16

Some bugs left.
This commit is contained in:
Witold Filipczyk 2022-03-18 17:00:25 +01:00
parent 9b1b2f4590
commit e8719ba9e7
3 changed files with 67 additions and 4 deletions

View File

@ -27,9 +27,11 @@ struct bfu_color_entry {
unsigned int node_number;
unsigned int was_color16_set:1;
unsigned int was_color256_set:1;
unsigned int was_color24_set:1;
struct screen_char c16;
struct screen_char c256;
struct screen_char c24;
};
@ -38,6 +40,32 @@ struct bfu_color_entry *node_entries[1024];
static struct hash *bfu_colors = NULL;
unsigned char *
get_bfu_background_color16_node(unsigned int node_number)
{
struct bfu_color_entry *entry = node_entries[node_number];
if (!entry->was_color16_set) {
set_term_color(&entry->c16, &entry->colors, 0, COLOR_MODE_16);
entry->was_color16_set = 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) {
set_term_color(&entry->c16, &entry->colors, 0, COLOR_MODE_16);
entry->was_color16_set = 1;
}
return &entry->c16.c.color[0];
}
unsigned char
get_bfu_background_color256_node(unsigned int node_number)
{
@ -64,6 +92,7 @@ get_bfu_foreground_color256_node(unsigned int node_number)
return TERM_COLOR_FOREGROUND_256(entry->c256.c.color);
}
unsigned char *
get_bfu_background_color_true_node(unsigned int node_number)
{

View File

@ -27,6 +27,8 @@ get_bfu_color(struct terminal *term, const char *stylename);
unsigned int get_bfu_color_node(struct terminal *term, const char *stylename);
unsigned char *get_bfu_background_color16_node(unsigned int node_number);
unsigned char *get_bfu_foreground_color16_node(unsigned int node_number);
unsigned char get_bfu_background_color256_node(unsigned int node_number);
unsigned char get_bfu_foreground_color256_node(unsigned int node_number);
unsigned char *get_bfu_background_color_true_node(unsigned int node_number);

View File

@ -443,6 +443,10 @@ static const struct screen_driver_opt *const screen_driver_opts[] = {
static INIT_LIST_OF(struct screen_driver, active_screen_drivers);
static unsigned char *get_foreground_color16_from_node(struct screen_char *ch);
static unsigned char *get_background_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.
*
@ -956,8 +960,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(ch->c.color)));
add_to_string(screen, terminfo_set_background(TERM_COLOR_BACKGROUND_16(ch->c.color)));
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))));
if (italic)
add_to_string(screen, terminfo_set_italics(italic));
@ -980,9 +984,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(ch->c.color);
unsigned char bgcolor = TERM_COLOR_BACKGROUND_16(get_background_color16_from_node(ch));
code[2] += TERM_COLOR_FOREGROUND_16(ch->c.color);
code[2] += TERM_COLOR_FOREGROUND_16(get_foreground_color16_from_node(ch));
if (!driver->opt.transparent || bgcolor != 0) {
code[5] += bgcolor;
@ -1089,6 +1093,34 @@ get_foreground_color_from_node(struct screen_char *ch)
return ch->c.color[0];
}
static unsigned char *
get_background_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 &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];
}
static inline void
add_background_color(struct string *str, const struct string *seq, struct screen_char *ch)
{