]> arthur.barton.de Git - ax-zsh.git/commitdiff
Implement new axzsh_is_widechar_terminal() function
authorAlexander Barton <alex@barton.de>
Thu, 6 Jul 2017 20:55:35 +0000 (22:55 +0200)
committerAlexander Barton <alex@barton.de>
Thu, 6 Jul 2017 20:55:35 +0000 (22:55 +0200)
This function tries to detect if the current terminal can display "wide
characters" or not.

Idea:
<https://unix.stackexchange.com/questions/184345/detect-how-much-of-unicode-my-terminal-supports-even-through-screen>

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
themes/ax.axzshtheme
themes/axemoji.axzshtheme

index f26a13195e8be2689350169d138538587eec6273..0c7bce0a8bed651aa6d5dd0b6ec9cab9ae5eb838 100644 (file)
@@ -21,6 +21,18 @@ function axzsh_is_utf_terminal {
 }
 alias isutfenv=axzsh_is_utf_terminal
 
+# Check if terminal supports "wide" characters.
+# <https://unix.stackexchange.com/questions/184345/detect-how-much-of-unicode-my-terminal-supports-even-through-screen>
+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
index b4cae3489a1a7390ccc17f089c5a51d84ecabc22..df8b0565f1349b1dff7ef897806287ae901c8b15 100644 (file)
@@ -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%})"
 
index eeb05f16ea994cd311d30bc1d1a3576fd07d240e..b309bf9f943cd80f0a18693493eba2dd5b0d3321 100644 (file)
@@ -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