aloxaf.fzf-tab/lib/-ftb-colorize
birkhoff 0983009f86
fix: append SGR reset to dsuf to prevent background color bleed (#570)
In lib/-ftb-colorize, the color opened in dpre was never closed in dsuf,
causing background colors (e.g. from vivid LS_COLORS themes) to bleed
into the first character of the following entry in the fzf list.

- Symlink branch: append \033[0m after the resolved path in dsuf
- Non-symlink branch: prepend \033[0m to dsuf

Note: the C module (fzf-tab-candidates-generate builtin) already appends
\033[0m to dsuf in fzftab.c:454 so it is unaffected.

Fixes: #563
2026-03-17 19:39:13 +08:00

36 lines
925 B
Bash

#!/hint/zsh
emulate -L zsh -o cbases -o octalzeroes
local REPLY
local -a reply stat lstat
# fzf-tab-lscolors::match-by $1 lstat follow
zstat -A lstat -L -- $1
# follow symlink
(( lstat[3] & 0170000 )) && zstat -A stat -- $1 2>/dev/null
fzf-tab-lscolors::from-mode "$1" "$lstat[3]" $stat[3]
# fall back to name
[[ -z $REPLY ]] && fzf-tab-lscolors::from-name $1
# If this is a symlink
if [[ -n $lstat[14] ]]; then
local sym_color=$REPLY
local rsv_color=$REPLY
local rsv=$lstat[14]
# If this is not a broken symlink
if [[ -e $rsv ]]; then
# fzf-tab-lscolors::match-by $rsv stat
zstat -A stat -- $rsv
fzf-tab-lscolors::from-mode $rsv $stat[3]
# fall back to name
[[ -z $REPLY ]] && fzf-tab-lscolors::from-name $rsv
rsv_color=$REPLY
fi
dpre=$'\033[0m\033['$sym_color'm'
dsuf+=$'\033[0m -> \033['$rsv_color'm'$rsv$'\033[0m'
else
dpre=$'\033[0m\033['$REPLY'm'
dsuf=$'\033[0m'$dsuf
fi