Make fish immediately show color changes again

Historically, fish tried to re-exec the prompt and repaint immediately
when a color variable changed.

Commit f5c6306bde (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 0c9a1a56c2 (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 ff62d172e5 (Stop repainting in C++, 2020-12-11) undid that.

Finally, 69c71052ef (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.
This commit is contained in:
Johannes Altmanninger
2025-12-01 15:22:01 +01:00
parent d67cdf5f6f
commit 7996637db5
2 changed files with 13 additions and 5 deletions

View File

@@ -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) {

View File

@@ -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