From 407ca7d114bb9d40ede57ffc1375a22a5c72e0fa Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 18 Mar 2022 16:24:48 +0100 Subject: [PATCH] [colors] Implemented displaying for 256 color mode --- src/bfu/style.c | 31 +++++++++++++++++++++++++++++++ src/bfu/style.h | 2 ++ src/terminal/screen.c | 15 +++++++++++++-- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/src/bfu/style.c b/src/bfu/style.c index 4ff497c7..c5208f90 100644 --- a/src/bfu/style.c +++ b/src/bfu/style.c @@ -26,12 +26,43 @@ struct bfu_color_entry { struct color_pair colors; unsigned int node_number; + + unsigned int was_color256_set:1; + + struct screen_char c256; + struct screen_char c24; }; struct bfu_color_entry *node_entries[1024]; static struct hash *bfu_colors = NULL; +unsigned char +get_bfu_background_color256_node(unsigned int node_number) +{ + struct bfu_color_entry *entry = node_entries[node_number]; + + if (!entry->was_color256_set) { + set_term_color(&entry->c256, &entry->colors, 0, COLOR_MODE_256); + entry->was_color256_set = 1; + } + + return TERM_COLOR_BACKGROUND_256(entry->c256.c.color); +} + +unsigned char +get_bfu_foreground_color256_node(unsigned int node_number) +{ + struct bfu_color_entry *entry = node_entries[node_number]; + + if (!entry->was_color256_set) { + set_term_color(&entry->c256, &entry->colors, 0, COLOR_MODE_256); + entry->was_color256_set = 1; + } + + return TERM_COLOR_FOREGROUND_256(entry->c256.c.color); +} + static struct bfu_color_entry * get_bfu_color_common(struct terminal *term, const char *stylename) { diff --git a/src/bfu/style.h b/src/bfu/style.h index cf475db6..4741ccbd 100644 --- a/src/bfu/style.h +++ b/src/bfu/style.h @@ -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_color256_node(unsigned int node_number); +unsigned char get_bfu_foreground_color256_node(unsigned int node_number); /** Cleanup after the BFU style cache * diff --git a/src/terminal/screen.c b/src/terminal/screen.c index 43a77e30..fda5b3f6 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -10,6 +10,7 @@ #include "elinks.h" +#include "bfu/style.h" #include "config/options.h" #include "intl/charsets.h" #include "main/module.h" @@ -1067,14 +1068,24 @@ add_char_color(struct string *screen, const struct string *seq, unsigned char co static unsigned char get_background_color_from_node(struct screen_char *ch) { - /* TODO */ + unsigned int node_number = ch->c.node_number; + + if (node_number < 1024) { + return get_bfu_background_color256_node(node_number); + } + return ch->c.color[1]; } static unsigned char get_foreground_color_from_node(struct screen_char *ch) { - /* TODO */ + unsigned int node_number = ch->c.node_number; + + if (node_number < 1024) { + return get_bfu_foreground_color256_node(node_number); + } + return ch->c.color[0]; }