From 9b1b2f4590ec0ad107a4f5e7931a23003efe0a3b Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Fri, 18 Mar 2022 16:33:52 +0100 Subject: [PATCH] [colors] displaying node_numbers colors for 24bit color --- src/bfu/style.c | 28 ++++++++++++++++++++++++++++ src/bfu/style.h | 2 ++ src/terminal/screen.c | 14 ++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/bfu/style.c b/src/bfu/style.c index c5208f90..9d6c7e3f 100644 --- a/src/bfu/style.c +++ b/src/bfu/style.c @@ -28,6 +28,7 @@ struct bfu_color_entry { unsigned int node_number; unsigned int was_color256_set:1; + unsigned int was_color24_set:1; struct screen_char c256; struct screen_char c24; @@ -63,6 +64,33 @@ 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) +{ + struct bfu_color_entry *entry = node_entries[node_number]; + + if (!entry->was_color24_set) { + set_term_color(&entry->c24, &entry->colors, 0, COLOR_MODE_TRUE_COLOR); + entry->was_color24_set = 1; + } + + return &entry->c24.c.color[3]; +} + +unsigned char * +get_bfu_foreground_color_true_node(unsigned int node_number) +{ + struct bfu_color_entry *entry = node_entries[node_number]; + + if (!entry->was_color24_set) { + set_term_color(&entry->c24, &entry->colors, 0, COLOR_MODE_TRUE_COLOR); + entry->was_color24_set = 1; + } + + return &entry->c24.c.color[0]; +} + + 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 4741ccbd..5ee5d315 100644 --- a/src/bfu/style.h +++ b/src/bfu/style.h @@ -29,6 +29,8 @@ 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); +unsigned char *get_bfu_background_color_true_node(unsigned int node_number); +unsigned char *get_bfu_foreground_color_true_node(unsigned int node_number); /** Cleanup after the BFU style cache * diff --git a/src/terminal/screen.c b/src/terminal/screen.c index fda5b3f6..04a5fe86 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -1233,14 +1233,24 @@ static const struct string color_true_seqs[] = { static unsigned char * get_true_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_color_true_node(node_number); + } + return &(ch)->c.color[3]; } static unsigned char * get_true_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_color_true_node(node_number); + } + return &(ch)->c.color[0]; }