From ff140cf81ac4b3246bde3a5b4b3f3c82e5e7a6b2 Mon Sep 17 00:00:00 2001 From: Alexander Barton Date: Thu, 6 Jul 2017 22:55:35 +0200 Subject: [PATCH] Implement new axzsh_is_widechar_terminal() function This function tries to detect if the current terminal can display "wide characters" or not. Idea: At the moment, this function is used by the "axemoji" theme and the default "right side error prompt" to not use wide characters that would destroy the layout of the terminal used. --- core/11_terminal/11_terminal.zshrc | 12 ++++++++++++ themes/ax.axzshtheme | 2 +- themes/axemoji.axzshtheme | 8 ++------ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/11_terminal/11_terminal.zshrc b/core/11_terminal/11_terminal.zshrc index f26a131..0c7bce0 100644 --- a/core/11_terminal/11_terminal.zshrc +++ b/core/11_terminal/11_terminal.zshrc @@ -21,6 +21,18 @@ function axzsh_is_utf_terminal { } alias isutfenv=axzsh_is_utf_terminal +# Check if terminal supports "wide" characters. +# +function axzsh_is_widechar_terminal { + [[ -t 1 ]] || return 1 + axzsh_is_utf_terminal || return 1 + echo -ne "🍀\033[6n\033[1K\r" + read -s -d\[ garbage + read -s -d R pos + [[ "${pos#*;}" -eq 2 ]] || return 1 + return 0 +} + # Test for "modern" terminal function axzsh_is_modern_terminal { [[ "$TERM" = screen* ]] && return 0 diff --git a/themes/ax.axzshtheme b/themes/ax.axzshtheme index b4cae34..df8b056 100644 --- a/themes/ax.axzshtheme +++ b/themes/ax.axzshtheme @@ -16,7 +16,7 @@ ax_hostname_prompt_functions=($ax_hostname_prompt_functions ax_hostname_prompt_r PS1="$(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b"'$(ax_vcs_prompt)'"$(ax_prompt)" # Prompt on right side -axzsh_is_utf_terminal \ +axzsh_is_widechar_terminal \ && RPS1="%(?..%{$fg_no_bold[red]%}%? ↵%{$reset_color%})" \ || RPS1="%(?..%{$fg_no_bold[red]%}<%?>%{$reset_color%})" diff --git a/themes/axemoji.axzshtheme b/themes/axemoji.axzshtheme index eeb05f1..b309bf9 100644 --- a/themes/axemoji.axzshtheme +++ b/themes/axemoji.axzshtheme @@ -4,11 +4,7 @@ ZSH_THEME_PROMPT_PREFIX_SPACING=" " ZSH_THEME_PROMPT_SUFFIX_SPACING=" " -enable_emoji=1 - -[[ "$TERM_PROGRAM" = "Hyper" ]] && unset enable_emoji - -if [[ -n "$enable_emoji" ]] && axzsh_is_utf_terminal; then +if axzsh_is_widechar_terminal; then # UTF8 capable terminal: if [[ -r "$HOME/.system_emoji-$SHORT_HOST" ]]; then system_emoji=$(<"$HOME/.system_emoji-$SHORT_HOST") @@ -36,4 +32,4 @@ fi PS1="${system_emoji}${emoji_spacing} $(ax_logname_prompt_yn)$(ax_hostname_prompt_yn)%B%2~%b"'$(ax_vcs_prompt)'"$(ax_prompt)" -unset enable_emoji system_emoji emoji_spacing +unset system_emoji emoji_spacing -- 2.39.2