feat(functions): derive the shared help palette from the fish theme

__fish_palette's c_cmd/c_flag/c_arg/c_dim now read fish's own highlighter
variables (fish_color_command/option/param/autosuggestion) when set, and
c_head reads the pager's fish_pager_color_prefix, so --help text matches
whatever the user's actual theme renders at the prompt instead of a fixed
guess at it. Each role keeps its previous static value as a fallback
(e.g. a --no-config script, or the theme variable being unset or empty).

Routes __fish_help_header's title/section colors and config-help's,
gi's, and git-clean's own hand-rolled --help blocks through the palette
instead of their hardcoded set_color calls, which fixes the
--help-vs-actual-prompt color mismatch across most of the config's
functions in one place (__fish_help_header backs the majority of
user-facing --help output).

Also fixes role mismatches found along the way: several already-palette
functions (dockup, fish-deps, pkg, play-media, dng2avif) were coloring
their <placeholder>/[bracket] argument text with c_dim instead of c_arg,
and scrub's "Aggressive Targets:" heading was still a hardcoded
set_color call sitting next to an otherwise-converted help block.
This commit is contained in:
2026-09-21 01:19:38 -04:00
parent 02c060f9f1
commit 610714476d
11 changed files with 103 additions and 96 deletions
+28 -9
View File
@@ -19,11 +19,18 @@
# TERM=dumb, which yields empty strings, and is unaffected by whether
# stdout is a tty or a pipe.)
#
# A role is a semantic slot, not a colour. c_flag and c_warn are both
# yellow but stay separate, as do c_ok and c_accent (both green) --
# merging either pair would foreclose ever restyling one without the
# other. c_accent is the command name in logs and smart_exit, which
# style it green where the rest of the config styles it bold.
# A role is a semantic slot, not a colour. c_flag and c_warn can both be
# yellow but stay separate, as do c_ok and c_accent -- merging either
# pair would foreclose ever restyling one without the other. c_accent is
# the command name in logs and smart_exit, which style it green where
# the rest of the config styles it bold.
#
# c_cmd, c_flag, c_arg, and c_dim are drawn from fish's own highlighter
# variables (fish_color_command/option/param/autosuggestion) when set,
# and c_head from the pager's fish_pager_color_prefix -- the same colour
# a real command, flag, argument, or pager heading gets at the prompt.
# Each falls back to its previous static default when the theme
# variable is unset or empty (e.g. a --no-config script).
#
# ARGUMENTS
# none
@@ -49,15 +56,27 @@
function __fish_palette --no-scope-shadowing --description 'Define the shared output colour palette in the caller scope'
set c_reset (set_color normal)
set c_head (set_color --bold cyan)
set c_cmd (set_color --bold)
set c_cmd (set_color brblue)
set c_flag (set_color brgreen)
set c_arg (set_color cyan)
set c_flag (set_color yellow)
set c_dim (set_color brblack)
set c_head (set_color --bold cyan)
set c_warn (set_color yellow)
set c_err (set_color red)
set c_ok (set_color green)
set c_accent (set_color green)
set c_dim (set_color brblack)
set c_sel (set_color --bold magenta)
set c_hi (set_color --bold white)
# Theme overrides: same roles fish's own highlighter/pager use, so
# --help text matches the prompt instead of a fixed guess at it.
set -l roles command option param autosuggestion
set -l vars c_cmd c_flag c_arg c_dim
for i in (seq (count $roles))
set -l themevar fish_color_$roles[$i]
set -q $themevar; and test (count $$themevar) -gt 0
and set $vars[$i] (set_color $$themevar)
end
set -q fish_pager_color_prefix; and test (count $fish_pager_color_prefix) -gt 0
and set c_head (set_color --bold $fish_pager_color_prefix)
end