Skip to content

Commit 8679464

Browse files
Nahorkrobelus
authored andcommitted
color: prefer set_color --reset over set_color normal
`set_color normal` is too ambiguous and easily misinterpreted since it actually reset all colors and modes instead of resetting just the foreground color as one without prior knowledge might expect. Closes fish-shell#12548
1 parent 9ea760c commit 8679464

69 files changed

Lines changed: 214 additions & 209 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

doc_src/cmds/fish_breakpoint_prompt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ A simple prompt that is a simplified version of the default debugging prompt::
3434
set -l function (status current-function)
3535
set -l line (status current-line-number)
3636
set -l prompt "$function:$line >"
37-
echo -ns (set_color $fish_color_status) "BP $prompt" (set_color normal) ' '
37+
echo -ns (set_color $fish_color_status) "BP $prompt" (set_color --reset) ' '
3838
end
3939

doc_src/cmds/fish_config.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ The format looks like this:
8585
fish_color_command 5c5cff
8686

8787
[unknown]
88-
fish_color_normal normal
88+
fish_color_normal --reset
8989
fish_color_autosuggestion brblack
9090
fish_color_cancel -r
91-
fish_color_command normal
91+
fish_color_command --reset
9292

9393
The comments provide name and background color to the web config tool.
9494

doc_src/cmds/fish_greeting.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,5 @@ A simple greeting:
3939

4040
function fish_greeting
4141
echo Hello friend!
42-
echo The time is (set_color yellow)(date +%T)(set_color normal) and this machine is called $hostname
42+
echo The time is (set_color yellow)(date +%T)(set_color --reset) and this machine is called $hostname
4343
end

doc_src/cmds/fish_mode_prompt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ Example
6262
set_color --bold red
6363
echo '?'
6464
end
65-
set_color normal
65+
set_color --reset
6666
end
6767

6868

doc_src/cmds/fish_prompt.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ A simple prompt:
4141
# $USER and $hostname are set by fish, so you can just use them
4242
# instead of using `whoami` and `hostname`
4343
printf '%s@%s %s%s%s > ' $USER $hostname \
44-
(set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
44+
(set_color $fish_color_cwd) (prompt_pwd) (set_color --reset)
4545
end
4646

4747

doc_src/cmds/read.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ The following options control the interactive mode:
6262
Masks characters written to the terminal, replacing them with asterisks. This is useful for reading things like passwords or other sensitive information.
6363

6464
**-p** or **--prompt** *PROMPT_CMD*
65-
Uses the output of the shell command *PROMPT_CMD* as the prompt for the interactive mode. The default prompt command is ``set_color green; echo -n read; set_color normal; echo -n "> "``
65+
Uses the output of the shell command *PROMPT_CMD* as the prompt for the interactive mode. The default prompt command is ``set_color green; echo -n read; set_color --reset; echo -n "> "``
6666

6767
**-P** or **--prompt-str** *PROMPT_STR*
6868
Uses the literal *PROMPT_STR* as the prompt for the interactive mode.

doc_src/cmds/set_color.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ Synopsis
1111
Description
1212
-----------
1313

14-
``set_color`` is used to control the color and styling of text in the terminal. *VALUE* describes that styling. *VALUE* can be a reserved color name like **red** or an RGB color value given as 3 or 6 hexadecimal digits ("F27" or "FF2277"). A special keyword **normal** resets text formatting to terminal defaults.
14+
``set_color`` is used to control the color and styling of text in the terminal.
15+
*VALUE* describes that styling.
16+
*VALUE* can be a reserved color name like **red** or an RGB color value given as 3 or 6 hexadecimal digits ("F27" or "FF2277").
17+
A special keyword **normal** resets text formatting to terminal defaults, however it is not recommended and the **--reset** option is preferred as it is less confusing and more future-proof.
1518

1619
Valid colors include:
1720

@@ -87,9 +90,10 @@ Notes
8790

8891
1. Using ``set_color normal`` will reset all colors and modes to the terminal's default.
8992
2. In contrast, ``set_color --foreground normal`` will only reset the foreground color and leave all the other colors and modes unchanged.
90-
3. Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. Look for a config option.
91-
4. Some terminals use the ``--bold`` escape sequence to switch to a brighter color set rather than increasing the weight of text.
92-
5. ``set_color`` works by printing sequences of characters to standard output. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit status of ``isatty stdout`` before using ``set_color`` can be useful to decide not to colorize output in a script.
93+
3. Because of the risk of confusion, ``set_color --reset`` is recommended over ``set_color normal``.
94+
4. Setting the background color only affects subsequently written characters. Fish provides no way to set the background color for the entire terminal window. Configuring the window background color (and other attributes such as its opacity) has to be done using whatever mechanisms the terminal provides. Look for a config option.
95+
5. Some terminals use the ``--bold`` escape sequence to switch to a brighter color set rather than increasing the weight of text.
96+
6. ``set_color`` works by printing sequences of characters to standard output. If used in command substitution or a pipe, these characters will also be captured. This may or may not be desirable. Checking the exit status of ``isatty stdout`` before using ``set_color`` can be useful to decide not to colorize output in a script.
9397

9498
Examples
9599
--------

doc_src/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ The prompt is the output of the ``fish_prompt`` function. Put it in ``~/.config/
9191
function fish_prompt
9292
set_color $fish_color_cwd
9393
echo -n (prompt_pwd)
94-
set_color normal
94+
set_color --reset
9595
echo -n ' > '
9696
end
9797

doc_src/fish_for_bash_users.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ and a rough fish equivalent::
318318
319319
echo -s (prompt_hostname) \
320320
(set_color blue) (prompt_pwd) \
321-
(set_color yellow) $prompt_symbol (set_color normal)
321+
(set_color yellow) $prompt_symbol (set_color --reset)
322322
end
323323
324324
This shows a few differences:

doc_src/interactive.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ Syntax highlighting variables
105105

106106
The colors used by fish for syntax highlighting can be configured by changing the values of various variables. The value of these variables can be one of the colors accepted by the :doc:`set_color <cmds/set_color>` command.
107107
Options accepted by ``set_color`` like
108+
``--foreground=``,
108109
``--background=``,
109110
``--bold``,
110111
``--dim``,

0 commit comments

Comments
 (0)