make set_term 24 bits aware
This commit is contained in:
@@ -325,10 +325,14 @@ term_set()
|
||||
local _term_has
|
||||
_term_has() { tput -T "$1" longname >/dev/null 2>&1; }
|
||||
|
||||
# True-color hint: COLORTERM=truecolor|24bit is set by the emulator.
|
||||
local _truecolor=0
|
||||
[[ "${COLORTERM:-}" == "truecolor" || "${COLORTERM:-}" == "24bit" ]] && _truecolor=1
|
||||
|
||||
local _candidate=""
|
||||
|
||||
# 1. Explicit truecolor hint set by modern terminal emulators.
|
||||
if [[ "${COLORTERM:-}" == "truecolor" || "${COLORTERM:-}" == "24bit" ]]; then
|
||||
if (( _truecolor )); then
|
||||
local _t
|
||||
for _t in xterm-direct xterm-256color; do
|
||||
_term_has "$_t" && { _candidate="$_t"; break; }
|
||||
@@ -339,38 +343,62 @@ term_set()
|
||||
if [[ -z "$_candidate" ]]; then
|
||||
case "${TERM_PROGRAM:-}" in
|
||||
iTerm.app)
|
||||
_term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
if (( _truecolor )); then
|
||||
_term_has "xterm-direct" && _candidate="xterm-direct"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
;;
|
||||
WezTerm)
|
||||
if (( _truecolor )); then
|
||||
_term_has "xterm-direct" && _candidate="xterm-direct"
|
||||
fi
|
||||
if [[ -z "$_candidate" ]]; then
|
||||
_term_has "wezterm" && _candidate="wezterm"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
;;
|
||||
Hyper|vscode)
|
||||
_term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
if (( _truecolor )); then
|
||||
_term_has "xterm-direct" && _candidate="xterm-direct"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# 3. VTE-based terminals (GNOME Terminal, Tilix, Xfce Terminal, …).
|
||||
if [[ -z "$_candidate" && -n "${VTE_VERSION:-}" ]]; then
|
||||
_term_has "vte-256color" && _candidate="vte-256color"
|
||||
if (( _truecolor )); then
|
||||
_term_has "vte-direct" && _candidate="vte-direct"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "vte-256color" && _candidate="vte-256color"
|
||||
[[ -z "$_candidate" ]] && _term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
fi
|
||||
|
||||
# 4. Windows Terminal.
|
||||
if [[ -z "$_candidate" && -n "${WT_SESSION:-}" ]]; then
|
||||
_term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
if (( _truecolor )); then
|
||||
_term_has "xterm-direct" && _candidate="xterm-direct"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "xterm-256color" && _candidate="xterm-256color"
|
||||
fi
|
||||
|
||||
# 5. tmux — prefer tmux-256color, fall back to screen-256color.
|
||||
# 5. tmux — prefer *-direct when truecolor, then *-256color, then screen-256color.
|
||||
if [[ -z "$_candidate" && -n "${TMUX:-}" ]]; then
|
||||
_term_has "tmux-256color" && _candidate="tmux-256color"
|
||||
if (( _truecolor )); then
|
||||
_term_has "tmux-direct" && _candidate="tmux-direct"
|
||||
[[ -z "$_candidate" ]] && _term_has "screen-direct" && _candidate="screen-direct"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "tmux-256color" && _candidate="tmux-256color"
|
||||
[[ -z "$_candidate" ]] && _term_has "screen-256color" && _candidate="screen-256color"
|
||||
fi
|
||||
|
||||
# 6. GNU screen — prefer screen-256color, fall back to screen.
|
||||
# 6. GNU screen — prefer screen-direct when truecolor, then screen-256color.
|
||||
if [[ -z "$_candidate" && -n "${STY:-}" ]]; then
|
||||
_term_has "screen-256color" && _candidate="screen-256color"
|
||||
if (( _truecolor )); then
|
||||
_term_has "screen-direct" && _candidate="screen-direct"
|
||||
fi
|
||||
[[ -z "$_candidate" ]] && _term_has "screen-256color" && _candidate="screen-256color"
|
||||
[[ -z "$_candidate" ]] && _term_has "screen" && _candidate="screen"
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user