diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2023-04-21 22:28:53 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2023-04-26 21:07:26 +0200 |
commit | e8c48c0a1f379fe9abab1a9604a2325015d0b3e4 (patch) | |
tree | 1b01b4470c42ecad2434f6cc33f6a631bc890ea8 | |
parent | ff402fb6ec15a770cfa99ed92dedd96c007b9352 (diff) | |
download | weechat-e8c48c0a1f379fe9abab1a9604a2325015d0b3e4.zip |
core: always allow 256 colors, find nearest color if less colors are available in terminal (issue #1920)
-rw-r--r-- | src/core/wee-config.c | 4 | ||||
-rw-r--r-- | src/gui/curses/gui-curses-color.c | 31 | ||||
-rw-r--r-- | src/gui/gui-color.h | 1 |
3 files changed, 30 insertions, 6 deletions
diff --git a/src/core/wee-config.c b/src/core/wee-config.c index 87fdf749b..692dacfe6 100644 --- a/src/core/wee-config.c +++ b/src/core/wee-config.c @@ -3007,8 +3007,8 @@ config_weechat_init_options () N_("time format for each line displayed in buffers (see man " "strftime for date/time specifiers) (note: content is evaluated, " "so you can use colors with format \"${color:xxx}\", see /help " - "eval); for example time using grayscale (requires support of " - "256 colors): \"${color:252}%H${color:245}%M${color:240}%S\""), + "eval); for example time using grayscale: " + "\"${color:252}%H${color:243}%M${color:237}%S\""), NULL, 0, 0, "%H:%M:%S", NULL, 0, NULL, NULL, NULL, &config_change_buffer_time_format, NULL, NULL, diff --git a/src/gui/curses/gui-curses-color.c b/src/gui/curses/gui-curses-color.c index e01f1b483..3f96bca5f 100644 --- a/src/gui/curses/gui-curses-color.c +++ b/src/gui/curses/gui-curses-color.c @@ -449,11 +449,34 @@ gui_color_get_pair (int fg, int bg) if (gui_color_use_term_colors) return COLOR_WHITE; - /* if invalid color, use default fg/bg */ + /* if invalid color, use nearest color or default fg/bg */ if (fg >= gui_color_term_colors) - fg = -1; + { + /* find nearest color */ + if ((fg >= 0) && (fg <= 255)) + { + fg = gui_color_convert_rgb_to_term (gui_color_term256[fg], + gui_color_term_colors); + } + else + { + /* fallback to default foreground */ + fg = -1; + } + } if (bg >= gui_color_term_colors) - bg = -1; + { + if ((bg >= 0) && (bg <= 255)) + { + bg = gui_color_convert_rgb_to_term (gui_color_term256[bg], + gui_color_term_colors); + } + else + { + /* fallback to default background */ + bg = -1; + } + } /* compute index for gui_color_pairs with foreground and background */ index = ((bg + 1) * (gui_color_term_colors + 2)) + (fg + 1); @@ -1362,7 +1385,7 @@ gui_color_palette_build_aliases () WEECHAT_LIST_POS_END, NULL); } - for (i = 0; i <= gui_color_term_colors; i++) + for (i = 0; i < 256; i++) { color_palette = gui_color_palette_get (i); if (color_palette) diff --git a/src/gui/gui-color.h b/src/gui/gui-color.h index 50bab4a95..f9d40a37b 100644 --- a/src/gui/gui-color.h +++ b/src/gui/gui-color.h @@ -183,6 +183,7 @@ extern struct t_gui_color *gui_color[]; extern struct t_hashtable *gui_color_hash_palette_color; extern struct t_hashtable *gui_color_hash_palette_alias; extern struct t_weelist *gui_color_list_with_alias; +extern int gui_color_term256[]; /* color functions */ |