From 4ea5ce6dd70fa8dfbc9563c7aede84d99bab7019 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Wed, 27 May 2026 17:57:04 +0200 Subject: [PATCH] buflist: contribute "light" theme overrides Add buflist-theme.{c,h} with the buflist plugin contribution to the built-in "light" theme: 5 overrides on buflist.format.* options (buffer_current, hotlist_low, hotlist_message, lag, number) tuned for a light-background terminal. Each target is a "string|themable" option holding an evaluated format expression with embedded ${color:...} references. Follows the same pattern as the irc and fset contributions: a NULL-terminated 2D string table consumed by a tiny local register helper that builds a hashtable and calls weechat_theme_register; buflist_theme_init() is called once from weechat_plugin_init after buflist_config_init / buflist_config_read. Default option values are NOT changed. --- src/plugins/buflist/CMakeLists.txt | 1 + src/plugins/buflist/buflist-theme.c | 93 +++++++++++++++++++++++++++++ src/plugins/buflist/buflist-theme.h | 27 +++++++++ src/plugins/buflist/buflist.c | 3 + 4 files changed, 124 insertions(+) create mode 100644 src/plugins/buflist/buflist-theme.c create mode 100644 src/plugins/buflist/buflist-theme.h diff --git a/src/plugins/buflist/CMakeLists.txt b/src/plugins/buflist/CMakeLists.txt index bfac3fcdb..b70926eed 100644 --- a/src/plugins/buflist/CMakeLists.txt +++ b/src/plugins/buflist/CMakeLists.txt @@ -27,6 +27,7 @@ add_library(buflist MODULE buflist-config.c buflist-config.h buflist-info.c buflist-info.h buflist-mouse.c buflist-mouse.h + buflist-theme.c buflist-theme.h ) set_target_properties(buflist PROPERTIES PREFIX "") diff --git a/src/plugins/buflist/buflist-theme.c b/src/plugins/buflist/buflist-theme.c new file mode 100644 index 000000000..2da593d60 --- /dev/null +++ b/src/plugins/buflist/buflist-theme.c @@ -0,0 +1,93 @@ +/* + * SPDX-FileCopyrightText: 2026 Sébastien Helleu + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see . + */ + +/* buflist contribution to built-in themes. */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include + +#include "../weechat-plugin.h" +#include "buflist.h" +#include "buflist-theme.h" + + +/* + * buflist contribution to the "light" theme: format strings tuned for + * a light-background terminal. Each row is { option_full_name, value }; + * the table is NULL-terminated. + */ + +const char *buflist_theme_light[][2] = +{ + { "buflist.format.buffer_current", + "${color:,117}${format_buffer}" }, + { "buflist.format.hotlist_low", + "${color:default}" }, + { "buflist.format.hotlist_message", + "${color:94}" }, + { "buflist.format.lag", + " ${color:green}[${color:94}${lag}${color:green}]" }, + { "buflist.format.number", + "${color:28}${number}${if:${number_displayed}?.: }" }, + { NULL, NULL }, +}; + +/* + * Registers buflist's contribution to one theme from a NULL-terminated + * table of {option, value} rows. + */ + +void +buflist_theme_register (const char *name, const char *entries[][2]) +{ + struct t_hashtable *overrides; + int i; + + if (!name || !entries) + return; + + overrides = weechat_hashtable_new (32, + WEECHAT_HASHTABLE_STRING, + WEECHAT_HASHTABLE_STRING, + NULL, NULL); + if (!overrides) + return; + + for (i = 0; entries[i][0]; i++) + weechat_hashtable_set (overrides, entries[i][0], entries[i][1]); + + weechat_theme_register (name, overrides); + + weechat_hashtable_free (overrides); +} + +/* + * Registers all built-in theme contributions from buflist. + */ + +void +buflist_theme_init (void) +{ + buflist_theme_register ("light", buflist_theme_light); +} diff --git a/src/plugins/buflist/buflist-theme.h b/src/plugins/buflist/buflist-theme.h new file mode 100644 index 000000000..dc5a21cd5 --- /dev/null +++ b/src/plugins/buflist/buflist-theme.h @@ -0,0 +1,27 @@ +/* + * SPDX-FileCopyrightText: 2026 Sébastien Helleu + * + * SPDX-License-Identifier: GPL-3.0-or-later + * + * This file is part of WeeChat, the extensible chat client. + * + * WeeChat is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * WeeChat is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with WeeChat. If not, see . + */ + +#ifndef WEECHAT_PLUGIN_BUFLIST_THEME_H +#define WEECHAT_PLUGIN_BUFLIST_THEME_H + +extern void buflist_theme_init (void); + +#endif /* WEECHAT_PLUGIN_BUFLIST_THEME_H */ diff --git a/src/plugins/buflist/buflist.c b/src/plugins/buflist/buflist.c index 2b3b25eb1..49b1a9c3d 100644 --- a/src/plugins/buflist/buflist.c +++ b/src/plugins/buflist/buflist.c @@ -34,6 +34,7 @@ #include "buflist-config.h" #include "buflist-info.h" #include "buflist-mouse.h" +#include "buflist-theme.h" WEECHAT_PLUGIN_NAME(BUFLIST_PLUGIN_NAME); @@ -455,6 +456,8 @@ weechat_plugin_init (struct t_weechat_plugin *plugin, int argc, char *argv[]) buflist_config_read (); + buflist_theme_init (); + if (!buflist_bar_item_init ()) return WEECHAT_RC_ERROR;