From 266d05ac666b3c5fd9ae8ef4be386a10bb0114ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 4 Jul 2026 17:15:13 +0200 Subject: [PATCH] core: add theme name completion Add two completion items hooked alongside "layouts_names": - "theme_themes_all": all theme names (built-ins from the registry plus every *.theme file in /themes/, including backup-*.theme). Used by tab-complete on /theme apply and /theme info. - "theme_themes_user": user theme files only (excludes built-ins and backup-*.theme). Used by tab-complete on /theme save and /theme del, so users cannot accidentally try to overwrite a built-in name or save a name colliding with the reserved backup prefix. Both callbacks share a small dir_exec_on_files-based helper to filter the themes directory. The /theme command's completion template in core-command.c is updated to reference these new items. --- po/cs.po | 8 ++- po/de.po | 8 ++- po/es.po | 8 ++- po/fr.po | 10 +++- po/hu.po | 8 ++- po/it.po | 8 ++- po/ja.po | 8 ++- po/pl.po | 8 ++- po/pt.po | 8 ++- po/pt_BR.po | 8 ++- po/ru.po | 8 ++- po/sr.po | 8 ++- po/tr.po | 8 ++- po/weechat.pot | 8 ++- src/core/core-command.c | 8 +-- src/core/core-completion.c | 118 +++++++++++++++++++++++++++++++++++++ 16 files changed, 221 insertions(+), 19 deletions(-) diff --git a/po/cs.po b/po/cs.po index 46af22de8..9f2f294b5 100644 --- a/po/cs.po +++ b/po/cs.po @@ -23,7 +23,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-05-30 14:01+0200\n" "Last-Translator: Ondřej Súkup \n" "Language-Team: Czech \n" @@ -4354,6 +4354,12 @@ msgstr "" msgid "names of layouts" msgstr "jména rozvržení" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "jména chráněných dat (soubor sec.conf, sekce data)" diff --git a/po/de.po b/po/de.po index ded6da285..7ed772d07 100644 --- a/po/de.po +++ b/po/de.po @@ -26,7 +26,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:28+0200\n" "Last-Translator: Nils Görs \n" "Language-Team: German \n" @@ -4823,6 +4823,12 @@ msgstr "" msgid "names of layouts" msgstr "Namen der Layouts" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "Namen der geschützten Daten (Datei sec.conf, section data)" diff --git a/po/es.po b/po/es.po index ce51e0fbb..de4689918 100644 --- a/po/es.po +++ b/po/es.po @@ -24,7 +24,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:46+0200\n" "Last-Translator: Santiago Forero \n" "Language-Team: Spanish \n" @@ -4444,6 +4444,12 @@ msgstr "áreas (\"chat\" o nombre de barra) para movimiento libre del cursor" msgid "names of layouts" msgstr "nombres de temas" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "" diff --git a/po/fr.po b/po/fr.po index 59e4707f5..3ff867d5e 100644 --- a/po/fr.po +++ b/po/fr.po @@ -23,8 +23,8 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" -"PO-Revision-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" +"PO-Revision-Date: 2026-07-04 17:15+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: French \n" "Language: fr\n" @@ -4744,6 +4744,12 @@ msgstr "zones (\"chat\" ou un nom de barre) pour le mouvement libre du curseur" msgid "names of layouts" msgstr "noms des dispositions" +msgid "names of themes (built-ins + user files + backups)" +msgstr "noms des thèmes (intégrés + fichiers utilisateur + sauvegardes)" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "noms des thèmes utilisateur (sans les intégrés et sauvegardes)" + msgid "names of secured data (file sec.conf, section data)" msgstr "noms de données sécurisées (fichier sec.conf, section data)" diff --git a/po/hu.po b/po/hu.po index 39fe9d94c..85cab0b55 100644 --- a/po/hu.po +++ b/po/hu.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-03-08 08:59+0100\n" "Last-Translator: Andras Voroskoi \n" "Language-Team: Hungarian \n" @@ -4166,6 +4166,12 @@ msgstr "" msgid "names of layouts" msgstr "Aliaszok listája:\n" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "" diff --git a/po/it.po b/po/it.po index bc2c20d52..a380d0e89 100644 --- a/po/it.po +++ b/po/it.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-05-30 14:02+0200\n" "Last-Translator: Esteban I. Ruiz Moreno \n" "Language-Team: Italian \n" @@ -4379,6 +4379,12 @@ msgstr "aree (\"chat\" o nome barra) per il movimento libero del cursore" msgid "names of layouts" msgstr "nomi dei layout" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + #, fuzzy msgid "names of secured data (file sec.conf, section data)" msgstr "nome dei dati sensibili (file sec.conf, sezione data)" diff --git a/po/ja.po b/po/ja.po index d509c5f9e..699b77902 100644 --- a/po/ja.po +++ b/po/ja.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-05-30 14:02+0200\n" "Last-Translator: AYANOKOUZI, Ryuunosuke \n" "Language-Team: Japanese \n" @@ -4481,6 +4481,12 @@ msgstr "カーソルを自由に動かせるエリア (\"chat\" またはバー msgid "names of layouts" msgstr "レイアウトの名前" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "保護データの名前 (sec.conf ファイル、セクションデータ)" diff --git a/po/pl.po b/po/pl.po index 93aa99c74..09ff4916e 100644 --- a/po/pl.po +++ b/po/pl.po @@ -23,7 +23,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:55+0200\n" "Last-Translator: Krzysztof Korościk \n" "Language-Team: Polish \n" @@ -4614,6 +4614,12 @@ msgstr "" msgid "names of layouts" msgstr "nazwy układów" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "nazwy zabezpieczonych danych (plik sec.conf, sekcja data)" diff --git a/po/pt.po b/po/pt.po index 1308129bf..9d4131089 100644 --- a/po/pt.po +++ b/po/pt.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:48+0200\n" "Last-Translator: Vasco Almeida \n" "Language-Team: Portuguese \n" @@ -4500,6 +4500,12 @@ msgstr "áreas (\"chat\" ou nome da barra) onde mover o cursor livremente" msgid "names of layouts" msgstr "nomes das disposições" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "nomes dos ficheiros protegidos (ficheiro sec.conf, secção de dados)" diff --git a/po/pt_BR.po b/po/pt_BR.po index f97100d63..8ad84a026 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -46,7 +46,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:49+0200\n" "Last-Translator: Érico Nogueira \n" "Language-Team: Portuguese (Brazil) \n" @@ -4404,6 +4404,12 @@ msgstr "" msgid "names of layouts" msgstr "nomes das disposições" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "" diff --git a/po/ru.po b/po/ru.po index c9d44fb62..c510bbce5 100644 --- a/po/ru.po +++ b/po/ru.po @@ -23,7 +23,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-03-08 08:59+0100\n" "Last-Translator: Aleksey V Zapparov AKA ixti \n" "Language-Team: Russian \n" @@ -4190,6 +4190,12 @@ msgstr "" msgid "names of layouts" msgstr "Список сокращений:\n" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "" diff --git a/po/sr.po b/po/sr.po index 248a80303..4be8b67ad 100644 --- a/po/sr.po +++ b/po/sr.po @@ -22,7 +22,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:52+0200\n" "Last-Translator: Ivan Pešić \n" "Language-Team: Serbian \n" @@ -4589,6 +4589,12 @@ msgstr "површине („chat” или име траке) за слобод msgid "names of layouts" msgstr "имена распореда" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "имена обезбеђених података (фајл sec.conf, одељак data)" diff --git a/po/tr.po b/po/tr.po index 9f1a9d7f6..fcadca26c 100644 --- a/po/tr.po +++ b/po/tr.po @@ -23,7 +23,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2026-06-28 08:53+0200\n" "Last-Translator: Emir SARI \n" "Language-Team: Turkish \n" @@ -4415,6 +4415,12 @@ msgstr "serbest imleç hareketi için alanlar (\"chat\" veya çubuk adı)" msgid "names of layouts" msgstr "dizilim adları" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "güvenli veri adları (sec.conf dosyası, bölüm verisi)" diff --git a/po/weechat.pot b/po/weechat.pot index 6326c414d..beffe649b 100644 --- a/po/weechat.pot +++ b/po/weechat.pot @@ -23,7 +23,7 @@ msgid "" msgstr "" "Project-Id-Version: WeeChat\n" "Report-Msgid-Bugs-To: flashcode@flashtux.org\n" -"POT-Creation-Date: 2026-07-04 17:00+0200\n" +"POT-Creation-Date: 2026-07-04 17:14+0200\n" "PO-Revision-Date: 2014-08-16 10:27+0200\n" "Last-Translator: Sébastien Helleu \n" "Language-Team: weechat-dev \n" @@ -3910,6 +3910,12 @@ msgstr "" msgid "names of layouts" msgstr "" +msgid "names of themes (built-ins + user files + backups)" +msgstr "" + +msgid "names of user theme files (without built-ins and backups)" +msgstr "" + msgid "names of secured data (file sec.conf, section data)" msgstr "" diff --git a/src/core/core-command.c b/src/core/core-command.c index 99c13ad6d..6b0812c36 100644 --- a/src/core/core-command.c +++ b/src/core/core-command.c @@ -10114,10 +10114,10 @@ command_init (void) "state can be restored with: `/theme apply backup-`. " "This is controlled by the option weechat.look.theme_backup.")), "list -backups" - " || apply" - " || save -full" - " || del" - " || info", + " || apply %(theme_themes_all)" + " || save %(theme_themes_user) -full" + " || del %(theme_themes_user)" + " || info %(theme_themes_all)", &command_theme, NULL, NULL); hook_command ( NULL, "toggle", diff --git a/src/core/core-completion.c b/src/core/core-completion.c index a925f7063..f2f293b56 100644 --- a/src/core/core-completion.c +++ b/src/core/core-completion.c @@ -46,6 +46,7 @@ #include "core-proxy.h" #include "core-secure.h" #include "core-string.h" +#include "core-theme.h" #include "../gui/gui-completion.h" #include "../gui/gui-bar.h" #include "../gui/gui-bar-item.h" @@ -63,6 +64,12 @@ extern char **environ; +struct t_completion_theme_dir +{ + struct t_gui_completion *completion; + int show_backups; +}; + /* * Add a word with quotes around to completion list. @@ -1974,6 +1981,111 @@ completion_list_add_layouts_names_cb (const void *pointer, void *data, return WEECHAT_RC_OK; } +/* + * Add filename (without ".theme" suffix) to completion list if it ends + * with ".theme"; skips "backup-*.theme" entries unless data is non-NULL. + * + * Callback for dir_exec_on_files; "data" carries a pair of pointers: + * data[0] = struct t_gui_completion *completion (target) + * data[1] = int *show_backups + */ + +void +completion_theme_add_file_cb (void *data, const char *filename) +{ + struct t_completion_theme_dir *ctx; + const char *base; + char *name; + size_t len; + + ctx = (struct t_completion_theme_dir *)data; + base = strrchr (filename, '/'); + base = (base) ? base + 1 : filename; + len = strlen (base); + if ((len < 7) || (strcmp (base + len - 6, ".theme") != 0)) + return; + if (!ctx->show_backups && (strncmp (base, "backup-", 7) == 0)) + return; + name = string_strndup (base, len - 6); + if (!name) + return; + gui_completion_list_add (ctx->completion, name, 0, WEECHAT_LIST_POS_SORT); + free (name); +} + +/* + * Add theme names to completion list: in-memory built-ins plus any + * "*.theme" files in /themes/ (including backups). + */ + +int +completion_list_add_theme_themes_all_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_theme *ptr_theme; + struct t_completion_theme_dir ctx; + char *dir; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) completion_item; + (void) buffer; + + for (ptr_theme = themes; ptr_theme; ptr_theme = ptr_theme->next_theme) + { + gui_completion_list_add (completion, ptr_theme->name, + 0, WEECHAT_LIST_POS_SORT); + } + + dir = NULL; + string_asprintf (&dir, "%s/themes", weechat_config_dir); + if (dir) + { + ctx.completion = completion; + ctx.show_backups = 1; + dir_exec_on_files (dir, 0, 0, &completion_theme_add_file_cb, &ctx); + free (dir); + } + + return WEECHAT_RC_OK; +} + +/* + * Add user theme file names (excluding built-ins and backups) to the + * completion list; suitable for /theme save and /theme del. + */ + +int +completion_list_add_theme_themes_user_cb (const void *pointer, void *data, + const char *completion_item, + struct t_gui_buffer *buffer, + struct t_gui_completion *completion) +{ + struct t_completion_theme_dir ctx; + char *dir; + + /* make C compiler happy */ + (void) pointer; + (void) data; + (void) completion_item; + (void) buffer; + + dir = NULL; + string_asprintf (&dir, "%s/themes", weechat_config_dir); + if (dir) + { + ctx.completion = completion; + ctx.show_backups = 0; + dir_exec_on_files (dir, 0, 0, &completion_theme_add_file_cb, &ctx); + free (dir); + } + + return WEECHAT_RC_OK; +} + /* * Add a secured data to completion list. */ @@ -2365,6 +2477,12 @@ completion_init (void) hook_completion (NULL, "layouts_names", N_("names of layouts"), &completion_list_add_layouts_names_cb, NULL, NULL); + hook_completion (NULL, "theme_themes_all", + N_("names of themes (built-ins + user files + backups)"), + &completion_list_add_theme_themes_all_cb, NULL, NULL); + hook_completion (NULL, "theme_themes_user", + N_("names of user theme files (without built-ins and backups)"), + &completion_list_add_theme_themes_user_cb, NULL, NULL); hook_completion (NULL, "secured_data", N_("names of secured data (file sec.conf, section data)"), &completion_list_add_secured_data_cb, NULL, NULL);