From 7969eb3f1881c06cf1749f5eab5dedae122bc5eb Mon Sep 17 00:00:00 2001 From: Roman Perepelitsa Date: Mon, 16 Nov 2020 09:02:31 +0100 Subject: [PATCH] retain instant prompt and state dumps when TERM or TERM_PROGRAM change (#1098) --- internal/p10k.zsh | 122 +++++++++++++++++++++++----------------------- 1 file changed, 62 insertions(+), 60 deletions(-) diff --git a/internal/p10k.zsh b/internal/p10k.zsh index f1534e7f..acbbbfd1 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -5758,7 +5758,7 @@ _p9k_set_instant_prompt() { [[ -n $RPROMPT ]] || unset RPROMPT } -typeset -gri __p9k_instant_prompt_version=37 +typeset -gri __p9k_instant_prompt_version=38 _p9k_dump_instant_prompt() { local user=${(%):-%n} @@ -5774,7 +5774,7 @@ _p9k_dump_instant_prompt() { local -i fd sysopen -a -m 600 -o creat,trunc -u fd -- $tmp || return { - [[ $TERM_PROGRAM == Hyper ]] && local hyper='==' || local hyper='!=' + [[ $TERM == (screen*|tmux*) ]] && local screen='-n' || local screen='-z' local -a display_v=("${_p9k__display_v[@]}") local -i i for ((i = 6; i <= $#display_v; i+=2)); do display_v[i]=show; done @@ -5785,14 +5785,16 @@ _p9k_dump_instant_prompt() { if [[ -r $gitstatus_dir/install.info ]]; then IFS= read -r gitstatus_header <$gitstatus_dir/install.info || return fi + >&$fd print -r -- '[[ -t 0 && -t 1 && -t 2 && -o interactive && -o zle && -o no_xtrace ]] && + ! (( ${+__p9k_instant_prompt_disabled} || ZSH_SUBSHELL || ${+ZSH_SCRIPT} || ${+ZSH_EXECUTION_STRING} )) || return 0' >&$fd print -r -- "() { $__p9k_intro_no_locale - (( ! \$+__p9k_instant_prompt_disabled )) || return - typeset -gi __p9k_instant_prompt_disabled=1 __p9k_instant_prompt_sourced=$__p9k_instant_prompt_version + typeset -gi __p9k_instant_prompt_disabled=1 [[ \$ZSH_VERSION == ${(q)ZSH_VERSION} && \$ZSH_PATCHLEVEL == ${(q)ZSH_PATCHLEVEL} && - \$TERM_PROGRAM $hyper 'Hyper' && \$+VTE_VERSION == $+VTE_VERSION && \$TERM == ${(q)TERM} && + $screen \${(M)TERM:#(screen*|tmux*)} && + \${#\${(M)VTE_VERSION:#(<1-4602>|4801)}} == ${#${(M)VTE_VERSION:#(<1-4602>|4801)}} && \$POWERLEVEL9K_DISABLE_INSTANT_PROMPT != 'true' && - \$POWERLEVEL9K_INSTANT_PROMPT != 'off' ]] || { __p9k_instant_prompt_sourced=0; return 1; } + \$POWERLEVEL9K_INSTANT_PROMPT != 'off' ]] || return typeset -g __p9k_instant_prompt_param_sig=${(q+)_p9k__param_sig} local gitstatus_dir=${(q)gitstatus_dir} local gitstatus_header=${(q)gitstatus_header} @@ -5808,12 +5810,7 @@ _p9k_dump_instant_prompt() { if [[ -r $gitstatus_dir/install.info ]]; then IFS= read -r real_gitstatus_header <$gitstatus_dir/install.info || real_gitstatus_header=borked fi - if [[ $real_gitstatus_header != $gitstatus_header ]]; then - __p9k_instant_prompt_sourced=0 - return 1 - fi - [[ $ZSH_SUBSHELL == 0 && -z $ZSH_SCRIPT && -z $ZSH_EXECUTION_STRING && - -t 0 && -t 1 && -t 2 && -o interactive && -o zle && -o no_xtrace ]] || return + [[ $real_gitstatus_header == $gitstatus_header ]] || return zmodload zsh/langinfo zsh/terminfo zsh/system || return if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]]; then local loc_cmd=$commands[locale] @@ -5833,9 +5830,16 @@ _p9k_dump_instant_prompt() { local prompt_file=$prompt_dir/prompt-${#pwd} local key=$pwd:$ssh:${(%):-%#} local content + if [[ ! -e $prompt_file ]]; then + typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version' + return 1 + fi { content="$(<$prompt_file)" } 2>/dev/null || return local tail=${content##*$rs$key$us} - [[ ${#tail} != ${#content} ]] || return + if (( ${#tail} == ${#content} )); then + typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version' + return 1 + fi local P9K_PROMPT=instant if [[ -z $P9K_TTY || $P9K_TTY == old && -n ${_P9K_TTY:#$TTY} ]]; then' if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then @@ -5962,37 +5966,36 @@ _p9k_dump_instant_prompt() { fi >&$fd print -r -- ' trap "unset -m _p9k__\*; unfunction p10k" EXIT - local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")' - if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]]; then - if [[ $TERM_PROGRAM == Hyper ]]; then - local bad_lines=40 bad_columns=100 - else - local bad_lines=24 bad_columns=80 - fi - >&$fd print -r -- ' - if (( LINES == '$bad_lines' && COLUMNS == '$bad_columns' )); then - zmodload -F zsh/stat b:zstat || return - zmodload zsh/datetime || return - local -a tty_ctime - if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( tty_ctime[1] + 2 > EPOCHREALTIME )); then - local -F deadline=$((EPOCHREALTIME+0.025)) - local tty_size - while true; do - if (( EPOCHREALTIME > deadline )) || ! tty_size="$(/bin/stty size 2>/dev/null)" || [[ $tty_size != <->" "<-> ]]; then - (( $+_p9k__ruler_i )) || local -i _p9k__ruler_i=1 - local _p9k__g= _p9k__'$#_p9k_line_segments_right'r= _p9k__'$#_p9k_line_segments_right'r_frame= - break - fi - if [[ $tty_size != "'$bad_lines' '$bad_columns'" ]]; then - local lines_columns=(${=tty_size}) - local LINES=$lines_columns[1] - local COLUMNS=$lines_columns[2] - break - fi - done + local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}") + if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && (( $+commands[stty] )); then + if [[ $TERM_PROGRAM == Hyper ]]; then + local bad_lines=40 bad_columns=100 + else + local bad_lines=24 bad_columns=80 + fi + if (( LINES == bad_lines && COLUMNS == bad_columns )); then + zmodload -F zsh/stat b:zstat || return + zmodload zsh/datetime || return + local -a tty_ctime + if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( tty_ctime[1] + 2 > EPOCHREALTIME )); then + local -F deadline=$((EPOCHREALTIME+0.025)) + local tty_size + while true; do + if (( EPOCHREALTIME > deadline )) || ! tty_size="$(command stty size 2>/dev/null)" || [[ $tty_size != <->" "<-> ]]; then + (( $+_p9k__ruler_i )) || local -i _p9k__ruler_i=1 + local _p9k__g= _p9k__'$#_p9k_line_segments_right'r= _p9k__'$#_p9k_line_segments_right'r_frame= + break + fi + if [[ $tty_size != "$bad_lines $bad_columns" ]]; then + local lines_columns=(${=tty_size}) + local LINES=$lines_columns[1] + local COLUMNS=$lines_columns[2] + break + fi + done + fi fi fi' - fi (( __p9k_ksh_arrays )) && >&$fd print -r -- ' setopt ksh_arrays' (( __p9k_sh_glob )) && >&$fd print -r -- ' setopt sh_glob' >&$fd print -r -- ' typeset -ga __p9k_used_instant_prompt=("${(@e)_p9k_t[-3,-1]}")' @@ -6017,15 +6020,13 @@ _p9k_dump_instant_prompt() { fi _p9k__ret=$x } - local out' - [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && >&$fd print -r -- ' if (( ! $+_p9k__g )); then' - >&$fd print -r -- ' - local mark=${(e)PROMPT_EOL_MARK} - [[ $mark == "%B%S%#%s%b" ]] && _p9k__ret=1 || _p9k_prompt_length $mark - local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0)) - out+="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}"' - [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && >&$fd print -r -- ' fi' - >&$fd print -r -- ' + local out + if [[ $+VTE_VERSION == 0 && $TERM_PROGRAM != Hyper ]] || (( ! $+_p9k__g )); then + local mark=${(e)PROMPT_EOL_MARK} + [[ $mark == "%B%S%#%s%b" ]] && _p9k__ret=1 || _p9k_prompt_length $mark + local -i fill=$((COLUMNS > _p9k__ret ? COLUMNS - _p9k__ret : 0)) + out+="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}" + fi out+="${(pl.$height..$lf.)}$esc${height}A$terminfo[sc]" out+=${(%):-"$__p9k_used_instant_prompt[1]$__p9k_used_instant_prompt[2]"} if [[ -n $__p9k_used_instant_prompt[3] ]]; then @@ -6094,7 +6095,8 @@ _p9k_dump_instant_prompt() { zshexit_functions=(_p9k_instant_prompt_cleanup $zshexit_functions) precmd_functions=(_p9k_instant_prompt_precmd_first $precmd_functions) DISABLE_UPDATE_PROMPT=true -} && unsetopt prompt_cr prompt_sp || true' +} && unsetopt prompt_cr prompt_sp && typeset -gi __p9k_instant_prompt_sourced='$__p9k_instant_prompt_version' || + typeset -gi __p9k_instant_prompt_sourced=${__p9k_instant_prompt_sourced:-0}' } always { exec {fd}>&- } @@ -7936,11 +7938,11 @@ _p9k_must_init() { _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1' _p9k__param_pat+=$'$GITSTATUS_CACHE_DIR\1$GITSTATUS_AUTO_INSTALL\1${ZLE_RPROMPT_INDENT:-1}\1' _p9k__param_pat+=$'$__p9k_sh_glob\1$__p9k_ksh_arrays\1$ITERM_SHELL_INTEGRATION_INSTALLED\1' - _p9k__param_pat+=$'${PROMPT_EOL_MARK-%B%S%#%s%b}\1$commands[locale]\1$langinfo[CODESET]\1' - _p9k__param_pat+=$'$VTE_VERSION\1$TERM_PROGRAM\1$DEFAULT_USER\1$P9K_SSH\1$commands[uname]\1' + _p9k__param_pat+=$'${PROMPT_EOL_MARK-%B%S%#%s%b}\1$+commands[locale]\1$langinfo[CODESET]\1' + _p9k__param_pat+=$'${(M)VTE_VERSION:#(<1-4602>|4801)}\1$DEFAULT_USER\1$P9K_SSH\1$+commands[uname]\1' _p9k__param_pat+=$'$__p9k_root_dir\1$functions[p10k-on-init]\1$functions[p10k-on-pre-prompt]\1' _p9k__param_pat+=$'$functions[p10k-on-post-widget]\1$functions[p10k-on-post-prompt]\1' - _p9k__param_pat+=$'$+commands[git]\1$terminfo[colors]\1$TERM' + _p9k__param_pat+=$'$+commands[git]\1$terminfo[colors]' local MATCH IFS=$'\1' _p9k__param_pat+="${(@)${(@o)parameters[(I)POWERLEVEL9K_*]}:/(#m)*/\${${(q)MATCH}-$IFS\}}" IFS=$'\2' _p9k__param_sig="${(e)_p9k__param_pat}" @@ -8357,6 +8359,11 @@ _p9k_init() { _p9k_dumped_instant_prompt_sigs=() fi + if (( $+__p9k_instant_prompt_sourced && __p9k_instant_prompt_sourced != __p9k_instant_prompt_version )); then + _p9k_delete_instant_prompt + _p9k_dumped_instant_prompt_sigs=() + fi + if (( $+__p9k_instant_prompt_erased )); then unset __p9k_instant_prompt_erased { @@ -8832,10 +8839,5 @@ if [[ $__p9k_dump_file != $__p9k_instant_prompt_dump_file && -n $__p9k_instant_p zf_rm -f -- $__p9k_instant_prompt_dump_file{,.zwc} 2>/dev/null fi -if [[ $+__p9k_instant_prompt_sourced == 1 && $__p9k_instant_prompt_sourced != $__p9k_instant_prompt_version ]]; then - _p9k_delete_instant_prompt - zf_rm -f -- $__p9k_dump_file{,.zwc} 2>/dev/null -fi - _p9k_init_ssh prompt_powerlevel9k_setup