1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 09:13:14 +02:00

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 <weechat_config_dir>/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.
This commit is contained in:
Sébastien Helleu
2026-07-04 17:15:13 +02:00
parent a09bd50b92
commit 9aef5f452e
16 changed files with 221 additions and 19 deletions
+7 -1
View File
@@ -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 <mimi.vx@gmail.com>\n"
"Language-Team: Czech <weechat-dev@nongnu.org>\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)"
+7 -1
View File
@@ -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 <weechatter@arcor.de>\n"
"Language-Team: German <weechatter@arcor.de>\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)"
+7 -1
View File
@@ -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 <santiago@forero.xyz>\n"
"Language-Team: Spanish <weechat-dev@nongnu.org>\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 ""
+8 -2
View File
@@ -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 <flashcode@flashtux.org>\n"
"Language-Team: French <flashcode@flashtux.org>\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)"
+7 -1
View File
@@ -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 <voroskoi@frugalware.org>\n"
"Language-Team: Hungarian <weechat-dev@nongnu.org>\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 ""
+7 -1
View File
@@ -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 <exio4.com@gmail.com>\n"
"Language-Team: Italian <weechat-dev@nongnu.org>\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)"
+7 -1
View File
@@ -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 <i38w7i3@yahoo.co.jp>\n"
"Language-Team: Japanese <weechat-dev@nongnu.org>\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 ファイル、セクションデータ)"
+7 -1
View File
@@ -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 <soltys@soltys.info>\n"
"Language-Team: Polish <soltys@soltys.info>\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)"
+7 -1
View File
@@ -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 <vascomalmeida@sapo.pt>\n"
"Language-Team: Portuguese <weechat-dev@nongnu.org>\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)"
+7 -1
View File
@@ -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 <ericonr@disroot.org>\n"
"Language-Team: Portuguese (Brazil) <weechat-dev@nongnu.org>\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 ""
+7 -1
View File
@@ -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 <ixti@member.fsf.org>\n"
"Language-Team: Russian <weechat-dev@nongnu.org>\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 ""
+7 -1
View File
@@ -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ć <ivan.pesic@gmail.com>\n"
"Language-Team: Serbian <ivan.pesic@gmail.com>\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)"
+7 -1
View File
@@ -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 <emir_sari@icloud.com>\n"
"Language-Team: Turkish <emir_sari@icloud.com>\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)"
+7 -1
View File
@@ -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 <flashcode@flashtux.org>\n"
"Language-Team: weechat-dev <weechat-dev@nongnu.org>\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 ""
+4 -4
View File
@@ -10114,10 +10114,10 @@ command_init (void)
"state can be restored with: `/theme apply backup-<timestamp>`. "
"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",
+118
View File
@@ -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 <weechat_config_dir>/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);