diff --git a/src/bfu/style.c b/src/bfu/style.c index 0f3b270d8..712f7d137 100644 --- a/src/bfu/style.c +++ b/src/bfu/style.c @@ -29,11 +29,13 @@ struct bfu_color_entry { unsigned int was_mono:1; unsigned int was_color16:1; + unsigned int was_color88:1; unsigned int was_color256:1; unsigned int was_color24:1; struct screen_char mono; struct screen_char c16; + struct screen_char c88; struct screen_char c256; struct screen_char c24; }; @@ -81,6 +83,32 @@ get_bfu_foreground_color16_node(unsigned int node_number) return &entry->c16.c.color[0]; } +unsigned char +get_bfu_background_color88_node(unsigned int node_number) +{ + struct bfu_color_entry *entry = node_entries[node_number]; + + if (!entry->was_color88) { + set_term_color(&entry->c88, &entry->colors, 0, COLOR_MODE_88); + entry->was_color88 = 1; + } + + return TERM_COLOR_BACKGROUND_256(entry->c88.c.color); +} + +unsigned char +get_bfu_foreground_color88_node(unsigned int node_number) +{ + struct bfu_color_entry *entry = node_entries[node_number]; + + if (!entry->was_color88) { + set_term_color(&entry->c88, &entry->colors, 0, COLOR_MODE_88); + entry->was_color88 = 1; + } + + return TERM_COLOR_FOREGROUND_256(entry->c88.c.color); +} + unsigned char get_bfu_background_color256_node(unsigned int node_number) { @@ -107,7 +135,6 @@ 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) { diff --git a/src/bfu/style.h b/src/bfu/style.h index 3201fb202..f72080bf1 100644 --- a/src/bfu/style.h +++ b/src/bfu/style.h @@ -31,6 +31,8 @@ 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); +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); unsigned char get_bfu_foreground_color256_node(unsigned int node_number); unsigned char *get_bfu_background_color_true_node(unsigned int node_number); diff --git a/src/terminal/screen.c b/src/terminal/screen.c index cda028c55..748485765 100644 --- a/src/terminal/screen.c +++ b/src/terminal/screen.c @@ -1100,6 +1100,31 @@ get_foreground_color_from_node(struct screen_char *ch) return ch->c.color[0]; } +static unsigned char +get_background_color88_from_node(struct screen_char *ch) +{ + unsigned int node_number = ch->c.node_number; + + if (node_number < 1024) { + return get_bfu_background_color88_node(node_number); + } + + return ch->c.color[1]; +} + +static unsigned char +get_foreground_color88_from_node(struct screen_char *ch) +{ + unsigned int node_number = ch->c.node_number; + + if (node_number < 1024) { + return get_bfu_foreground_color88_node(node_number); + } + + return ch->c.color[0]; +} + + static struct screen_char * get_mono_from_node(struct screen_char *ch) { @@ -1162,6 +1187,27 @@ add_foreground_color(struct string *str, const struct string *seq, struct screen } } +static inline void +add_background_color88(struct string *str, const struct string *seq, struct screen_char *ch) +{ + if (ch->is_node) { + add_char_color(str, &(seq)[1], get_background_color88_from_node(ch)); + } else { + add_char_color(str, &(seq)[1], ch->c.color[1]); + } +} + +static inline void +add_foreground_color88(struct string *str, const struct string *seq, struct screen_char *ch) +{ + if (ch->is_node) { + add_char_color(str, (&seq)[0], get_foreground_color88_from_node(ch)); + } else { + add_char_color(str, &(seq)[0], ch->c.color[0]); + } +} + + #if 0 #define add_background_color(str, seq, chr) add_char_color(str, &(seq)[1], (chr)->c.color[1]) #define add_foreground_color(str, seq, chr) add_char_color(str, &(seq)[0], (chr)->c.color[0]) @@ -1253,9 +1299,17 @@ add_char256(struct string *screen, struct screen_driver *driver, } else #endif { - add_foreground_color(screen, driver->opt.color256_seqs, ch); + if (driver->opt.color_mode == COLOR_MODE_88) { + add_foreground_color88(screen, driver->opt.color256_seqs, ch); + } else { + add_foreground_color(screen, driver->opt.color256_seqs, ch); + } if (!driver->opt.transparent || ch->c.color[1] != 0) { - add_background_color(screen, driver->opt.color256_seqs, ch); + if (driver->opt.color_mode == COLOR_MODE_88) { + add_background_color88(screen, driver->opt.color256_seqs, ch); + } else { + add_background_color(screen, driver->opt.color256_seqs, ch); + } } if (ch->attr & SCREEN_ATTR_BOLD)