1
0
mirror of https://github.com/weechat/weechat.git synced 2026-07-01 15:26:37 +02:00

core: implement /theme save and /theme delete

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 delete <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).

Bug fix while at it: the writer was previously calling
config_file_option_value_to_string (ptr_option, 0, 1, 0); the third
and fourth arguments are "use_colors" and "use_delimiters", so the
call inserted GUI color escape codes into the file output and skipped
quoting strings. Corrected to (ptr_option, 0, 0, 1) so plain text
with proper string quoting is written; the change also fixes the
content of files produced by theme_make_backup in the previous commit.
This commit is contained in:
Sébastien Helleu
2026-05-26 18:57:56 +02:00
parent 74faa91578
commit 144d79f331
4 changed files with 252 additions and 17 deletions
+29
View File
@@ -7333,6 +7333,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 delete <name>": remove a user theme file */
if (string_strcmp (argv[1], "delete") == 0)
{
COMMAND_MIN_ARGS(3, "delete");
return theme_delete (argv[2]);
}
/* "/theme info <name>": show details about a theme */
if (string_strcmp (argv[1], "info") == 0)
{
@@ -10057,6 +10074,8 @@ command_init (void)
/* TRANSLATORS: only text between angle brackets (eg: "<name>") may be translated */
N_("[list [-backups]]"
" || apply <name>"
" || save <name> [-full]"
" || delete <name>"
" || info <name>"),
CMD_ARGS_DESC(
N_("raw[list]: list registered themes and any *.theme files in "
@@ -10068,6 +10087,14 @@ 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[delete]: delete a user theme file (refuses to delete "
"built-in themes, which have no 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"),
@@ -10086,6 +10113,8 @@ command_init (void)
"weechat.look.theme_backup.")),
"list -backups"
" || apply"
" || save -full"
" || delete"
" || info",
&command_theme, NULL, NULL);
hook_command (