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