Compare expanded preprompt when rendering (#214)

* Compare expanded preprompt when rendering

The expanded content of the preprompt was not considered previously when
checking if the content had changed. E.g. path changes were never detected.
The typeset (definition) and assignment are performed on separate lines as it
would cause issues otherwise.

Fixes #213.
This commit is contained in:
Mathias Fredriksson
2016-07-27 12:04:49 +03:00
committed by GitHub
parent b3adab82c0
commit e3f1f87fc3

View File

@@ -141,12 +141,15 @@ prompt_pure_preprompt_render() {
# execution time
preprompt+="%F{yellow}${prompt_pure_cmd_exec_time}%f"
# make sure prompt_pure_last_preprompt is a global array
typeset -g -a prompt_pure_last_preprompt
# if executing through precmd, do not perform fancy terminal editing
if [[ "$1" == "precmd" ]]; then
print -P "\n${preprompt}"
else
# only redraw if preprompt has changed
[[ "${prompt_pure_last_preprompt}" != "${preprompt}" ]] || return
# only redraw if the expanded preprompt has changed
[[ "${prompt_pure_last_preprompt[2]}" != "${(S%%)preprompt}" ]] || return
# calculate length of preprompt and store it locally in preprompt_length
integer preprompt_length lines
@@ -157,7 +160,7 @@ prompt_pure_preprompt_render() {
# calculate previous preprompt lines to figure out how the new preprompt should behave
integer last_preprompt_length last_lines
prompt_pure_string_length_to_var "${prompt_pure_last_preprompt}" "last_preprompt_length"
prompt_pure_string_length_to_var "${prompt_pure_last_preprompt[1]}" "last_preprompt_length"
(( last_lines = ( last_preprompt_length - 1 ) / COLUMNS + 1 ))
# clr_prev_preprompt erases visual artifacts from previous preprompt
@@ -190,8 +193,8 @@ prompt_pure_preprompt_render() {
zle && zle .reset-prompt
fi
# store previous preprompt for comparison
prompt_pure_last_preprompt=$preprompt
# store both unexpanded and expanded preprompt for comparison
prompt_pure_last_preprompt=("$preprompt" "${(S%%)preprompt}")
}
prompt_pure_precmd() {