From aab01cfae11afd98c591ba14c9449ab97fe1205a Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Thu, 10 Mar 2022 18:27:37 +0100 Subject: [PATCH] [bfu] Added get_bfu_color_node --- src/bfu/style.c | 32 +++++++++++++++++++++++++++++--- src/bfu/style.h | 3 +++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/src/bfu/style.c b/src/bfu/style.c index a4172f19..4ff497c7 100644 --- a/src/bfu/style.c +++ b/src/bfu/style.c @@ -28,10 +28,12 @@ struct bfu_color_entry { unsigned int node_number; }; +struct bfu_color_entry *node_entries[1024]; + static struct hash *bfu_colors = NULL; -struct color_pair * -get_bfu_color(struct terminal *term, const char *stylename) +static struct bfu_color_entry * +get_bfu_color_common(struct terminal *term, const char *stylename) { static color_mode_T last_color_mode; struct bfu_color_entry *entry; @@ -93,16 +95,40 @@ get_bfu_color(struct terminal *term, const char *stylename) entry->background = &get_opt_color_tree(opt, "background", NULL); entry->node_number = ++node_number_counter; - + node_entries[node_number_counter] = entry; } /* Always update the color pair. */ entry->colors.background = *entry->background; entry->colors.foreground = *entry->foreground; + return entry; +} + +struct color_pair * +get_bfu_color(struct terminal *term, const char *stylename) +{ + struct bfu_color_entry *entry = get_bfu_color_common(term, stylename); + + if (!entry) { + return NULL; + } + return &entry->colors; } +unsigned int +get_bfu_color_node(struct terminal *term, const char *stylename) +{ + struct bfu_color_entry *entry = get_bfu_color_common(term, stylename); + + if (!entry) { + return 0; + } + + return entry->node_number; +} + void done_bfu_colors(void) { diff --git a/src/bfu/style.h b/src/bfu/style.h index 4af54258..cf475db6 100644 --- a/src/bfu/style.h +++ b/src/bfu/style.h @@ -25,6 +25,9 @@ struct terminal; struct color_pair * get_bfu_color(struct terminal *term, const char *stylename); +unsigned int get_bfu_color_node(struct terminal *term, const char *stylename); + + /** Cleanup after the BFU style cache * * Free all resources used by the BFU style cache.