stop loading icons.zsh lazily; print boundaries in get_icon_names

pull/527/head
romkatv 5 years ago
parent d9da275e9e
commit a6a2d9a481

@ -636,14 +636,18 @@ function _p9k_init_icons() {
} }
# Sadly, this is a part of public API. Its use is emphatically discouraged. # Sadly, this is a part of public API. Its use is emphatically discouraged.
function _p9k_print_icon() { function print_icon() {
eval "$__p9k_intro"
if (( ! $+_p9k__locale )); then
_p9k_init_locale
[[ -z $_p9k__locale ]] || local LC_ALL=$_p9k__locale
fi
_p9k_init_icons _p9k_init_icons
local icon_name=$1 local var=POWERLEVEL9K_$1
local var_name=POWERLEVEL9K_${icon_name} if (( $+parameters[$var] )); then
if [[ -n "${(tP)var_name}" ]]; then echo -n - ${(P)var}
echo -n "${(P)var_name}"
else else
echo -n "${icons[$icon_name]}" echo -n - $icons[$1]
fi fi
} }
@ -652,17 +656,22 @@ function _p9k_print_icon() {
# * $1 string - If "original", then the original icons are printed, # * $1 string - If "original", then the original icons are printed,
# otherwise "print_icon" is used, which takes the users # otherwise "print_icon" is used, which takes the users
# overrides into account. # overrides into account.
function _p9k_get_icon_names() { function get_icon_names() {
eval "$__p9k_intro"
if (( ! $+_p9k__locale )); then
_p9k_init_locale
[[ -z $_p9k__locale ]] || local LC_ALL=$_p9k__locale
fi
_p9k_init_icons _p9k_init_icons
# Iterate over a ordered list of keys of the icons array local key
for key in ${(@kon)icons}; do for key in ${(@kon)icons}; do
echo -n "POWERLEVEL9K_$key: " echo -n - "POWERLEVEL9K_$key: "
if [[ "${1}" == "original" ]]; then print -nP "%K{red} %k"
# print the original icons as they are defined in the array above if [[ $1 == original ]]; then
echo "${icons[$key]}" echo -n - $icons[$key]
else else
# print the icons as they are configured by the user print_icon $key
echo "$(print_icon "$key")"
fi fi
print -P "%K{red} %k"
done done
} }

@ -52,6 +52,7 @@ fi
source "${__p9k_root_dir}/internal/configure.zsh" source "${__p9k_root_dir}/internal/configure.zsh"
source "${__p9k_root_dir}/internal/worker.zsh" source "${__p9k_root_dir}/internal/worker.zsh"
source "${__p9k_root_dir}/internal/parser.zsh" source "${__p9k_root_dir}/internal/parser.zsh"
source "${__p9k_root_dir}/internal/icons.zsh"
# For compatibility with Powerlevel9k. It's not recommended to use mnemonic color # For compatibility with Powerlevel9k. It's not recommended to use mnemonic color
# names in the configuration except for colors 0-7 as these are standard. # names in the configuration except for colors 0-7 as these are standard.
@ -137,32 +138,6 @@ function getColorCode() {
return 1 return 1
} }
# Sadly, this is a part of public API. Its use is emphatically discouraged.
function print_icon() {
eval "$__p9k_intro"
if (( ! $+_p9k__locale )); then
_p9k_init_locale
[[ -z $_p9k__locale ]] || local LC_ALL=$_p9k__locale
fi
(( $+functions[_p9k_print_icon] )) || source "${__p9k_root_dir}/internal/icons.zsh"
_p9k_print_icon "$@"
}
# Prints a list of configured icons.
#
# * $1 string - If "original", then the original icons are printed,
# otherwise "print_icon" is used, which takes the users
# overrides into account.
function get_icon_names() {
eval "$__p9k_intro"
if (( ! $+_p9k__locale )); then
_p9k_init_locale
[[ -z $_p9k__locale ]] || local LC_ALL=$_p9k__locale
fi
(( $+functions[_p9k_get_icon_names] )) || source "${__p9k_root_dir}/internal/icons.zsh"
_p9k_get_icon_names "$@"
}
# _p9k_declare <type> <uppercase-name> [default]... # _p9k_declare <type> <uppercase-name> [default]...
function _p9k_declare() { function _p9k_declare() {
local -i set=$+parameters[$2] local -i set=$+parameters[$2]
@ -7055,7 +7030,7 @@ _p9k_must_init() {
[[ $sig == $_p9k__param_sig ]] && return 1 [[ $sig == $_p9k__param_sig ]] && return 1
_p9k_deinit _p9k_deinit
fi fi
_p9k__param_pat=$'v50\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1' _p9k__param_pat=$'v51\1'${ZSH_VERSION}$'\1'${ZSH_PATCHLEVEL}$'\1'
_p9k__param_pat+=$'${#parameters[(I)POWERLEVEL9K_*]}\1${(%):-%n%#}\1$GITSTATUS_LOG_LEVEL\1' _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+=$'$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+=$'$DEFAULT_USER\1${ZLE_RPROMPT_INDENT:-1}\1$P9K_SSH\1$__p9k_ksh_arrays'
@ -7075,7 +7050,6 @@ function _p9k_set_os() {
} }
function _p9k_init_cacheable() { function _p9k_init_cacheable() {
(( $+functions[_p9k_init_icons] )) || source "${__p9k_root_dir}/internal/icons.zsh"
_p9k_init_icons _p9k_init_icons
_p9k_init_params _p9k_init_params
_p9k_init_prompt _p9k_init_prompt

@ -1827,7 +1827,6 @@ fi
zmodload zsh/terminfo || return zmodload zsh/terminfo || return
autoload -Uz is-at-least || return autoload -Uz is-at-least || return
source $__p9k_root_dir/internal/icons.zsh || return
if is-at-least 5.7.1 && [[ $COLORTERM == (24bit|truecolor) ]]; then if is-at-least 5.7.1 && [[ $COLORTERM == (24bit|truecolor) ]]; then
local -ir has_truecolor=1 local -ir has_truecolor=1

Loading…
Cancel
Save