Merge pull request #142 from zmwangx/string-length-fix

prompt_pure_string_length: no need to subtract one
This commit is contained in:
Mathias Fredriksson
2015-07-15 15:32:56 +03:00

View File

@@ -76,8 +76,7 @@ prompt_pure_preexec() {
# string length ignoring ansi escapes # string length ignoring ansi escapes
prompt_pure_string_length() { prompt_pure_string_length() {
# Subtract one since newline is counted as two characters echo $(( ${#${(S%%)1//(\%([KF1]|)\{*\}|\%[Bbkf])}} ))
echo $(( ${#${(S%%)1//(\%([KF1]|)\{*\}|\%[Bbkf])}} - 1 ))
} }
prompt_pure_preprompt_render() { prompt_pure_preprompt_render() {
@@ -108,11 +107,11 @@ prompt_pure_preprompt_render() {
# calculate length of preprompt for redraw purposes # calculate length of preprompt for redraw purposes
local preprompt_length=$(prompt_pure_string_length $preprompt) local preprompt_length=$(prompt_pure_string_length $preprompt)
local lines=$(( $preprompt_length / $COLUMNS + 1 )) local lines=$(( ($preprompt_length - 1) / $COLUMNS + 1 ))
# disable clearing of line if last char of preprompt is last column of terminal # disable clearing of line if last char of preprompt is last column of terminal
local clr="\e[K" local clr="\e[K"
(( $preprompt_length * $lines == $COLUMNS - 1 )) && clr="" (( $COLUMNS * $lines == $preprompt_length )) && clr=""
# modify previous preprompt # modify previous preprompt
print -Pn "\e7\e[${lines}A\e[1G${preprompt}${clr}\e8" print -Pn "\e7\e[${lines}A\e[1G${preprompt}${clr}\e8"