Stop --background=somecolor from implicitly setting the bold modifier

As reported in https://github.com/fish-shell/fish-shell/issues/11325, we have logic that
implicitly activates bold mode.

Even worse: the test case from https://github.com/fish-shell/fish-shell/issues/11426 shows that
we're not even consistent about that.

To reproduce, use

    set -g fish_pager_color_background --background=fff
    set -g fish_pager_color_prefix --underline --bold 000
    set -g fish_pager_color_completion
    set -g fish_pager_color_description
    complete : -s a -l all -d asdf

and type ": -" <TAB>

The second prefix is underlined but not bold,
because the implicit bold mode has a subtle bug.

Now if we were to fix this, using

    diff --git a/src/terminal.rs b/src/terminal.rs
    index b86a7d85fe..7791d34936 100644
    --- a/src/terminal.rs
    +++ b/src/terminal.rs
    @@ -589,7 +589,7 @@
             // Lastly, we set bold, underline, italics, dim, and reverse modes correctly.
             if style.is_bold()
                 && !self.last.style.is_bold()
    -            && !bg_set
    +            && !(bg_set && !last_bg_set)
                 && self.write_command(EnterBoldMode)
             {
                 self.last.style.bold = true;

that would make the description bold as well, which would probably cause chaos.
Either way, it seems wrong to expand this hack.

Let's remove it.

For better or worse, we can't safely update the default theme yet on
an existing user's machine, because we have set universal variables.
This means that fish_color_search_match and fish_pager_color_progress on
existing installations are no longer bold. That's probably acceptable.
The former was hard to read for the longest time, until 9af6a64fd2 (Fix
bad contrast in search match highlighting, 2024-04-15). The progress info
is probably not a big deal.

Attentive users may run "fish_config theme choose 'fish default'". Perhaps
we should tell them on upgrade?

Closes #11325
This commit is contained in:
Johannes Altmanninger
2025-04-26 08:18:39 +02:00
parent 742016f455
commit c8f2471357
26 changed files with 79 additions and 103 deletions

View File

@@ -34,6 +34,8 @@ Deprecations and removed features
To make the nearest-match logic use the 16 color palette instead, use ``set fish_term256 0``.
- Inside macOS Terminal.app, fish makes an attempt to still use the palette colors.
If that doesn't work, use ``set fish_term24bit 0``.
- ``set_color --background=COLOR`` no longer implicitly activates bold mode.
To mitigate this change on existing installations that use a default theme, update your theme with ``fish_config theme choose`` or ``fish_config theme save``.
Scripting improvements
----------------------

View File

@@ -10,8 +10,8 @@ fish_color_end ba8baf
fish_color_error ab4642
fish_color_param d8d8d8
fish_color_comment f7ca88
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 7cafc2
fish_color_escape 86c1b9
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option d8d8d8
fish_color_keyword a1b56c

View File

@@ -10,8 +10,8 @@ fish_color_end ba8baf
fish_color_error ab4642
fish_color_param 383838
fish_color_comment f7ca88
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 7cafc2
fish_color_cwd_root red
@@ -25,7 +25,7 @@ fish_color_host normal
fish_pager_color_description B3A06D yellow
fish_pager_color_completion normal
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 383838
fish_color_keyword a1b56c

View File

@@ -10,8 +10,8 @@ fish_color_end cc99cc
fish_color_error f2777a
fish_color_param d3d0c8
fish_color_comment ffcc66
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 6699cc
fish_color_escape 66cccc
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option d3d0c8
fish_color_keyword 99cc99

View File

@@ -9,8 +9,8 @@ fish_color_end FFB273
fish_color_error FF7400
fish_color_param 33CCCC
fish_color_comment FF9640
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 33CCCC
fish_color_keyword 009999

View File

@@ -21,8 +21,8 @@ fish_color_end ffb86c
fish_color_error ff5555
fish_color_param bd93f9
fish_color_comment 6272a4
fish_color_selection --background=44475a
fish_color_search_match --background=44475a
fish_color_selection --background=44475a --bold
fish_color_search_match --background=44475a --bold
fish_color_history_current --bold
fish_color_operator 50fa7b
fish_color_escape ff79c6

View File

@@ -9,8 +9,8 @@ fish_color_end 8D003B
fish_color_error EC3B86
fish_color_param 225E79
fish_color_comment FFE100
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_prefix normal --bold --underline
fish_pager_color_description B3A06D yellow
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 225E79
fish_color_keyword 0772A1

View File

@@ -9,8 +9,8 @@ fish_color_end 969696
fish_color_error FFA779
fish_color_param A0A0F0
fish_color_comment B0B0B0
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option A0A0F0
fish_color_keyword F4F4F4

View File

@@ -9,8 +9,8 @@ fish_color_end FF4C00
fish_color_error FFDD73
fish_color_param FFC000
fish_color_comment A63100
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option FFC000
fish_color_keyword FF9400

View File

@@ -9,8 +9,8 @@ fish_color_end 767676
fish_color_error b2b2b2
fish_color_param 303030
fish_color_comment 4e4e4e
fish_color_search_match white --background=brblack
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack --bold
fish_color_selection white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -23,7 +23,7 @@ fish_color_host normal
fish_pager_color_prefix normal --bold --underline
fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_description B3A06D yellow
fish_pager_color_selected_background --background=brblack
fish_color_option 303030

View File

@@ -9,8 +9,8 @@ fish_color_end 949494
fish_color_error 585858
fish_color_param d7d7d7
fish_color_comment bcbcbc
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option d7d7d7
fish_color_keyword ffffff

View File

@@ -14,7 +14,7 @@ fish_color_param d8dee9
fish_color_valid_path --underline
fish_color_option 8fbcbb
fish_color_comment 4c566a --italics
fish_color_selection d8dee9 --bold --background=434c5e
fish_color_selection d8dee9 --background=434c5e --bold
fish_color_operator 81a1c1
fish_color_escape ebcb8b
fish_color_autosuggestion 4c566a
@@ -25,10 +25,10 @@ fish_color_host a3be8c
fish_color_host_remote ebcb8b
fish_color_status bf616a
fish_color_cancel --reverse
fish_color_search_match --bold --background=434c5e
fish_color_search_match --background=434c5e --bold
fish_color_history_current e5e9f0 --bold
fish_pager_color_progress 3b4252 --background=d08770
fish_pager_color_progress 3b4252 --background=d08770 --bold
fish_pager_color_completion e5e9f0
fish_pager_color_prefix normal --bold --underline
fish_pager_color_description ebcb8b --italics

View File

@@ -9,8 +9,8 @@ fish_color_end FF7B7B
fish_color_error A40000
fish_color_param 30BE30
fish_color_comment 30BE30
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 30BE30
fish_color_keyword 00FF00

View File

@@ -9,8 +9,8 @@ fish_color_end 8EEB00
fish_color_error 60B9CE
fish_color_param 04819E
fish_color_comment 5C9900
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_completion normal
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 04819E
fish_color_keyword 00BF32

View File

@@ -9,8 +9,8 @@ fish_color_end 02BDBD
fish_color_error 9177E5
fish_color_param 4319CC
fish_color_comment 007B7B
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -24,7 +24,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 4319CC
fish_color_keyword 164CC9

View File

@@ -10,8 +10,8 @@ fish_color_end 268bd2
fish_color_error dc322f
fish_color_param 839496
fish_color_comment 586e75
fish_color_selection white --bold --background=brblack
fish_color_search_match bryellow --background=black
fish_color_selection white --background=brblack --bold
fish_color_search_match bryellow --background=black --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion B3A06D
fish_pager_color_description B3A06D
fish_pager_color_prefix cyan --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 839496
fish_color_keyword 93a1a1

View File

@@ -10,8 +10,8 @@ fish_color_end 268bd2
fish_color_error dc322f
fish_color_param 657b83
fish_color_comment 93a1a1
fish_color_selection white --bold --background=brblack
fish_color_search_match bryellow --background=white
fish_color_selection white --background=brblack --bold
fish_color_search_match bryellow --background=white --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion green
fish_pager_color_description B3A06D
fish_pager_color_prefix cyan --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=white
fish_color_option 657b83
fish_color_keyword 586e75

View File

@@ -10,8 +10,8 @@ fish_color_end c397d8
fish_color_error d54e53
fish_color_param 7aa6da
fish_color_comment e7c547
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_operator 00a6b2
fish_color_history_current --bold
fish_color_escape 00a6b2
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 7aa6da
fish_color_keyword c397d8

View File

@@ -10,8 +10,8 @@ fish_color_end b294bb
fish_color_error cc6666
fish_color_param 81a2be
fish_color_comment f0c674
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -25,7 +25,7 @@ fish_color_host normal
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 81a2be
fish_color_keyword b294bb

View File

@@ -10,8 +10,8 @@ fish_color_end 8959a8
fish_color_error c82829
fish_color_param 4271ae
fish_color_comment eab700
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack
fish_color_selection white --background=brblack --bold
fish_color_search_match white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator 00a6b2
fish_color_escape 00a6b2
@@ -25,7 +25,7 @@ fish_pager_color_description B3A06D yellow
fish_pager_color_completion normal
fish_color_cancel -r
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=brblack
fish_color_option 4271ae
fish_color_keyword 8959a8

View File

@@ -10,8 +10,8 @@ fish_color_end F29668
fish_color_error FF3333
fish_color_param B3B1AD
fish_color_comment 626A73
fish_color_selection --background=E6B450
fish_color_search_match --background=E6B450
fish_color_selection --background=E6B450 --bold
fish_color_search_match --background=E6B450 --bold
fish_color_history_current --bold
fish_color_operator E6B450
fish_color_escape 95E6CB
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=E6B450
fish_color_option B3B1AD
fish_color_keyword 39BAE6

View File

@@ -10,8 +10,8 @@ fish_color_end ED9366
fish_color_error F51818
fish_color_param 575F66
fish_color_comment ABB0B6
fish_color_selection --background=FF9940
fish_color_search_match --background=FF9940
fish_color_selection --background=FF9940 --bold
fish_color_search_match --background=FF9940 --bold
fish_color_history_current --bold
fish_color_operator FF9940
fish_color_escape 4CBF99
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_description B3A06D yellow
fish_pager_color_completion normal
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=FF9940
fish_color_option 575F66
fish_color_keyword 55B4D4

View File

@@ -10,8 +10,8 @@ fish_color_end F29E74
fish_color_error FF3333
fish_color_param CBCCC6
fish_color_comment 5C6773
fish_color_selection --background=FFCC66
fish_color_search_match --background=FFCC66
fish_color_selection --background=FFCC66 --bold
fish_color_search_match --background=FFCC66 --bold
fish_color_history_current --bold
fish_color_operator FFCC66
fish_color_escape 95E6CB
@@ -25,7 +25,7 @@ fish_color_cancel -r
fish_pager_color_completion normal
fish_pager_color_description B3A06D yellow
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background --background=FFCC66
fish_color_option CBCCC6
fish_color_keyword 5CCFE6

View File

@@ -18,8 +18,8 @@ fish_color_operator 0AA
fish_color_param ccccff
fish_color_quote 9ce781
fish_color_redirection FFF
fish_color_search_match --background=533
fish_color_selection --background=B218B2
fish_color_search_match --background=533 --bold
fish_color_selection --background=B218B2 --bold
fish_color_status F22
fish_color_user brgreen
fish_color_valid_path --underline

View File

@@ -11,8 +11,8 @@ fish_color_end green
fish_color_error brred
fish_color_param cyan
fish_color_comment red
fish_color_search_match white --background=brblack
fish_color_selection white --bold --background=brblack
fish_color_search_match white --background=brblack --bold
fish_color_selection white --background=brblack --bold
fish_color_history_current --bold
fish_color_operator brcyan
fish_color_escape brcyan
@@ -26,7 +26,7 @@ fish_color_host normal
fish_pager_color_description yellow -i
fish_color_cancel -r
fish_pager_color_prefix normal --bold --underline
fish_pager_color_progress brwhite --background=cyan
fish_pager_color_progress brwhite --background=cyan --bold
fish_pager_color_selected_background -r
fish_color_option cyan
fish_color_keyword normal

View File

@@ -500,8 +500,6 @@ pub(crate) fn set_text_face(&mut self, face: TextFace) {
let bg = face.bg;
let underline_color = face.underline_color;
let style = face.style;
let mut bg_set = false;
let mut last_bg_set = false;
use TerminalCommand::{
DefaultBackgroundColor, DefaultUnderlineColor, EnterBoldMode, EnterCurlyUnderlineMode,
@@ -521,32 +519,12 @@ pub(crate) fn set_text_face(&mut self, face: TextFace) {
// Only way to exit non-resettable ones is a reset of all attributes.
self.reset_text_face();
}
if !self.last.bg.is_special() {
// Background was set.
// "Special" here refers to the special "normal" and "none" colors,
// that really just disable the background.
last_bg_set = true;
}
if !bg.is_special() {
// Background is set.
bg_set = true;
if fg == bg {
fg = if bg == Color::WHITE {
Color::BLACK
} else {
Color::WHITE
};
}
}
if bg_set && !last_bg_set {
// Background color changed and is set, so we enter bold mode to make reading easier.
// This means bold mode is _always_ on when the background color is set.
self.write_command(EnterBoldMode);
}
if !bg_set && last_bg_set {
// Background color changed and is no longer set, so we exit bold mode.
self.reset_text_face();
if !bg.is_special() && fg == bg {
fg = if bg == Color::WHITE {
Color::BLACK
} else {
Color::WHITE
};
}
if !fg.is_none() && fg != self.last.fg {
@@ -583,11 +561,7 @@ pub(crate) fn set_text_face(&mut self, face: TextFace) {
}
// Lastly, we set bold, underline, italics, dim, and reverse modes correctly.
if style.is_bold()
&& !self.last.style.is_bold()
&& !bg_set
&& self.write_command(EnterBoldMode)
{
if style.is_bold() && !self.last.style.is_bold() && self.write_command(EnterBoldMode) {
self.last.style.bold = true;
}