aboutsummaryrefslogtreecommitdiff
path: root/internal/p10k.zsh
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-07-09 11:09:50 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-07-09 11:09:50 +0300
commit996316a6fcc785af3d765fcbfb7110a67c4a7746 (patch)
tree3231cd42df366cb975c98faacf9165ca7222bfac /internal/p10k.zsh
parent0891841e7552371f8c9009d2cab27c227bd0dfb5 (diff)
iron out bugs in the new rendered; rename TRANSFORMER to EXPANSION
Diffstat (limited to 'internal/p10k.zsh')
-rwxr-xr-xinternal/p10k.zsh101
1 files changed, 56 insertions, 45 deletions
diff --git a/internal/p10k.zsh b/internal/p10k.zsh
index 0ec0da90..17b89159 100755
--- a/internal/p10k.zsh
+++ b/internal/p10k.zsh
@@ -129,7 +129,7 @@ _p9k_escape_rcurly() {
}
_p9k_escape() {
- _P9K_RETVAL="\${(Q)\${:-${(qqq)${(q)1}}}}"
+ [[ $1 == *["~!#\$^&*()\\\"'<>?{}[]"]* ]] && _P9K_RETVAL="\${(Q)\${:-${(qqq)${(q)1}}}}" || _P9K_RETVAL=$1
}
# Begin a left prompt segment.
@@ -160,13 +160,25 @@ left_prompt_segment() {
_p9k_get_icon LEFT_SUBSEGMENT_SEPARATOR
local subsep=$_P9K_RETVAL
+ local icon_
+ if [[ -n $5 ]]; then
+ _p9k_get_icon $5
+ _p9k_escape $_P9K_RETVAL
+ icon_=$_P9K_RETVAL
+ fi
+
local line_start=$POWERLEVEL9K_LEFT_PROMPT_FIRST_SEGMENT_START_SYMBOL
- [[ -n $line_start ]] && line_start="%b%k%F{$bg_color}$line_start"
+ [[ -n $line_start ]] && line_start="%k%F{$bg_color}$line_start"
local style=%b$bg$fg
_p9k_escape_rcurly $style
local style_=$_P9K_RETVAL
+ local space=$POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS
+ [[ $space == *%* ]] && space+=$style
+ _p9k_escape $space
+ local space_=$_P9K_RETVAL
+
local state=${(U)${1}#prompt_}
# Segment separator logic:
@@ -175,79 +187,78 @@ left_prompt_segment() {
# 1
# elif (( joined )); then
# 2
- # elif [[ $bg_color == $_P9K_BG ]]; then
+ # elif [[ $bg_color == (${_P9K_BG}|${_P9K_BG:-0}) ]]; then
# 3
# else
# 4
# fi
local t=$#_P9K_T
- _P9K_T+=$line_start # 1
- _P9K_T+='' # 2
+ _P9K_T+=$line_start$style$space # 1
+ _P9K_T+=$style # 2
if [[ -z $fg_color ]]; then
_p9k_foreground $DEFAULT_COLOR
- _P9K_T+=%b$bg$_P9K_RETVAL$subsep # 3
+ _P9K_T+=$bg$_P9K_RETVAL$subsep$style$space # 3
else
- _P9K_T+=$style$subsep # 3
+ _P9K_T+=$bg$fg$subsep$style$space # 3
fi
_p9k_get_icon LEFT_SEGMENT_SEPARATOR
- _P9K_T+=%b$bg%F{\$_P9K_BG}$_P9K_RETVAL # 4
+ _P9K_T+=$bg$_P9K_RETVAL$style$space # 4
local p=
-
- local p='${P9K_VISUAL_IDENTIFIER::='
- if [[ -n $5 ]]; then
- _p9k_get_icon $5
- [[ -n $_P9K_RETVAL ]] && p+="\${(Q)\${:-${(qqq)${(q)_P9K_RETVAL}}}}"
+ p+="\${_P9K_N::=}\${_P9K_F::=}"
+ p+="\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}" # 1
+ p+="\${_P9K_N:=\${\${\$((_P9K_I>=$_P9K_LEFT_JOIN[$2])):#0}:+$((t+2))}}" # 2
+ p+="\${_P9K_N:=\${\${(M)\${:-x$bg_color}:#x(\$_P9K_BG|\${_P9K_BG:-0})}:+$((t+3))}}" # 3
+ p+="\${_P9K_N:=\${\${_P9K_F::=%F{\$_P9K_BG\}}:+$((t+4))}}" # 4
+
+ p+="\${_P9K_I::=$2}\${_P9K_BG::=$bg_color}"
+
+ local icon_exp=POWERLEVEL9K_${state}_VISUAL_IDENTIFIER_EXPANSION
+ (( $+parameters[$icon_exp] )) && icon_exp=${(P)icon_exp} || icon_exp='${P9K_VISUAL_IDENTIFIER}'
+ local content_exp=POWERLEVEL9K_${state}_CONTENT_EXPANSION
+ (( $+parameters[$content_exp] )) && content_exp=${(P)content_exp} || content_exp='${P9K_CONTENT}'
+
+ if [[ $icon_exp == '${P9K_VISUAL_IDENTIFIER}' && $content_exp == '${P9K_CONTENT}' ]]; then
+ p+="\${_P9K_V::=$icon_"
+ [[ $icon_ == *%* ]] && p+=$style_
+ p+="}"
+ else
+ p+="\${P9K_VISUAL_IDENTIFIER::=$icon}\${_P9K_V::=$icon_exp$style_}"
fi
- p+='}'
- p+="\${_P9K_N::=}"
- p+="\${\${\${_P9K_BG:-0}:#NONE}:-\${_P9K_N::=$((t+1))}}" # 1
- p+="\${_P9K_N:=\${\${\$((_P9K_I>=$_P9K_LEFT_JOIN[$2])):#0}:+$((t+2))}}" # 2
- p+="\${_P9K_N:=\${\${\$((!\${#\${:-0\$_P9K_BG}:#0$bg_color})):#0}:+$((t+3))}}" # 3
- p+="\${_P9K_N:=$((t+4))}" # 4
-
- p+="\${_P9K_I::=$2}"
-
- p+='${_P9K_C::='
- local var=POWERLEVEL9K_${state}_CONTENT_TRANSFORMER
- (( $+parameters[$var] )) && p+=${(P)var} || p+='${P9K_CONTENT}'
- p+='}'
-
- p+='${_P9K_V::='
- local var=POWERLEVEL9K_${state}_VISUAL_IDENTIFIER_TRANSFORMER
- (( $+parameters[$var] )) && p+=${(P)var} || p+='${P9K_P9K_VISUAL_IDENTIFIER}'
- p+='}'
-
- _p9k_escape $POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS
- local space_=$_P9K_RETVAL
+ p+="\${_P9K_C::=$content_exp}"
p+='}+}'
_p9k_get_icon ${state}_PREFIX
_p9k_escape $_P9K_RETVAL
- p+="\${_P9K_T[\$_P9K_N]}$style_$space_$style_$_P9K_RETVAL"
+ p+="%b\${_P9K_F}\${_P9K_T[\$_P9K_N]}$_P9K_RETVAL"
+ [[ $_P9K_RETVAL == *%* ]] && local -i need_style=1 || local -i need_style=0
_p9k_color $fg_color $1 VISUAL_IDENTIFIER_COLOR
_p9k_foreground $_P9K_RETVAL
- _p9k_escape %b$bg$_P9K_RETVAL
- p+="$_P9K_RETVAL\$_P9K_V$style_"
+ _p9k_escape_rcurly %b$bg$_P9K_RETVAL
+ [[ $_P9K_RETVAL != $style_ || $need_style == 1 ]] && p+=$_P9K_RETVAL
+ p+="\$_P9K_V"
- # TODO: Fix this. Output space only if _P9K_V and _P9K_C are both non-empty.
- p+='${${(%):-$_P9K_V%1(l. .x)}[-1]:#x}'
+ p+='${${(%):-$_P9K_V%1(l.${(%):-$_P9K_C%1(l. .x)}.x)}[-1]:#x}'
_p9k_get_icon ${state}_SUFFIX
_p9k_escape $_P9K_RETVAL
- p+="\${_P9K_C}$style_$_P9K_RETVAL$style_$space_\${\${_P9K_BG::=$bg_color}+}"
-
- p+='}'
+ p+="\${_P9K_C}$style_$_P9K_RETVAL"
+ [[ $_P9K_RETVAL == *%* ]] && p+=$style_
+ p+=$space_
_p9k_cache_set "$p"
fi
- (( $6 )) && local content=$8 || local content="\${(Q)\${:-${(qqq)${(q)8}}}}"
- _P9K_PROMPT+="\${\${:-${7:-1}}:+\${\${:-\${P9K_CONTENT::=$content}$_P9K_CACHE_VAL[1]"
+ (( $6 )) && _P9K_RETVAL=$8 || _p9k_escape $8
+ if [[ -z $7 ]]; then
+ _P9K_PROMPT+="\${\${:-\${P9K_CONTENT::=$_P9K_RETVAL}$_P9K_CACHE_VAL[1]"
+ else
+ _P9K_PROMPT+="\${\${:-$7}:+\${\${:-\${P9K_CONTENT::=$_P9K_RETVAL}$_P9K_CACHE_VAL[1]}"
+ fi
}
# The same as left_prompt_segment above but for the right prompt.
@@ -320,7 +331,7 @@ right_prompt_segment() {
local space=$_P9K_RETVAL
fi
- local tr=POWERLEVEL9K_${state}_CONTENT_TRANSFORMER
+ local tr=POWERLEVEL9K_${state}_CONTENT_EXPANSION
(( $+parameters[$tr] )) && tr=${(P)tr} || tr='${P9K_CONTENT}'
_p9k_get_icon ${state}_SUFFIX