Compare commits

...

9 Commits

2 changed files with 79 additions and 7 deletions

View File

@ -138,6 +138,14 @@ function getColorCode() {
return 1
}
function _p9k_codeset_is_utf8() {
# Use `case` to survive SH_GLOB.
case "${langinfo[CODESET]}" in
utf-8|UTF-8|utf8|UTF8) return 0;;
*) return 1;;
esac
}
# _p9k_declare <type> <uppercase-name> [default]...
function _p9k_declare() {
local -i set=$+parameters[$2]
@ -1344,6 +1352,16 @@ _p9k_prompt_battery_init() {
_p9k__async_segments_compute+='_p9k_worker_invoke battery _p9k_prompt_battery_compute'
return
fi
if [[ $_p9k_os == Windows ]]; then
if command -v wmic > /dev/null 2>&1; then # Test "wimc" command
_p9k__async_segments_compute+='_p9k_worker_invoke battery _p9k_prompt_battery_compute'
return
else
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
fi
fi
if [[ $_p9k_os != (Linux|Android) ||
-z /sys/class/power_supply/(CMB*|BAT*|*battery)/(energy_full|charge_full|charge_counter)(#qN) ]]; then
typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${:-}'
@ -1456,6 +1474,54 @@ _p9k_prompt_battery_set_args() {
fi
;;
Windows)
local raw_data
local -a info_values
# See definitions to Win32_Battery class members at https://learn.microsoft.com/en-us/windows/win32/cimwin32prov/win32-battery
{
read -r 2>/dev/null
read -r raw_data
} <<< "$(wmic path Win32_Battery get BatteryStatus,EstimatedChargeRemaining,EstimatedRunTime)"
# info_values[1]: BatteryStatus
# info_values[2]: EstimatedChargeRemaining
# info_values[3]: EstimatedRunTime
info_values=(${(s: :)raw_data})
(( ${#info_values[@]} == 4 )) || return # Missing info_values (index [4] is for the following CRCR)
bat_percent=${info_values[2]}
local -i bat_remain_minutes=${info_values[3]}
case ${info_values[1]} in
'1'|'4'|'5')
# When the battery is charging or full, system will show that bat_remain_minutes (EstimatedRunTime) is 71582788 (min)
(( bat_remain_minutes < 71582788 )) && remain=$((bat_remain_minutes/60)):${(l#2##0#)$((bat_remain_minutes%60))} || remain=''
if (( bat_percent < _POWERLEVEL9K_BATTERY_LOW_THRESHOLD )); then
state=LOW
else
state=DISCONNECTED
fi
;;
'2'|'6'|'7'|'8'|'9'|'11') # In this case, the battery is likely to be charged and disconnected, or still been charging.
remain=''
if (( bat_percent == 100 )); then
state=CHARGED
else
state=CHARGING
fi
;;
'3')
(( bat_remain_minutes < 71582788 )) && remain=$((bat_remain_minutes/60)):${(l#2##0#)$((bat_remain_minutes%60))} || remain=''
state=CHARGED
;;
*)
state=CHARGED
remain=''
;;
esac
;;
*)
return 0
;;
@ -1796,7 +1862,7 @@ prompt_dir() {
if (( $+_POWERLEVEL9K_SHORTEN_DELIMITER )); then
local delim=$_POWERLEVEL9K_SHORTEN_DELIMITER
else
if [[ $langinfo[CODESET] == (utf|UTF)(-|)8 ]]; then
if _p9k_codeset_is_utf8; then
local delim=$'\u2026'
else
local delim='..'
@ -6851,13 +6917,13 @@ function _p9k_restore_special_params() {
}
function _p9k_on_expand() {
(( _p9k__expanded && ! ${+__p9k_instant_prompt_active} )) && [[ "${langinfo[CODESET]}" == (utf|UTF)(-|)8 ]] && return
(( _p9k__expanded && ! ${+__p9k_instant_prompt_active} )) && _p9k_codeset_is_utf8 && return
eval "$__p9k_intro_no_locale"
if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]]; then
if ! _p9k_codeset_is_utf8; then
_p9k_restore_special_params
if [[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]] && _p9k_init_locale; then
if ! _p9k_codeset_is_utf8 && _p9k_init_locale; then
if [[ -n $LC_ALL ]]; then
_p9k__real_lc_all=$LC_ALL
LC_ALL=$__p9k_locale
@ -7458,7 +7524,7 @@ _p9k_init_params() {
_p9k_declare -i POWERLEVEL9K_VCS_SHORTEN_LENGTH
_p9k_declare -i POWERLEVEL9K_VCS_SHORTEN_MIN_LENGTH
_p9k_declare -s POWERLEVEL9K_VCS_SHORTEN_STRATEGY
if [[ $langinfo[CODESET] == (utf|UTF)(-|)8 ]]; then
if _p9k_codeset_is_utf8; then
_p9k_declare -e POWERLEVEL9K_VCS_SHORTEN_DELIMITER '\u2026'
else
_p9k_declare -e POWERLEVEL9K_VCS_SHORTEN_DELIMITER '..'
@ -9519,7 +9585,7 @@ 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
typeset -g P9K_VERSION=1.20.16
typeset -g P9K_VERSION=1.20.17
if [[ ${VSCODE_SHELL_INTEGRATION-} == <1-> && ${+__p9k_force_term_shell_integration} == 0 ]]; then
typeset -gri __p9k_force_term_shell_integration=1

View File

@ -27,7 +27,13 @@
local -a match mbegin mend
local -i MBEGIN MEND OPTIND
local MATCH OPTARG IFS=$'\'' \t\n\0'\'
typeset -gr __p9k_intro_locale='[[ $langinfo[CODESET] != (utf|UTF)(-|)8 ]] && _p9k_init_locale && { [[ -n $LC_ALL ]] && local LC_ALL=$__p9k_locale || local LC_CTYPE=$__p9k_locale }'
# Use `case` to survive SH_GLOB.
typeset -gr __p9k_intro_locale='{
case "${langinfo[CODESET]}" in
utf-8|UTF-8|utf8|UTF8) false;;
*) true;;
esac
} && _p9k_init_locale && { [[ -n "$LC_ALL" ]] && local LC_ALL=$__p9k_locale || local LC_CTYPE=$__p9k_locale }'
typeset -gr __p9k_intro_no_locale="${${__p9k_intro_base/ match / match reply }/ MATCH / MATCH REPLY }"
typeset -gr __p9k_intro_no_reply="$__p9k_intro_base; $__p9k_intro_locale"
typeset -gr __p9k_intro="$__p9k_intro_no_locale; $__p9k_intro_locale"