diff options
Diffstat (limited to 'internal/p10k.zsh')
-rw-r--r-- | internal/p10k.zsh | 846 |
1 files changed, 518 insertions, 328 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh index 0de24d95..243ab560 100644 --- a/internal/p10k.zsh +++ b/internal/p10k.zsh @@ -98,7 +98,7 @@ function getColorCode() { local v=${__p9k_colors[$k]} print -rP -- "%F{$v}$v - $k%f" done - return + return 0 ;; background) local k @@ -106,7 +106,7 @@ function getColorCode() { local v=${__p9k_colors[$k]} print -rP -- "%K{$v}$v - $k%k" done - return + return 0 ;; esac fi @@ -301,7 +301,7 @@ _p9k_cache_stat_get() { local -a key=($0 $label fprint "$@" "$_p9k__cache_stat_fprint") _p9k__cache_fprint_key="${(pj:\0:)key}" shift 2 _p9k_cache_val - return + return 0 fi if (( $+commands[md5] )); then @@ -325,7 +325,7 @@ _p9k_cache_stat_get() { _p9k_cache_key=$meta_key _p9k_cache_set "$_p9k__cache_stat_meta" "$_p9k__cache_stat_fprint" "$_p9k_cache_val[@]" shift 2 _p9k_cache_val - return + return 0 fi _p9k__cache_fprint_key=$_p9k_cache_key @@ -616,7 +616,7 @@ _p9k_left_prompt_segment() { fi p+="\${_p9k_c::=$content_exp_}" - p+='${_p9k_e::=${${__p9k_s_'${${1#prompt_}%%[A-Z_]#}'+00}:-' + p+='${_p9k_e::=${${_p9k__'${_p9k_line_index}l${${1#prompt_}%%[A-Z_]#}'+00}:-' if (( has_icon == -1 )); then p+='${${(%):-$_p9k_c%1(l.1.0)}[-1]}${${(%):-$_p9k_v%1(l.1.0)}[-1]}}' else @@ -837,7 +837,7 @@ _p9k_right_prompt_segment() { fi p+="\${_p9k_c::=$content_exp_}" - p+='${_p9k_e::=${${__p9k_s_'${${1#prompt_}%%[A-Z_]#}'+00}:-' + p+='${_p9k_e::=${${_p9k__'${_p9k_line_index}r${${1#prompt_}%%[A-Z_]#}'+00}:-' if (( has_icon == -1 )); then p+='${${(%):-$_p9k_c%1(l.1.0)}[-1]}${${(%):-$_p9k_v%1(l.1.0)}[-1]}}' else @@ -1134,7 +1134,7 @@ prompt_battery() { ;; *) - return + return 0 ;; esac @@ -1411,7 +1411,7 @@ prompt_dir() { [[ -n $_p9k_cache_val[1] ]] || continue parts[1,i]=($_p9k_cache_val[1]) fake_first=1 - return + return 0 done done fi @@ -1844,7 +1844,7 @@ function _p9k_nvm_ls_default() { ;; system|v) _p9k_ret=system - return + return 0 ;; iojs-[0-9]*) v=iojs-v${v#iojs-} @@ -1857,10 +1857,10 @@ function _p9k_nvm_ls_default() { if [[ $v == v*.*.* ]]; then if [[ -x $NVM_DIR/versions/node/$v/bin/node || -x $NVM_DIR/$v/bin/node ]]; then _p9k_ret=$v - return + return 0 elif [[ -x $NVM_DIR/versions/io.js/$v/bin/node ]]; then _p9k_ret=iojs-$v - return + return 0 else return 1 fi @@ -1999,7 +1999,7 @@ prompt_dotnet_version() { if (( _POWERLEVEL9K_DOTNET_VERSION_PROJECT_ONLY )); then case $_p9k_pwd in - ~|/) return;; + ~|/) return 0;; ~/*) local parent=~/ local parts=(${(s./.)_p9k_pwd#$parent}) @@ -2307,7 +2307,7 @@ prompt_swap() { 'M') (( used_bytes *= 1048576 ));; 'G') (( used_bytes *= 1073741824 ));; 'T') (( used_bytes *= 1099511627776 ));; - *) return;; + *) return 0;; esac else local meminfo && meminfo="$(grep -F 'Swap' /proc/meminfo 2>/dev/null)" || return @@ -3151,7 +3151,7 @@ prompt_kubecontext() { for ((; pos > 0; --pos)); do local line=$cfg[pos] if [[ $line == '- context:' ]]; then - return + return 0 elif [[ $line == (#b)' cluster: '([^\"\'\|\>]*) ]]; then cluster=$match[1] elif [[ $line == (#b)' namespace: '([^\"\'\|\>]*) ]]; then @@ -3462,43 +3462,45 @@ function _p9k_set_prompt() { IFS=$' \t\n\0' _p9k_pwd=${(%):-%/} _p9k_pwd_a=${_p9k_pwd:A} - PROMPT=$_p9k_prompt_prefix_left + PROMPT= RPROMPT= + [[ $1 == instant_ ]] || PROMPT+='${$((_p9k_on_expand()))+}' + PROMPT+=$_p9k_prompt_prefix_left (( _p9k_fetch_iface )) && _p9k_set_iface - local -i left_idx=1 right_idx=1 num_lines=$#_p9k_line_segments_left i - for i in {1..$num_lines}; do + local -i left_idx=1 right_idx=1 num_lines=$#_p9k_line_segments_left + for _p9k_line_index in {1..$num_lines}; do local right= if (( !_POWERLEVEL9K_DISABLE_RPROMPT )); then _p9k_dir= _p9k__prompt= _p9k_segment_index=right_idx _p9k_prompt_side=right - for _p9k_segment_name in ${(@0)_p9k_line_segments_right[i]}; do + for _p9k_segment_name in ${(@0)_p9k_line_segments_right[_p9k_line_index]}; do _p9k_build_${1}segment done _p9k__prompt=${${_p9k__prompt//$' %{\b'/'%{%G'}//$' \b'} right_idx=_p9k_segment_index - if [[ -n $_p9k__prompt || $_p9k_line_never_empty_right[i] == 1 ]]; then - right=$_p9k_line_prefix_right[i]$_p9k__prompt$_p9k_line_suffix_right[i] + if [[ -n $_p9k__prompt || $_p9k_line_never_empty_right[_p9k_line_index] == 1 ]]; then + right=$_p9k_line_prefix_right[_p9k_line_index]$_p9k__prompt$_p9k_line_suffix_right[_p9k_line_index] fi fi unset _p9k_dir - _p9k__prompt=$_p9k_line_prefix_left[i] + _p9k__prompt=$_p9k_line_prefix_left[_p9k_line_index] _p9k_segment_index=left_idx _p9k_prompt_side=left - for _p9k_segment_name in ${(@0)_p9k_line_segments_left[i]}; do + for _p9k_segment_name in ${(@0)_p9k_line_segments_left[_p9k_line_index]}; do _p9k_build_${1}segment done _p9k__prompt=${${_p9k__prompt//$' %{\b'/'%{%G'}//$' \b'} left_idx=_p9k_segment_index - _p9k__prompt+=$_p9k_line_suffix_left[i] - if (( $+_p9k_dir || (i != num_lines && $#right) )); then - _p9k__prompt='${${:-${_p9k_d::=0}${_p9k_rprompt::=${__p9k_x_right-'$right'}}${_p9k_lprompt::='$_p9k__prompt'}}+}' + _p9k__prompt+=$_p9k_line_suffix_left[_p9k_line_index] + if (( $+_p9k_dir || (_p9k_line_index != num_lines && $#right) )); then + _p9k__prompt='${${:-${_p9k_d::=0}${_p9k_rprompt::='$right'}${_p9k_lprompt::='$_p9k__prompt'}}+}' _p9k__prompt+=$_p9k_gap_pre if (( $+_p9k_dir )); then - if (( i == num_lines && (_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS > 0 || _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT > 0) )); then + if (( _p9k_line_index == num_lines && (_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS > 0 || _POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT > 0) )); then local a=$_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS local f=$((0.01*_POWERLEVEL9K_DIR_MIN_COMMAND_COLUMNS_PCT))'*_p9k_clm' _p9k__prompt+="\${\${_p9k_g::=$((($a<$f)*$f+($a>=$f)*$a))}+}" @@ -3523,15 +3525,15 @@ function _p9k_set_prompt() { else _p9k__prompt+='${_p9k_lprompt}' fi - ((i != num_lines && $#right)) && _p9k__prompt+=$_p9k_line_gap_post[i] + ((_p9k_line_index != num_lines && $#right)) && _p9k__prompt+=$_p9k_line_gap_post[_p9k_line_index] fi - if (( i == num_lines )); then - [[ -n $right ]] && RPROMPT='${__p9k_x_right-'$_p9k_prompt_prefix_right$right$_p9k_prompt_suffix_right'}' - _p9k__prompt+=$_p9k_prompt_suffix_left + if (( _p9k_line_index == num_lines )); then + [[ -n $right ]] && RPROMPT=$_p9k_prompt_prefix_right$right$_p9k_prompt_suffix_right + _p9k__prompt='${_p9k__'$_p9k_line_index'-'$_p9k__prompt'}'$_p9k_prompt_suffix_left [[ $1 == instant_ ]] || PROMPT+=$_p9k__prompt else - PROMPT+=$_p9k__prompt - [[ -n $right ]] || PROMPT+=$'\n' + [[ -n $right ]] || _p9k__prompt+=$'\n' + PROMPT+='${_p9k__'$_p9k_line_index'-'$_p9k__prompt'}' fi done @@ -3567,6 +3569,11 @@ _p9k_dump_instant_prompt() { sysopen -a -o creat,trunc -u fd $tmp || return { [[ $TERM_PROGRAM == Hyper ]] && local hyper='==' || local hyper='!=' + local -a display_v=("${_p9k__display_v[@]}") + local -i i + for ((i = 6; i <= $#display_v; i+=2)); do display_v[i]=show; done + display_v[2]=hide + display_v[4]=hide >&$fd print -r -- "() { emulate -L zsh (( ! \$+__p9k_instant_prompt_disabled )) || return @@ -3596,9 +3603,70 @@ _p9k_dump_instant_prompt() { { content="$(<$prompt_file)" } 2>/dev/null || return local tail=${content##*$rs$key$us} [[ ${#tail} != ${#content} ]] || return + local P9K_PROMPT=instant + if (( ! $+P9K_TTY )); then' + if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then + >&$fd print -r -- ' typeset -gx P9K_TTY=new' + else + >&$fd print -r -- ' + typeset -gx P9K_TTY=old + zmodload -F zsh/stat b:zstat + zmodload zsh/datetime + local -a stat + if zstat -A stat +ctime -- $TTY 2>/dev/null && + (( EPOCHREALTIME - stat[1] < '$_POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS' )); then + P9K_TTY=new + fi' + fi + >&$fd print -r -- ' fi + local -i _p9k__empty_line_i=3 _p9k__ruler_i=3 + local -A _p9k__display_k=('${(j: :)${(@q)${(kv)_p9k__display_k}}}') + local -a _p9k__display_v=('${(j: :)${(@q)display_v}}') + function p10k() { + emulate -L zsh + setopt no_hist_expand extended_glob prompt_percent prompt_subst no_aliases + [[ $1 == display ]] || return + shift + local opt match MATCH prev new pair list name var + local -i k + for opt; do + pair=(${(s:=:)opt}) + list=(${(s:,:)${pair[2]}}) + for k in ${(u@)_p9k__display_k[(I)$pair[1]]:/(#m)*/$_p9k__display_k[$MATCH]}; do + if (( $#list == 1 )); then + [[ $_p9k__display_v[k+1] == $list[1] ]] && continue + new=$list[1] + else + new=${list[list[(I)$_p9k__display_v[k+1]]+1]:-$list[1]} + [[ $_p9k__display_v[k+1] == $new ]] && continue + fi + _p9k__display_v[k+1]=$new + name=$_p9k__display_v[k] + if [[ $name == (empty_line|ruler) ]]; then + var=_p9k__${name}_i + [[ $new == hide ]] && typeset -gi $var=3 || unset $var + elif [[ $name == (#b)(<->)(*) ]]; then + var=_p9k__${match[1]}${${${${match[2]//\/}/#left/l}/#right/r}/#gap/g} + [[ $new == hide ]] && typeset -g $var= || unset $var + fi + done + done + }' + if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE )); then + >&$fd print -r -- ' [[ $P9K_TTY == old ]] && { unset _p9k__empty_line_i; _p9k__display_v[2]=print }' + fi + if (( _POWERLEVEL9K_SHOW_RULER )); then + >&$fd print -r -- '[[ $P9K_TTY == old ]] && { unset _p9k__ruler_i; _p9k__display_v[4]=print }' + fi + if (( $+functions[p10k-on-pre-prompt] )); then + >&$fd print -r -- ' + p10k-on-pre-prompt() { '$functions[p10k-on-pre-prompt]' } + p10k-on-pre-prompt + unfunction p10k-on-pre-prompt' + fi + >&$fd print -r -- ' + trap "unset -m _p9k__\*; unfunction p10k" EXIT local -a _p9k_t=("${(@ps:$us:)${tail%%$rs*}}")' - (( __p9k_ksh_arrays )) && >&$fd print -r -- ' setopt ksh_arrays' - (( __p9k_sh_glob )) && >&$fd print -r -- ' setopt sh_glob' if [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]]; then if [[ $TERM_PROGRAM == Hyper ]]; then local bad_lines=40 bad_columns=100 @@ -3610,15 +3678,14 @@ _p9k_dump_instant_prompt() { zmodload -F zsh/stat b:zstat zmodload zsh/datetime local -a tty_ctime - if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( $tty_ctime[1] + 2 > EPOCHREALTIME )); then + if ! zstat -A tty_ctime +ctime -- $TTY 2>/dev/null || (( tty_ctime[1] + 2 > EPOCHREALTIME )); then zmodload zsh/datetime 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 - local __p9k_x_ruler= - local __p9k_x_gap= - local __p9k_x_right= + (( $+_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 @@ -3631,6 +3698,8 @@ _p9k_dump_instant_prompt() { 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]}")' (( __p9k_ksh_arrays )) && >&$fd print -r -- ' unsetopt ksh_arrays' (( __p9k_sh_glob )) && >&$fd print -r -- ' unsetopt sh_glob' @@ -3654,7 +3723,7 @@ _p9k_dump_instant_prompt() { _p9k_ret=$x } local out' - [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && >&$fd print -r -- ' if (( ! $+__p9k_x_gap )); then' + [[ $+VTE_VERSION == 1 || $TERM_PROGRAM == Hyper ]] && >&$fd print -r -- ' if (( ! $+_p9k__g )); then' >&$fd print -r -- ' [[ $PROMPT_EOL_MARK == "%B%S%#%s%b" ]] && _p9k_ret=1 || _p9k_prompt_length $PROMPT_EOL_MARK local -i fill=$((COLUMNS > _p9k_ret ? COLUMNS - _p9k_ret : 0)) @@ -3838,113 +3907,222 @@ function _p9k_restore_state() { } function _p9k_clear_instant_prompt() { - (( $+__p9k_instant_prompt_active )) || return 0 + if (( $+__p9k_fd_0 )); then + exec 0<&$__p9k_fd_0 {__p9k_fd_0}>&- + unset __p9k_fd_0 + fi + exec 1>&$__p9k_fd_1 2>&$__p9k_fd_2 {__p9k_fd_1}>&- {__p9k_fd_2}>&- + unset __p9k_fd_1 __p9k_fd_2 + if [[ -s $__p9k_instant_prompt_output ]]; then + { + local content + [[ $_POWERLEVEL9K_INSTANT_PROMPT == verbose ]] && content="$(<$__p9k_instant_prompt_output)" + local mark="${PROMPT_EOL_MARK-%B%S%#%s%b}" + _p9k_prompt_length $mark + local -i fill=$((COLUMNS > _p9k_ret ? COLUMNS - _p9k_ret : 0)) + local sp="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}" + print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed] + if [[ -n ${(S)content//$'\e'*$'\a'} ]]; then + echo -E - "" + echo -E - "${(%):-[%3FWARNING%f]: Console output during zsh initialization detected.}" + echo -E - "" + echo -E - "${(%):-When using Powerlevel10k with instant prompt, console output during zsh}" + echo -E - "${(%):-initialization may indicate issues.}" + echo -E - "" + echo -E - "${(%):-You can:}" + echo -E - "" + echo -E - "${(%):- - %BRecommended%b: Change %B$__p9k_zshrc_u%b so that it does not perform console I/O}" + echo -E - "${(%):- after the instant prompt preamble. See the link below for details.}" + echo -E - "" + echo -E - "${(%):- * You %Bwill not%b see this error message again.}" + echo -E - "${(%):- * Zsh will start %Bquickly%b and prompt will update %Bsmoothly%b.}" + echo -E - "" + echo -E - "${(%):- - Suppress this warning either by running %Bp10k configure%b or by manually}" + echo -E - "${(%):- defining the following parameter:}" + echo -E - "" + echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=quiet}" + echo -E - "" + echo -E - "${(%):- * You %Bwill not%b see this error message again.}" + echo -E - "${(%):- * Zsh will start %Bquickly%b but prompt will %Bjump down%b after initialization.}" + echo -E - "" + echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}" + echo -E - "${(%):- defining the following parameter:}" + echo -E - "" + echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}" + echo -E - "" + echo -E - "${(%):- * You %Bwill not%b see this error message again.}" + echo -E - "${(%):- * Zsh will start %Bslowly%b.}" + echo -E - "" + echo -E - "${(%):- - Do nothing.}" + echo -E - "" + echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}" + echo -E - "${(%):- * Zsh will start %Bquickly%b but prompt will %Bjump down%b after initialization.}" + echo -E - "" + echo -E - "${(%):-For details, see:}" + echo - "${(%):-\e]8;;https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt\ahttps://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt\e]8;;\a}" + echo -E - "" + echo - "${(%):-%3F-- console output produced during zsh initialization follows --%f}" + echo -E - "" + fi + cat $__p9k_instant_prompt_output + echo -nE - $sp + zf_rm -f -- $__p9k_instant_prompt_output + } 2>/dev/null + else + zf_rm -f -- $__p9k_instant_prompt_output 2>/dev/null + print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed] + fi + prompt_opts=(percent subst sp cr) + if [[ $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT == 0 && -o prompt_cr ]]; then + >&2 echo -E - "" + >&2 echo -E - "${(%):-[%1FERROR%f]: When using Powerlevel10k with instant prompt, %Bprompt_cr%b must be unset.}" + >&2 echo -E - "" + >&2 echo -E - "${(%):-You can:}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- - %BRecommended%b: call %Bp10k finalize%b at the end of %B$__p9k_zshrc_u%b.}" + >&2 echo -E - "${(%):- You can do this by running the following command:}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- %2Fecho%f %3F'(( ! \${+functions[p10k]\} )) || p10k finalize'%f >>! $__p9k_zshrc_u}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" + >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b and %Bwithout%b prompt flickering.}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- - Find where %Bprompt_cr%b option gets sets in your zsh configs and stop setting it.}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" + >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b and %Bwithout%b prompt flickering.}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}" + >&2 echo -E - "${(%):- defining the following parameter:}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" + >&2 echo -E - "${(%):- * Zsh will start %Bslowly%b.}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- - Do nothing.}" + >&2 echo -E - "" + >&2 echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}" + >&2 echo -E - "${(%):- * Zsh will start %Bquckly%b but %Bwith%b prompt flickering.}" + >&2 echo -E - "" + fi +} + +function _p9k_maybe_dump() { + (( __p9k_dumps_enabled )) || return 0 + + _p9k__instant_prompt_sig=$_p9k_pwd:$P9K_SSH:${(%):-%#} + + if (( ! _p9k__dump_pid )) || ! kill -0 $_p9k__dump_pid 2>/dev/null; then + _p9k__dump_pid=0 + if (( _p9k__prompt_idx == 1 )) then + (( _p9k__instant_prompt_disabled )) || _p9k_set_instant_prompt + if (( !_p9k_state_restored )); then + if (( !_p9k__instant_prompt_disabled )); then + _p9k_dump_instant_prompt + _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 + fi + _p9k_dump_state + _p9k__state_dump_scheduled=0 + elif [[ $_p9k__instant_prompt_disabled == 0 && + "${(pj:\x1f:)__p9k_used_instant_prompt}" != "${(e)_p9k_instant_prompt}" ]]; then + _p9k_dump_instant_prompt + if (( ! $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig] )); then + _p9k_dump_state + _p9k__state_dump_scheduled=0 + _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 + fi + fi + elif (( _p9k__state_dump_scheduled || ! (_p9k__instant_prompt_disabled || $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]) )); then + setopt no_bg_nice + ( + if ! (( _p9k__instant_prompt_disabled || $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig] )); then + _p9k_set_instant_prompt + _p9k_dump_instant_prompt + _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 + fi + _p9k_dump_state + ) &! + _p9k__dump_pid=$! + _p9k__state_dump_scheduled=0 + (( _p9k__instant_prompt_disabled )) || _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 + fi + fi +} + +function _p9k_on_expand() { + (( _p9k__expanded && ! $+__p9k_instant_prompt_active )) && return + () { emulate -L zsh - if (( $+__p9k_fd_0 )); then - exec 0<&$__p9k_fd_0 {__p9k_fd_0}>&- - unset __p9k_fd_0 - fi - exec 1>&$__p9k_fd_1 2>&$__p9k_fd_2 {__p9k_fd_1}>&- {__p9k_fd_2}>&- - unset __p9k_fd_1 __p9k_fd_2 __p9k_instant_prompt_active - if [[ -s $__p9k_instant_prompt_output ]]; then - { - local content - [[ $_POWERLEVEL9K_INSTANT_PROMPT == verbose ]] && content="$(<$__p9k_instant_prompt_output)" - local mark="${PROMPT_EOL_MARK-%B%S%#%s%b}" - _p9k_prompt_length $mark - local -i fill=$((COLUMNS > _p9k_ret ? COLUMNS - _p9k_ret : 0)) - local sp="${(%):-%b%k%f%s%u$mark${(pl.$fill.. .)}$cr%b%k%f%s%u%E}" - print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed] - if [[ -n ${(S)content//$'\e'*$'\a'} ]]; then - echo -E - "" - echo -E - "${(%):-[%3FWARNING%f]: Console output during zsh initialization detected.}" - echo -E - "" - echo -E - "${(%):-When using Powerlevel10k with instant prompt, console output during zsh}" - echo -E - "${(%):-initialization may indicate issues.}" - echo -E - "" - echo -E - "${(%):-You can:}" - echo -E - "" - echo -E - "${(%):- - %BRecommended%b: Change %B$__p9k_zshrc_u%b so that it does not perform console I/O}" - echo -E - "${(%):- after the instant prompt preamble. See the link below for details.}" - echo -E - "" - echo -E - "${(%):- * You %Bwill not%b see this error message again.}" - echo -E - "${(%):- * Zsh will start %Bquickly%b and prompt will update %Bsmoothly%b.}" - echo -E - "" - echo -E - "${(%):- - Suppress this warning either by running %Bp10k configure%b or by manually}" - echo -E - "${(%):- defining the following parameter:}" - echo -E - "" - echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=quiet}" - echo -E - "" - echo -E - "${(%):- * You %Bwill not%b see this error message again.}" - echo -E - "${(%):- * Zsh will start %Bquickly%b but prompt will %Bjump down%b after initialization.}" - echo -E - "" - echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}" - echo -E - "${(%):- defining the following parameter:}" - echo -E - "" - echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}" - echo -E - "" - echo -E - "${(%):- * You %Bwill not%b see this error message again.}" - echo -E - "${(%):- * Zsh will start %Bslowly%b.}" - echo -E - "" - echo -E - "${(%):- - Do nothing.}" - echo -E - "" - echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}" - echo -E - "${(%):- * Zsh will start %Bquickly%b but prompt will %Bjump down%b after initialization.}" - echo -E - "" - echo -E - "${(%):-For details, see:}" - echo - "${(%):-\e]8;;https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt\ahttps://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt\e]8;;\a}" - echo -E - "" - echo - "${(%):-%3F-- console output produced during zsh initialization follows --%f}" - echo -E - "" + setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} no_aliases + + _p9k_maybe_dump + (( $+__p9k_instant_prompt_active )) && _p9k_clear_instant_prompt + + (( _p9k__expanded )) && return + _p9k__expanded=1 + + if (( ! $+P9K_TTY )); then + typeset -gx P9K_TTY=old + if (( _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS < 0 )); then + P9K_TTY=new + else + local -a stat + if zstat -A stat +ctime -- $TTY 2>/dev/null && + (( EPOCHREALTIME - stat[1] < _POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS )); then + P9K_TTY=new fi - cat $__p9k_instant_prompt_output - echo -nE - $sp - zf_rm -f -- $__p9k_instant_prompt_output - } 2>/dev/null - else - zf_rm -f -- $__p9k_instant_prompt_output 2>/dev/null - print -rn -- $terminfo[rc]${(%):-%b%k%f%s%u}$terminfo[ed] + fi + fi + + __p9k_reset_state=1 + + if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE )); then + _p9k__empty_line_i=3 + if [[ $P9K_TTY == new ]]; then + _p9k__display_v[2]=hide + else + _p9k__display_v[2]=print + fi + fi + + if (( _POWERLEVEL9K_SHOW_RULER )); then + _p9k__ruler_i=3 + if [[ $P9K_TTY == new ]]; then + _p9k__display_v[4]=hide + else + _p9k__display_v[4]=print + fi + fi + + typeset -g P9K_PROMPT=regular + + if (( $+functions[p10k-on-pre-prompt] )); then + p10k-on-pre-prompt fi - prompt_opts=(percent subst sp cr) - if [[ $_POWERLEVEL9K_DISABLE_INSTANT_PROMPT == 0 && -o prompt_cr ]]; then - >&2 echo -E - "" - >&2 echo -E - "${(%):-[%1FERROR%f]: When using Powerlevel10k with instant prompt, %Bprompt_cr%b must be unset.}" - >&2 echo -E - "" - >&2 echo -E - "${(%):-You can:}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- - %BRecommended%b: call %Bp10k finalize%b at the end of %B$__p9k_zshrc_u%b.}" - >&2 echo -E - "${(%):- You can do this by running the following command:}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- %2Fecho%f %3F'(( ! \${+functions[p10k]\} )) || p10k finalize'%f >>! $__p9k_zshrc_u}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" - >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b and %Bwithout%b prompt flickering.}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- - Find where %Bprompt_cr%b option gets sets in your zsh configs and stop setting it.}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" - >&2 echo -E - "${(%):- * Zsh will start %Bquickly%b and %Bwithout%b prompt flickering.}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- - Disable instant prompt either by running %Bp10k configure%b or by manually}" - >&2 echo -E - "${(%):- defining the following parameter:}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- %3Ftypeset%f -g POWERLEVEL9K_INSTANT_PROMPT=off}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" - >&2 echo -E - "${(%):- * Zsh will start %Bslowly%b.}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- - Do nothing.}" - >&2 echo -E - "" - >&2 echo -E - "${(%):- * You %Bwill%b see this error message every time you start zsh.}" - >&2 echo -E - "${(%):- * Zsh will start %Bquckly%b but %Bwith%b prompt flickering.}" - >&2 echo -E - "" + + __p9k_reset_state=0 + P9K_TTY=old + + [[ $_p9k__display_v[2] == print ]] && print -rn -- $_p9k_t[_p9k_empty_line_idx] + if [[ $_p9k__display_v[4] == print ]]; then + local ruler=$_p9k_t[_p9k_ruler_idx] + () { + (( __p9k_ksh_arrays )) && setopt ksh_arrays + (( __p9k_sh_glob )) && setopt sh_glob + print -rP -- $ruler + } fi } - unsetopt localoptions - setopt prompt_sp prompt_cr + if (( $+__p9k_instant_prompt_active )); then + unset __p9k_instant_prompt_active + unsetopt localoptions + setopt prompt_sp prompt_cr + fi } +functions -M _p9k_on_expand _p9k_precmd_impl() { emulate -L zsh @@ -3956,13 +4134,9 @@ _p9k_precmd_impl() { if zle; then __p9k_new_status=0 __p9k_new_pipestatus=(0) + _p9k__expanded=1 else - print -rn "${_p9k_prompt_newline:-}" - fi - - if (( _p9k__transient_rprompt_active )); then - _p9k__transient_rprompt_active=0 - unset __p9k_x_right __p9k_x_gap + _p9k__expanded=0 fi if (( $+_p9k_real_zle_rprompt_indent )); then @@ -4032,50 +4206,13 @@ _p9k_precmd_impl() { if [[ $precmd_functions[-1] != _p9k_precmd && $precmd_functions[(I)_p9k_precmd] != 0 ]]; then precmd_functions=(${(@)precmd_functions:#_p9k_precmd} _p9k_precmd) fi +} - if (( $+__p9k_instant_prompt_active )); then - functions -M _p9k_clear_instant_prompt - PROMPT+='${$((_p9k_clear_instant_prompt()))+}' - fi - - (( __p9k_dumps_enabled )) || return 0 - - _p9k__instant_prompt_sig=$_p9k_pwd:$P9K_SSH:${(%):-%#} - - if (( ! _p9k__dump_pid )) || ! kill -0 $_p9k__dump_pid 2>/dev/null; then - _p9k__dump_pid=0 - if (( _p9k__prompt_idx == 1 )) then - (( _p9k__instant_prompt_disabled )) || _p9k_set_instant_prompt - if (( !_p9k_state_restored )); then - if (( !_p9k__instant_prompt_disabled )); then - _p9k_dump_instant_prompt - _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 - fi - _p9k_dump_state - _p9k__state_dump_scheduled=0 - elif [[ $_p9k__instant_prompt_disabled == 0 && - "${(pj:\x1f:)__p9k_used_instant_prompt}" != "${(e)_p9k_instant_prompt}" ]]; then - _p9k_dump_instant_prompt - if (( ! $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig] )); then - _p9k_dump_state - _p9k__state_dump_scheduled=0 - _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 - fi - fi - elif (( _p9k__state_dump_scheduled || ! (_p9k__instant_prompt_disabled || $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]) )); then - setopt no_bg_nice - ( - if ! (( _p9k__instant_prompt_disabled || $+_p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig] )); then - _p9k_set_instant_prompt - _p9k_dump_instant_prompt - _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 - fi - _p9k_dump_state - ) &! - _p9k__dump_pid=$! - _p9k__state_dump_scheduled=0 - (( _p9k__instant_prompt_disabled )) || _p9k_dumped_instant_prompt_sigs[$_p9k__instant_prompt_sig]=1 - fi +_p9k_trapint() { + if (( __p9k_enabled )); then + emulate -L zsh + setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} + _p9k_zle_line_finish fi } @@ -4085,16 +4222,23 @@ _p9k_precmd() { [[ -o ksh_arrays ]] && __p9k_ksh_arrays=1 || __p9k_ksh_arrays=0 [[ -o sh_glob ]] && __p9k_sh_glob=1 || __p9k_sh_glob=0 + _p9k_precmd_impl + unsetopt localoptions setopt nopromptbang prompt_percent prompt_subst - _p9k_precmd_impl + if (( ! $+functions[TRAPINT] )); then + trap '_p9k_trapint; return 130' INT + fi } function _p9k_reset_prompt() { - (( __p9k_ksh_arrays )) && setopt ksh_arrays - (( __p9k_sh_glob )) && setopt sh_glob - zle && zle .reset-prompt && zle -R + if zle; then + (( __p9k_ksh_arrays )) && setopt ksh_arrays + (( __p9k_sh_glob )) && setopt sh_glob + zle .reset-prompt + zle -R + fi } function _p9k_zle_keymap_select() { @@ -4137,7 +4281,7 @@ function _p9k_on_async_message() { setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} no_aliases if (( ARGC != 1 )); then _p9k_deinit_async_pump - return + return 0 fi local msg='' IFS='' while read -r -t -u $1 msg; do @@ -4329,6 +4473,7 @@ _p9k_init_vars() { typeset -g _p9k_prompt_side typeset -g _p9k_segment_name typeset -gi _p9k_segment_index + typeset -gi _p9k_line_index typeset -g _p9k_refresh_reason typeset -gi _p9k__region_active typeset -g _p9k__async_pump_line @@ -4357,7 +4502,10 @@ _p9k_init_vars() { typeset -gi _p9k_g typeset -gi _p9k_ind typeset -g _p9k_gap_pre - typeset -g _p9k_prompt_newline + typeset -gi _p9k__ruler_i=3 + typeset -gi _p9k_ruler_idx + typeset -gi _p9k__empty_line_i=3 + typeset -gi _p9k_empty_line_idx typeset -g _p9k_prompt_prefix_left typeset -g _p9k_prompt_prefix_right typeset -g _p9k_prompt_suffix_left @@ -4386,10 +4534,12 @@ _p9k_init_vars() { typeset -g _p9k_uname typeset -g _p9k_uname_o typeset -g _p9k_uname_m + typeset -gA _p9k__display_k + typeset -ga _p9k__display_v - typeset -gi _p9k__transient_rprompt_active typeset -gA _p9k__dotnet_stat_cache typeset -gA _p9k__dir_stat_cache + typeset -gi _p9k__expanded typeset -g P9K_VISUAL_IDENTIFIER typeset -g P9K_CONTENT @@ -4411,6 +4561,7 @@ _p9k_init_params() { fi fi + _p9k_declare -F POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS 5 _p9k_declare -i POWERLEVEL9K_INSTANT_PROMPT_COMMAND_LINES 3 _p9k_declare -a POWERLEVEL9K_LEFT_PROMPT_ELEMENTS -- context dir vcs _p9k_declare -a POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS -- status root_indicator background_jobs history time @@ -4650,6 +4801,7 @@ _p9k_init_params() { # These correspond to `java -fullversion` and `java -version` respectively. _p9k_declare -b POWERLEVEL9K_JAVA_VERSION_FULL 1 _p9k_declare -b POWERLEVEL9K_PROMPT_CHAR_OVERWRITE_STATE 0 + _p9k_declare -F POWERLEVEL9K_NEW_TTY_MAX_AGE_SECONDS local -i i=1 while (( i <= $#_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS )); do @@ -4690,30 +4842,35 @@ _p9k_wrap_zle_widget() { zle -N $orig ${widgets[$widget]#user:} ;; builtin) - eval "_p9k_orig_${(q)widget}() { zle .${(q)widget} }" + functions[_p9k_orig_$widget]="zle .${(q)widget}" zle -N $orig _p9k_orig_$widget ;; esac local wrapper=_p9k_wrapper_$widget_$hook - eval "function ${(q)wrapper}() { + functions[$wrapper]=" emulate -L zsh setopt no_hist_expand extended_glob no_prompt_bang prompt_{percent,subst} (( __p9k_enabled )) && ${(q)hook} \"\$@\" - (( \$+widgets[${(q)orig}] )) && zle ${(q)orig} -- \"\$@\" - }" + (( \$+widgets[${(q)orig}] )) && zle ${(q)orig} -- \"\$@\"" zle -N -- $widget $wrapper } function _p9k_zle_line_finish() { _p9k__line_finished= - if [[ -o transient_rprompt ]]; then - __p9k_x_right= - __p9k_x_gap= - _p9k__transient_rprompt_active=1 - _p9k_reset_prompt - elif (( _p9k_reset_on_line_finish )); then + local -i reset=_p9k_reset_on_line_finish + + if (( $+functions[p10k-on-post-prompt] )); then + __p9k_reset_state=1 + p10k-on-post-prompt + if (( __p9k_reset_state == 2 )); then + reset=1 + fi + __p9k_reset_state=0 + fi + + if (( reset )); then _p9k_reset_prompt fi } @@ -4729,36 +4886,39 @@ function _p9k_zle_line_pre_redraw() { prompt__p9k_internal_nothing() { _p9k__prompt+='${_p9k_sss::=}'; } instant_prompt__p9k_internal_nothing() { prompt__p9k_internal_nothing; } -# _p9k_build_gap_post <first|newline> +# _p9k_build_gap_post line_number _p9k_build_gap_post() { - _p9k_get_icon '' MULTILINE_${(U)1}_PROMPT_GAP_CHAR + [[ $1 == 1 ]] && local kind=first || local kind=newline + _p9k_get_icon '' MULTILINE_${(U)kind}_PROMPT_GAP_CHAR local char=${_p9k_ret:- } _p9k_prompt_length $char if (( _p9k_ret != 1 || $#char != 1 )); then - print -rP -- "%F{red}WARNING!%f %BMULTILINE_${(U)1}_PROMPT_GAP_CHAR%b is not one character long. Will use ' '." - print -rP -- "Either change the value of %BPOWERLEVEL9K_MULTILINE_${(U)1}_PROMPT_GAP_CHAR%b or remove it." + print -rP -- "%F{red}WARNING!%f %BMULTILINE_${(U)kind}_PROMPT_GAP_CHAR%b is not one character long. Will use ' '." + print -rP -- "Either change the value of %BPOWERLEVEL9K_MULTILINE_${(U)kind}_PROMPT_GAP_CHAR%b or remove it." char=' ' fi local style - _p9k_color prompt_multiline_$1_prompt_gap BACKGROUND "" + _p9k_color prompt_multiline_${kind}_prompt_gap BACKGROUND "" [[ -n $_p9k_ret ]] && _p9k_background $_p9k_ret style+=$_p9k_ret - _p9k_color prompt_multiline_$1_prompt_gap FOREGROUND "" + _p9k_color prompt_multiline_${kind}_prompt_gap FOREGROUND "" [[ -n $_p9k_ret ]] && _p9k_foreground $_p9k_ret style+=$_p9k_ret _p9k_escape_style $style style=$_p9k_ret - local exp=POWERLEVEL9K_MULTILINE_${(U)1}_PROMPT_GAP_EXPANSION + local exp=POWERLEVEL9K_MULTILINE_${(U)kind}_PROMPT_GAP_EXPANSION (( $+parameters[$exp] )) && exp=${(P)exp} || exp='${P9K_GAP}' [[ $char == '.' ]] && local s=',' || local s='.' - _p9k_ret=$'${${__p9k_x_gap+\n}:-'$style'${${${_p9k_m:#-*}:+' + _p9k_ret=$'${${_p9k__g+\n}:-'$style'${${${_p9k_m:#-*}:+' + _p9k_ret+='${${_p9k__'$1'g+${(pl.$((_p9k_m+1)).. .)}}:-' if [[ $exp == '${P9K_GAP}' ]]; then - _p9k_ret+='${(pl'$s'$((_p9k_m+1))'$s$s$char$s$')}' + _p9k_ret+='${(pl'$s'$((_p9k_m+1))'$s$s$char$s')}' else - _p9k_ret+='${${P9K_GAP::=${(pl'$s'$((_p9k_m+1))'$s$s$char$s$')}}+}' + _p9k_ret+='${${P9K_GAP::=${(pl'$s'$((_p9k_m+1))'$s$s$char$s')}}+}' _p9k_ret+='${:-"'$exp'"}' style=1 fi + _p9k_ret+='}' if (( __p9k_ksh_arrays )); then _p9k_ret+=$'$_p9k_rprompt${_p9k_t[$((!_p9k_ind))]}}:-\n}' else @@ -4791,7 +4951,8 @@ _p9k_init_lines() { local -i num_lines=num_left_lines fi - repeat $num_lines; do + local -i i + for i in {1..$num_lines}; do local -i left_end=${left_segments[(i)newline]} local -i right_end=${right_segments[(i)newline]} _p9k_line_segments_left+="${(pj:\0:)left_segments[1,left_end-1]}" @@ -4802,13 +4963,13 @@ _p9k_init_lines() { _p9k_get_icon '' LEFT_SEGMENT_SEPARATOR _p9k_get_icon 'prompt_empty_line' LEFT_PROMPT_LAST_SEGMENT_END_SYMBOL $_p9k_ret _p9k_escape $_p9k_ret - _p9k_line_prefix_left+='${${:-${_p9k_bg::=NONE}${_p9k_i::=0}${_p9k_sss::=%f'$_p9k_ret'}}+}' + _p9k_line_prefix_left+='${_p9k__'$i'l-${${:-${_p9k_bg::=NONE}${_p9k_i::=0}${_p9k_sss::=%f'$_p9k_ret'}}+}' _p9k_line_suffix_left+='%b%k$_p9k_sss%b%k%f' _p9k_escape ${(g::)POWERLEVEL9K_EMPTY_LINE_RIGHT_PROMPT_FIRST_SEGMENT_START_SYMBOL} [[ -n $_p9k_ret ]] && _p9k_line_never_empty_right+=1 || _p9k_line_never_empty_right+=0 - _p9k_line_prefix_right+='${${:-${_p9k_bg::=NONE}${_p9k_i::=0}${_p9k_sss::='$_p9k_ret'}}+}' - _p9k_line_suffix_right+='$_p9k_sss%b%k%f' # gets overridden for _p9k_emulate_zero_rprompt_indent + _p9k_line_prefix_right+='${_p9k__'$i'r-${${:-${_p9k_bg::=NONE}${_p9k_i::=0}${_p9k_sss::='$_p9k_ret'}}+}' + _p9k_line_suffix_right+='$_p9k_sss%b%k%f}' # gets overridden for _p9k_emulate_zero_rprompt_indent done _p9k_get_icon '' LEFT_SEGMENT_END_SEPARATOR @@ -4823,15 +4984,19 @@ _p9k_init_lines() { fi fi + for i in {1..$num_lines}; do _p9k_line_suffix_left[i]+='}'; done + if (( num_lines > 1 )); then - _p9k_build_gap_post first - _p9k_line_gap_post[1]=$_p9k_ret + for i in {1..$((num_lines-1))}; do + _p9k_build_gap_post $i + _p9k_line_gap_post+=$_p9k_ret + done if [[ $+POWERLEVEL9K_MULTILINE_FIRST_PROMPT_PREFIX == 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE == 1 ]]; then _p9k_get_icon '' MULTILINE_FIRST_PROMPT_PREFIX [[ _p9k_ret == *%* ]] && _p9k_ret+=%b%k%f # Not escaped for historical reasons. - _p9k_ret='${:-"'$_p9k_ret'"}' + _p9k_ret='${_p9k__1l_frame-"'$_p9k_ret'"}' _p9k_line_prefix_left[1]=$_p9k_ret$_p9k_line_prefix_left[1] fi @@ -4839,43 +5004,40 @@ _p9k_init_lines() { _p9k_get_icon '' MULTILINE_LAST_PROMPT_PREFIX [[ _p9k_ret == *%* ]] && _p9k_ret+=%b%k%f # Not escaped for historical reasons. - _p9k_ret='${:-"'$_p9k_ret'"}' + _p9k_ret='${_p9k__'$num_lines'l_frame-"'$_p9k_ret'"}' _p9k_line_prefix_left[-1]=$_p9k_ret$_p9k_line_prefix_left[-1] fi _p9k_get_icon '' MULTILINE_FIRST_PROMPT_SUFFIX if [[ -n $_p9k_ret ]]; then [[ _p9k_ret == *%* ]] && _p9k_ret+=%b%k%f - _p9k_escape $_p9k_ret - _p9k_line_suffix_right[1]+=$_p9k_ret + _p9k_line_suffix_right[1]+='${_p9k__1r_frame-'${(qqq)_p9k_ret}'}' _p9k_line_never_empty_right[1]=1 fi _p9k_get_icon '' MULTILINE_LAST_PROMPT_SUFFIX if [[ -n $_p9k_ret ]]; then [[ _p9k_ret == *%* ]] && _p9k_ret+=%b%k%f - _p9k_escape $_p9k_ret - _p9k_line_suffix_right[-1]+=$_p9k_ret + _p9k_line_suffix_right[-1]+='${_p9k__'$num_lines'r_frame-'${(qqq)_p9k_ret}'}' _p9k_line_never_empty_right[-1]=1 fi if (( num_lines > 2 )); then - _p9k_build_gap_post newline - _p9k_line_gap_post[2,-2]=(${${:-{3..num_lines}}:/*/$_p9k_ret}) - if [[ $+POWERLEVEL9K_MULTILINE_NEWLINE_PROMPT_PREFIX == 1 || $_POWERLEVEL9K_PROMPT_ON_NEWLINE == 1 ]]; then _p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_PREFIX [[ _p9k_ret == *%* ]] && _p9k_ret+=%b%k%f - # Not escaped for historical reasons. - _p9k_ret='${:-"'$_p9k_ret'"}' - _p9k_line_prefix_left[2,-2]=$_p9k_ret${^_p9k_line_prefix_left[2,-2]} + for i in {2..$((num_lines-1))}; do + # Not escaped for historical reasons. + _p9k_line_prefix_left[i]='${_p9k__'$i'l_frame-"'$_p9k_ret'"}'$_p9k_line_prefix_left[i] + done fi _p9k_get_icon '' MULTILINE_NEWLINE_PROMPT_SUFFIX if [[ -n $_p9k_ret ]]; then [[ _p9k_ret == *%* ]] && _p9k_ret+=%b%k%f - _p9k_escape $_p9k_ret - _p9k_line_suffix_right[2,-2]=${^_p9k_line_suffix_right[2,-2]}$_p9k_ret + for i in {2..$((num_lines-1))}; do + _p9k_line_suffix_right[i]+='${_p9k__'$i'r_frame-'${(qqq)_p9k_ret}'}' + done _p9k_line_never_empty_right[2,-2]=${(@)_p9k_line_never_empty_right[2,-2]/0/1} fi fi @@ -4889,8 +5051,40 @@ _p9k_all_params_eq() { done } +_p9k_init_display() { + _p9k__display_k=(empty_line 1 ruler 3) + _p9k__display_v=(empty_line hide ruler hide) + local -i n=3 i + local name + for i in {1..$#_p9k_line_segments_left}; do + local -i j=$((-$#_p9k_line_segments_left+i-1)) + _p9k__display_k+=( + $i $((n+=2)) $j $n + $i/left_frame $((n+=2)) $j/left_frame $n + $i/right_frame $((n+=2)) $j/right_frame $n + $i/left $((n+=2)) $j/left $n + $i/right $((n+=2)) $j/right $n + $i/gap $((n+=2)) $j/gap $n) + _p9k__display_v+=( + $i show + $i/left_frame show + $i/right_frame show + $i/left show + $i/right show + $i/gap show) + for name in ${(@0)_p9k_line_segments_left[i]}; do + _p9k__display_k+=($i/left/$name $((n+=2)) $j/left/$name $n) + _p9k__display_v+=($i/left/$name show) + done + for name in ${(@0)_p9k_line_segments_right[i]}; do + _p9k__display_k+=($i/right/$name $((n+=2)) $j/right/$name $n) + _p9k__display_v+=($i/right/$name show) + done + done +} + _p9k_init_prompt() { - _p9k_t=($'\n' '') + _p9k_t=($'\n' '' '') _p9k_prompt_overflow_bug && _p9k_t[2]='%{%G%}' _p9k_init_lines @@ -4906,9 +5100,9 @@ _p9k_init_prompt() { _p9k_gap_pre+='}+}' _p9k_prompt_prefix_left='${${_p9k_clm::=$COLUMNS}+}${${COLUMNS::=1024}+}' - _p9k_prompt_prefix_right='${${_p9k_clm::=$COLUMNS}+}${${COLUMNS::=1024}+}' + _p9k_prompt_prefix_right='${_p9k__'$#_p9k_line_segments_left'-${${_p9k_clm::=$COLUMNS}+}${${COLUMNS::=1024}+}' _p9k_prompt_suffix_left='${${COLUMNS::=$_p9k_clm}+}' - _p9k_prompt_suffix_right='${${COLUMNS::=$_p9k_clm}+}' + _p9k_prompt_suffix_right='${${COLUMNS::=$_p9k_clm}+}}' if _p9k_segment_in_use vi_mode || _p9k_segment_in_use prompt_char; then _p9k_prompt_prefix_left+='${${_p9k__keymap::=${KEYMAP:-$_p9k__keymap}}+}' @@ -4930,49 +5124,52 @@ _p9k_init_prompt() { ! is-at-least 5.7.2; then _p9k_emulate_zero_rprompt_indent=1 _p9k_prompt_prefix_left+='${${:-${_p9k_real_zle_rprompt_indent:=$ZLE_RPROMPT_INDENT}${ZLE_RPROMPT_INDENT::=1}${_p9k_ind::=0}}+}' - _p9k_line_suffix_right[-1]='${_p9k_sss:+${_p9k_sss% }%E}' + _p9k_line_suffix_right[-1]='${_p9k_sss:+${_p9k_sss% }%E}}' else _p9k_emulate_zero_rprompt_indent=0 _p9k_prompt_prefix_left+='${${_p9k_ind::=${${ZLE_RPROMPT_INDENT:-1}/#-*/0}}+}' fi - if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE )); then - repeat $_POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT _p9k_prompt_newline+=$'\n' + if (( _POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT > 0 )); then + _p9k_t+=${(pl.$_POWERLEVEL9K_PROMPT_ADD_NEWLINE_COUNT..\n.)} + else + _p9k_t+='' + fi + _p9k_empty_line_idx=$#_p9k_t + if (( __p9k_ksh_arrays )); then + _p9k_prompt_prefix_left+='${_p9k_t[${_p9k__empty_line_i:-'$#_p9k_t'}-1]}' + else + _p9k_prompt_prefix_left+='${_p9k_t[${_p9k__empty_line_i:-'$#_p9k_t'}]}' fi - if (( _POWERLEVEL9K_SHOW_RULER )); then - _p9k_get_icon '' RULER_CHAR - local ruler_char=$_p9k_ret - _p9k_prompt_length $ruler_char - if (( _p9k_ret == 1 && $#ruler_char == 1 )); then - _p9k_prompt_prefix_left+=$'${${__p9k_x_ruler+\n}:-' - _p9k_color prompt_ruler BACKGROUND "" - if [[ -z $_p9k_ret && $ruler_char == ' ' ]]; then - _p9k_prompt_prefix_left+=$'\n' - else - _p9k_background $_p9k_ret - _p9k_escape_style $_p9k_ret - _p9k_prompt_prefix_left+=%b$_p9k_ret - _p9k_color prompt_ruler FOREGROUND "" - _p9k_foreground $_p9k_ret - _p9k_escape_style $_p9k_ret - _p9k_prompt_prefix_left+=$_p9k_ret - [[ $ruler_char == '.' ]] && local sep=',' || local sep='.' - local ruler_len='${$((_p9k_clm-_p9k_ind))/#-*/0}' - _p9k_prompt_prefix_left+="\${(pl$sep$ruler_len$sep$sep${(q)ruler_char}$sep)}%k%f" - if (( __p9k_ksh_arrays )); then - _p9k_prompt_prefix_left+='${_p9k_t[$((!_p9k_ind))]}' - else - _p9k_prompt_prefix_left+='${_p9k_t[$((1+!_p9k_ind))]}' - fi - fi - _p9k_prompt_prefix_left+='}' + _p9k_get_icon '' RULER_CHAR + local ruler_char=$_p9k_ret + _p9k_prompt_length $ruler_char + (( _p9k_ret == 1 && $#ruler_char == 1 )) || ruler_char=' ' + _p9k_color prompt_ruler BACKGROUND "" + if [[ -z $_p9k_ret && $ruler_char == ' ' ]]; then + local ruler=$'\n' + else + _p9k_background $_p9k_ret + local ruler=%b$_p9k_ret + _p9k_color prompt_ruler FOREGROUND "" + _p9k_foreground $_p9k_ret + ruler+=$_p9k_ret + [[ $ruler_char == '.' ]] && local sep=',' || local sep='.' + ruler+='${(pl'$sep'${$((_p9k_clm-_p9k_ind))/#-*/0}'$sep$sep$ruler_char$sep')}%k%f' + if (( __p9k_ksh_arrays )); then + ruler+='${_p9k_t[$((!_p9k_ind))]}' else - print -rP -- "%F{red}WARNING!%f %BPOWERLEVEL9K_RULER_CHAR%b is not one character long. Ruler won't be rendered." - print -rP -- "Either change the value of %BPOWERLEVEL9K_RULER_CHAR%b or set %BPOWERLEVEL9K_SHOW_RULER=false%b to" - print -rP -- "disable ruler." + ruler+='${_p9k_t[$((1+!_p9k_ind))]}' fi fi + _p9k_t+=$ruler + _p9k_ruler_idx=$#_p9k_t + if (( __p9k_ksh_arrays )); then + _p9k_prompt_prefix_left+='${(e)_p9k_t[${_p9k__ruler_i:-'$#_p9k_t'}-1]}' + else + _p9k_prompt_prefix_left+='${(e)_p9k_t[${_p9k__ruler_i:-'$#_p9k_t'}]}' + fi if [[ $ITERM_SHELL_INTEGRATION_INSTALLED == Yes ]]; then _p9k_prompt_prefix_left+=$'%{\e]133;A\a%}' @@ -4997,7 +5194,7 @@ _p9k_init_ssh() { typeset -gix P9K_SSH=0 if [[ -n $SSH_CLIENT || -n $SSH_TTY || -n $SSH_CONNECTION ]]; then P9K_SSH=1 - return + return 0 fi # When changing user on a remote system, the $SSH_CONNECTION environment variable can be lost. @@ -5027,8 +5224,9 @@ _p9k_must_init() { _p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1' _p9k__param_pat+=$'$GITSTATUS_ENABLE_LOGGING\1$GITSTATUS_DAEMON\1$GITSTATUS_NUM_THREADS\1' _p9k__param_pat+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays' - _p9k__param_pat+=$'$__p9k_sh_glob\1${options[transient_rprompt]}\1$ITERM_SHELL_INTEGRATION_INSTALLED\1' + _p9k__param_pat+=$'$__p9k_sh_glob\1$ITERM_SHELL_INTEGRATION_INSTALLED\1' _p9k__param_pat+=$'${PROMPT_EOL_MARK-%B%S%#%s%b}\1$LANG\1$LC_ALL\1$LC_CTYPE\1' + _p9k__param_pat+=$'$functions[p10k-on-pre-prompt]\1' local MATCH IFS=$'\1' _p9k__param_pat+="${(@)${(@o)parameters[(I)POWERLEVEL9K_*]}:/(#m)*/\${${(q)MATCH}-$IFS\}}" IFS=$'\2' _p9k__param_sig="${(e)_p9k__param_pat}" @@ -5187,11 +5385,11 @@ _p9k_init_vcs() { _p9k_vcs_info_init if (( $+functions[_p9k_preinit] )); then (( $+GITSTATUS_DAEMON_PID_POWERLEVEL9K )) && gitstatus_start POWERLEVEL9K || _p9k__gitstatus_disabled=1 - return + return 0 fi if (( _POWERLEVEL9K_DISABLE_GITSTATUS )); then _p9k__gitstatus_disabled=1 - return + return 0 fi (( $_POWERLEVEL9K_VCS_BACKENDS[(I)git] )) || return @@ -5228,7 +5426,7 @@ _p9k_init_vcs() { >&2 echo -E - "" >&2 echo -E - "${(%):- * You %Bwill not%b see this error message again.}" >&2 echo -E - "${(%):- * Git prompt will be %Bfast%b.}" - return + return 0 fi local daemon=${GITSTATUS_DAEMON} @@ -5278,6 +5476,8 @@ _p9k_init() { _p9k_init_vars _p9k_restore_state || _p9k_init_cacheable + _p9k_init_display + if _p9k_segment_in_use todo; then local todo=$commands[todo.sh] if [[ -n $todo ]]; then @@ -5295,9 +5495,7 @@ _p9k_init() { fi fi - if (( _p9k_reset_on_line_finish )) || _p9k_segment_in_use status || [[ -o transient_rprompt ]]; then - _p9k_wrap_zle_widget zle-line-finish _p9k_zle_line_finish - fi + _p9k_wrap_zle_widget zle-line-finish _p9k_zle_line_finish if _p9k_segment_in_use vi_mode || _p9k_segment_in_use prompt_char; then _p9k_wrap_zle_widget zle-keymap-select _p9k_zle_keymap_select @@ -5364,7 +5562,7 @@ _p9k_deinit() { (( $+functions[gitstatus_stop] )) && gitstatus_stop POWERLEVEL9K _p9k_deinit_async_pump (( _p9k__dump_pid )) && wait $_p9k__dump_pid 2>/dev/null - unset -m '(_POWERLEVEL9K_|P9K_|_p9k_)*~P9K_SSH' + unset -m '(_POWERLEVEL9K_|P9K_|_p9k_)*~(P9K_SSH|P9K_TTY)' } typeset -gi __p9k_enabled=0 @@ -5519,8 +5717,13 @@ Example: Bind Ctrl+P to toggle right prompt. zle -N toggle-right-prompt bindkey '^P' toggle-right-prompt" +# 0 -- reset-prompt not blocked +# 1 -- reset-prompt blocked and not needed +# 2 -- reset-prompt blocked and needed +typeset -gi __p9k_reset_state + function p10k() { - [[ $# != 1 || $1 != finalize ]] || { p10k-instant-prompt-finalize; return } + [[ $# != 1 || $1 != finalize ]] || { p10k-instant-prompt-finalize; return 0 } emulate -L zsh setopt no_hist_expand extended_glob prompt_percent prompt_subst no_aliases @@ -5574,57 +5777,44 @@ function p10k() { print -rP -- $__p9k_p10k_display_usage >&2 return 1 fi + if [[ $2 == -h ]]; then + print -rP -- $__p9k_p10k_display_usage >&2 + return 0 + fi shift - local opt - local -i reset + local opt match MATCH prev new pair list name var + local -i k for opt; do - case $opt in - -h) print -rP -- $__p9k_p10k_display_usage >&2; return 0;; - +right) - if (( $+__p9k_x_right )); then - reset=1 - unset __p9k_x_right __p9k_x_gap - fi - ;; - -right) - if (( ! $+__p9k_x_right )); then - reset=1 - __p9k_x_gap= - __p9k_x_right= - fi - ;; - right) - reset=1 - if (( $+__p9k_x_right )); then - unset __p9k_x_right __p9k_x_gap - else - typeset -g __p9k_x_right= - typeset -g __p9k_x_gap= - fi - ;; - +s:*) - if (( $+parameters[__p9k_s_${opt:3 }] )); then - reset=1 - unset __p9k_s_${opt:3 } - fi - ;; - -s:*) - if (( ! $+parameters[__p9k_s_${opt:3 }] )); then - reset=1 - typeset -g __p9k_s_${opt:3 }= - fi - ;; - s:*) - reset=1 - if (( $+parameters[__p9k_s_${opt:2 }] )); then - unset __p9k_s_${opt:2 } - else - typeset -g __p9k_s_${opt:2 }= - fi - ;; - esac + pair=(${(s:=:)opt}) + list=(${(s:,:)${pair[2]}}) + for k in ${(u@)_p9k__display_k[(I)$pair[1]]:/(#m)*/$_p9k__display_k[$MATCH]}; do + if (( $#list == 1 )); then # this branch is purely for optimization + [[ $_p9k__display_v[k+1] == $list[1] ]] && continue + new=$list[1] + else + new=${list[list[(I)$_p9k__display_v[k+1]]+1]:-$list[1]} + [[ $_p9k__display_v[k+1] == $new ]] && continue + fi + _p9k__display_v[k+1]=$new + name=$_p9k__display_v[k] + if [[ $name == (empty_line|ruler) ]]; then + var=_p9k__${name}_i + [[ $new == show ]] && unset $var || typeset -gi $var=3 + elif [[ $name == (#b)(<->)(*) ]]; then + var=_p9k__${match[1]}${${${${match[2]//\/}/#left/l}/#right/r}/#gap/g} + [[ $new == hide ]] && typeset -g $var= || unset $var + fi + if (( __p9k_reset_state > 0 )); then + __p9k_reset_state=2 + else + __p9k_reset_state=-1 + fi + done done - (( reset )) && zle && _p9k_reset_prompt || true + if (( __p9k_reset_state == -1 )); then + _p9k_reset_prompt + __p9k_reset_state=0 + fi ;; configure) if (( ARGC > 1 )); then |