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

core: implement /theme apply with themable enforcement and auto-backup

Implement /theme apply <name> for themes currently in the in-memory
registry. The file-shadowing branch (read a .theme file from
${weechat_config_dir}/themes/ when no built-in matches) is added in
the next commit together with the parser.

Apply algorithm (theme_apply in core-theme.c):

- Look up the theme in the registry; abort with an error if unknown.
- If weechat.look.theme_backup is on and the target name does not
  begin with "backup-", write a full snapshot of every themable
  option to ${weechat_config_dir}/themes/backup-<timestamp>.theme
  via theme_make_backup; abort the apply if the backup cannot be
  written, so the user can always undo.
- Iterate the theme's overrides with theme_applying=1 so the
  per-option config_change_color skips its gui refresh; for each
  entry look up the option, refuse it if missing or non-themable
  (warning to core buffer), otherwise call config_file_option_set.
- Perform a single gui_color_init_weechat + gui_window_ask_refresh
  at the end.
- Persist the active label in weechat.look.theme and send signal
  "theme_applied" with the name as data.

Add the new option weechat.look.theme_backup (boolean, default on)
which controls the backup-or-abort behaviour described above.

Wire the new /theme apply subcommand into core-command.c with the
existing /theme registration; update help text accordingly.
This commit is contained in:
Sébastien Helleu
2026-05-26 17:21:12 +02:00
parent 4ea07c0880
commit f8822f4fbf
6 changed files with 522 additions and 1 deletions
+19 -1
View File
@@ -7231,6 +7231,13 @@ COMMAND_CALLBACK(theme)
return WEECHAT_RC_OK;
}
/* "/theme apply <name>": apply a theme */
if (string_strcmp (argv[1], "apply") == 0)
{
COMMAND_MIN_ARGS(3, "apply");
return theme_apply (argv[2]);
}
/* "/theme info <name>": show details about a theme */
if (string_strcmp (argv[1], "info") == 0)
{
@@ -9927,10 +9934,13 @@ command_init (void)
N_("manage color themes"),
/* TRANSLATORS: only text between angle brackets (eg: "<name>") may be translated */
N_("[list]"
" || apply <name>"
" || info <name>"),
CMD_ARGS_DESC(
N_("raw[list]: list registered themes (default action with no "
"argument); active theme is marked with \"->\""),
N_("raw[apply]: apply a theme (set every themable option to the "
"value from the theme)"),
N_("raw[info]: display details on a theme (name, description, "
"creation date, WeeChat version, number of option overrides)"),
N_("name: name of a theme"),
@@ -9939,8 +9949,16 @@ command_init (void)
"option overrides. Built-in themes are registered in memory "
"by core/plugins/scripts; user themes are read from files "
"in directory \"themes\" inside the WeeChat configuration "
"directory.")),
"directory."),
"",
N_("By default, /theme apply creates a backup of current "
"themable values in directory \"themes\" before applying "
"(file name: \"backup-<timestamp>.theme\"); the previous "
"state can be restored with: /theme apply "
"backup-<timestamp>. This is controlled by the option "
"weechat.look.theme_backup.")),
"list"
" || apply"
" || info",
&command_theme, NULL, NULL);
hook_command (