From 7996637db550f73545f02ea5771823179e73694b Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Mon, 1 Dec 2025 15:22:01 +0100 Subject: [PATCH] Make fish immediately show color changes again Historically, fish tried to re-exec the prompt and repaint immediately when a color variable changed. Commit f5c6306bde9 (Do not repaint prompt on universal variable events, but add event handler for fish_color_cwd, 2006-05-11) restricted this to only variables used in the prompt like "fish_color_cwd". Commit 0c9a1a56c22 (Lots of work on web config Change to make fish immediately show color changes, 2012-03-25) added repainting back for all colors (except for pager colors). Commit ff62d172e5c (Stop repainting in C++, 2020-12-11) undid that. Finally, 69c71052efa (Remove __fish_repaint, 2021-03-04) removed the --on-variable repaint handlers added by the first commit. So if color changes via either 1. webconfig 2. an event handler reacting to the terminal switching between light/dark mode 3. a binding etc. then we fail to redraw. Affects both colors used in prompts and those not used in prompts. Fix that by adding back the hack from the second commit. This is particularly important for case 2, to be added by a following commit. In future we can remove this hack by making "--on-variable" take a wildcard. --- src/env_dispatch.rs | 8 ++++++++ .../tmux-autosuggestion-multiline-resizing-prompt.fish | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/env_dispatch.rs b/src/env_dispatch.rs index f8915433d..080e254de 100644 --- a/src/env_dispatch.rs +++ b/src/env_dispatch.rs @@ -16,6 +16,7 @@ use crate::terminal::use_terminfo; use crate::tty_handoff::xtversion; use crate::wchar::prelude::*; +use crate::wcstringutil::string_prefixes_string; use crate::wutil::fish_wcstoi; use crate::{function, terminal}; use std::collections::HashMap; @@ -214,6 +215,13 @@ pub fn env_dispatch_var_change(key: &wstr, vars: &EnvStack) { if let Some(dispatch_table) = Lazy::get(&VAR_DISPATCH_TABLE) { dispatch_table.dispatch(key, vars); } + + if string_prefixes_string(L!("fish_color_"), key) + // TODO Don't re-exec prompt when only pager color changed. + || string_prefixes_string(L!("fish_pager_color_"), key) + { + reader_schedule_prompt_repaint(); + } } fn handle_fish_term_change(vars: &EnvStack) { diff --git a/tests/checks/tmux-autosuggestion-multiline-resizing-prompt.fish b/tests/checks/tmux-autosuggestion-multiline-resizing-prompt.fish index 3872c2275..abdc650b3 100644 --- a/tests/checks/tmux-autosuggestion-multiline-resizing-prompt.fish +++ b/tests/checks/tmux-autosuggestion-multiline-resizing-prompt.fish @@ -25,13 +25,13 @@ tmux-sleep isolated-tmux send-keys i tmux-sleep isolated-tmux capture-pane -p | string replace -r ^ ^ -# CHECK: ^1.1 # CHECK: ^2.1 -# CHECK: ^2.2 if true +# CHECK: ^2.2 +# CHECK: ^3.1 +# CHECK: ^3.2 +# CHECK: ^3.3 if true # CHECK: ^ echo hello1 # CHECK: ^ echo hello2 # CHECK: ^ echo hello3 # CHECK: ^ echo hello4 -# CHECK: ^ echo hello5 -# CHECK: ^ echo hello6 -# CHECK: ^ echo hello7… +# CHECK: ^ echo hello5…