1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-05 17:23:15 +02:00

core: implement /theme save and /theme del

Add two complementary subcommands:

  /theme save <name> [-full]: writes a user theme file at
    ${weechat_config_dir}/themes/<name>.theme containing the current
    themable options. By default only options whose value differs from
    their default (config_file_option_has_changed) are written, which
    keeps the file small and focused. Pass "-full" to write every
    themable option (matches the format used by automatic backups).

    Name validation: refuses any name matching a built-in theme (those
    are reserved for in-memory registrations) and any name starting
    with "backup-" (reserved for /theme apply backups). Both checks
    print an error and abort without writing.

  /theme del <name>: removes ${weechat_config_dir}/themes/<name>.theme
    via unlink. Refuses to delete a name registered as a built-in
    theme (a built-in has no file on disk to delete, even if the user
    has a shadowing file of the same name they cannot remove it this
    way; they can rename or delete it manually).

The full-snapshot writer used by /theme apply backups is refactored
into theme_write_file (name, description, diff_only). It is reused
by theme_make_backup (diff_only=0) and theme_save (diff_only inverted
from the user's -full flag).
This commit is contained in:
Sébastien Helleu
2026-07-04 17:02:12 +02:00
parent afaf7cf85b
commit a09bd50b92
18 changed files with 919 additions and 42 deletions
+28
View File
@@ -7339,6 +7339,23 @@ COMMAND_CALLBACK(theme)
return theme_apply (argv[2]);
}
/* "/theme save <name> [-full]": write a user theme file */
if (string_strcmp (argv[1], "save") == 0)
{
COMMAND_MIN_ARGS(3, "save");
return theme_save (argv[2],
((argc >= 4)
&& (string_strcmp (argv[3], "-full") == 0))
? 1 : 0);
}
/* "/theme del <name>": remove a user theme file */
if (string_strcmp (argv[1], "del") == 0)
{
COMMAND_MIN_ARGS(3, "del");
return theme_delete (argv[2]);
}
/* "/theme info <name>": show details about a theme */
if (string_strcmp (argv[1], "info") == 0)
{
@@ -10063,6 +10080,8 @@ command_init (void)
/* TRANSLATORS: only text between angle brackets (eg: "<name>") may be translated */
N_("[list [-backups]]"
" || apply <name>"
" || save <name> [-full]"
" || del <name>"
" || info <name>"),
CMD_ARGS_DESC(
N_("raw[list]: list registered themes and any *.theme files in "
@@ -10073,6 +10092,13 @@ command_init (void)
"value from the theme); if a file named <name>.theme "
"exists in directory \"themes\" it shadows any built-in "
"theme of the same name"),
N_("raw[save]: save current themable options to a file "
"<name>.theme in directory \"themes\"; by default only "
"options whose value differs from their default are "
"written, use \"-full\" to write every themable option; "
"the name must not match a built-in theme or start with "
"\"backup-\""),
N_("raw[del]: delete a user theme file"),
N_("raw[info]: display details on a theme (name, description, "
"creation date, WeeChat version, number of option overrides)"),
N_("name: name of a theme"),
@@ -10089,6 +10115,8 @@ command_init (void)
"This is controlled by the option weechat.look.theme_backup.")),
"list -backups"
" || apply"
" || save -full"
" || del"
" || info",
&command_theme, NULL, NULL);
hook_command (