summaryrefslogtreecommitdiff
path: root/powerlevel9k.zsh-theme
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-05-29 10:21:02 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-05-29 10:41:59 +0300
commit01320275d234f7c39f65ebc374f00249fb9fa9b2 (patch)
tree5ec13fab4e03debb5b94462312ec112a2ba103df /powerlevel9k.zsh-theme
parent58545efa017975ebaec91f403e9b431ae16b77c8 (diff)
add a workaround for an off-by-one bug in ZSH that triggers when PROMPT overflows a line
Diffstat (limited to 'powerlevel9k.zsh-theme')
-rwxr-xr-xpowerlevel9k.zsh-theme32
1 files changed, 27 insertions, 5 deletions
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index 9732b609..a7a90193 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -411,10 +411,11 @@ function _p9k_left_prompt_end_line() {
_P9K_PROMPT+="\${_P9K_T[\$_P9K_N]}"
_P9K_PROMPT+="%f$1%f%k%b"
- (( ! _P9K_RPROMPT_DONE )) || return 0
- _P9K_PROMPT+=$_P9K_ALIGNED_RPROMPT
- _P9K_RPROMPT_DONE=1
- (( ${ZLE_RPROMPT_INDENT:-1} > 0 ))
+ if (( ! _P9K_RPROMPT_DONE )); then
+ _P9K_PROMPT+=$_P9K_ALIGNED_RPROMPT
+ _P9K_RPROMPT_DONE=1
+ return 1
+ fi
}
################################################################
@@ -2317,6 +2318,23 @@ _p9k_init_timer() {
fi
}
+# Does ZSH have a certain off-by-one bug that triggers when PROMPT overflows to a new line?
+#
+# Bug: https://github.com/zsh-users/zsh/commit/d8d9fee137a5aa2cf9bf8314b06895bfc2a05518.
+# ZSH_PATCHLEVEL=zsh-5.4.2-159-gd8d9fee13. Released in 5.5.
+#
+# Fix: https://github.com/zsh-users/zsh/commit/64d13738357c9b9c212adbe17f271716abbcf6ea.
+# ZSH_PATCHLEVEL=zsh-5.7.1-50-g64d137383.
+#
+# Test: PROMPT="${(pl:$((COLUMNS))::-:)}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
+# Workaround: PROMPT="${(pl:$((COLUMNS))::-:)}%{%G%}<%1(l.%2(l.FAIL.PASS).FAIL)> " zsh -dfis <<<exit
+function _p9k_prompt_overflow_bug() {
+ is-at-least 5.4.2 || return 1
+ [[ $ZSH_PATCHLEVEL =~ '^zsh-5\.4\.2-([0-9]+)-' ]] && return $(( match[1] < 159 ))
+ is-at-least 5.7.2 && return 1
+ [[ $ZSH_PATCHLEVEL =~ '^zsh-5\.7\.1-([0-9]+)-' ]] && return $(( match[1] >= 50 ))
+}
+
# Some people write POWERLEVEL9K_DIR_PATH_SEPARATOR='\uNNNN' instead of
# POWERLEVEL9K_DIR_PATH_SEPARATOR=$'\uNNNN'. There is no good reason for it and if we were
# starting from scratch we wouldn't perform automatic conversion from the former to the latter.
@@ -2426,6 +2444,8 @@ _p9k_init() {
_p9k_init_timer
fi
+ _p9k_prompt_overflow_bug && local glitch='%{%G%}' || local glitch=''
+
_P9K_ALIGNED_RPROMPT='${${:-${_P9K_X::=0}${_P9K_Y::=$((COLUMNS+1))}'
repeat 10; do
_P9K_ALIGNED_RPROMPT+='${_P9K_M::=$(((_P9K_X+_P9K_Y)/2))}'
@@ -2442,7 +2462,8 @@ _p9k_init() {
repeat 32; do
_P9K_ALIGNED_RPROMPT+='%-$_P9K_X(l. .)'
done
- _P9K_ALIGNED_RPROMPT+=' $_P9K_RPROMPT'
+ _P9K_ALIGNED_RPROMPT+=' $_P9K_RPROMPT${(pl.${${ZLE_RPROMPT_INDENT:-1}/#-*/0}.. .)}'
+ _P9K_ALIGNED_RPROMPT+=$glitch
if [[ $POWERLEVEL9K_PROMPT_ADD_NEWLINE == true ]]; then
repeat ${POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT:-1} _P9K_LEFT_PREFIX+=$'\n'
@@ -2465,6 +2486,7 @@ _p9k_init() {
local pad_len="\$((COLUMNS-$ruler_len))"
_P9K_LEFT_PREFIX+="%b\${(pl$sep$ruler_len$sep$sep${(q)ruler_char}$sep)}%k%f"
_P9K_LEFT_PREFIX+="\${(l$sep$pad_len$sep$sep $sep)}"
+ _P9K_LEFT_PREFIX+=$glitch
else
print -P "%F{red}WARNING!%f %BPOWERLEVEL9K_RULER_CHAR%b is not one character long. Ruler won't be rendered."
print -P "Either change the value of %BPOWERLEVEL9K_RULER_CHAR%b or set %BPOWERLEVEL9K_SHOW_RULER=false%b to"