bug fix: don't assume that $#POWERLEVEL9K_BATTERY_STAGES == $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND

Reported in: https://github.com/romkatv/powerlevel10k/issues/88
pull/93/head
romkatv 5 years ago
parent f95a0fc3ee
commit d80d3a5704

@ -413,13 +413,6 @@ set_default -a POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND
set_default POWERLEVEL9K_BATTERY_VERBOSE true set_default POWERLEVEL9K_BATTERY_VERBOSE true
typeset -g POWERLEVEL9K_BATTERY_STAGES typeset -g POWERLEVEL9K_BATTERY_STAGES
typeset -gA _P9K_BATTERY_STATES=(
'low' 'red'
'charging' 'yellow'
'charged' 'green'
'disconnected' "$DEFAULT_COLOR_INVERTED"
)
function _p9k_read_file() { function _p9k_read_file() {
_P9K_RETVAL='' _P9K_RETVAL=''
[[ -n $1 ]] && read -r _P9K_RETVAL <$1 [[ -n $1 ]] && read -r _P9K_RETVAL <$1
@ -507,15 +500,19 @@ prompt_battery() {
local msg="$bat_percent%%" local msg="$bat_percent%%"
[[ $POWERLEVEL9K_BATTERY_VERBOSE == true && -n $remain ]] && msg+=" ($remain)" [[ $POWERLEVEL9K_BATTERY_VERBOSE == true && -n $remain ]] && msg+=" ($remain)"
local icon=BATTERY_ICON bg=$DEFAULT_COLOR local icon=BATTERY_ICON
if (( $#POWERLEVEL9K_BATTERY_STAGES || $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )); then if (( $#POWERLEVEL9K_BATTERY_STAGES )); then
local -i idx=$#POWERLEVEL9K_BATTERY_STAGES local -i idx=$#POWERLEVEL9K_BATTERY_STAGES
(( bat_percent < 100 )) && idx=$((bat_percent * $#POWERLEVEL9K_BATTERY_STAGES / 100 + 1)) (( bat_percent < 100 )) && idx=$((bat_percent * $#POWERLEVEL9K_BATTERY_STAGES / 100 + 1))
if (( $#POWERLEVEL9K_BATTERY_STAGES )); then
icon+=_$idx icon+=_$idx
typeset -g POWERLEVEL9K_$icon=$POWERLEVEL9K_BATTERY_STAGES[idx] typeset -g POWERLEVEL9K_$icon=$POWERLEVEL9K_BATTERY_STAGES[idx]
fi fi
(( $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )) && bg=$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[idx]
local bg=$DEFAULT_COLOR
if (( $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND )); then
local -i idx=$#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND
(( bat_percent < 100 )) && idx=$((bat_percent * $#POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND / 100 + 1))
bg=$POWERLEVEL9K_BATTERY_LEVEL_BACKGROUND[idx]
fi fi
$1_prompt_segment $0_$state $2 "$bg" "$_P9K_BATTERY_STATES[$state]" $icon 0 '' $msg $1_prompt_segment $0_$state $2 "$bg" "$_P9K_BATTERY_STATES[$state]" $icon 0 '' $msg
@ -2486,6 +2483,13 @@ _p9k_init() {
DEFAULT_COLOR_INVERTED=white DEFAULT_COLOR_INVERTED=white
fi fi
typeset -gA _P9K_BATTERY_STATES=(
'low' 'red'
'charging' 'yellow'
'charged' 'green'
'disconnected' "$DEFAULT_COLOR_INVERTED"
)
local i local i
for ((i = 2; i <= $#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; ++i)); do for ((i = 2; i <= $#POWERLEVEL9K_LEFT_PROMPT_ELEMENTS; ++i)); do
local elem=$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[$i] local elem=$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[$i]

Loading…
Cancel
Save