bugfix analog time with a correct and faster implementation
This commit is contained in:
parent
f483697fda
commit
16d4014a2e
35
liquidprompt
35
liquidprompt
@ -1318,32 +1318,21 @@ _lp_time_analog()
|
|||||||
# U+1F550 (ONE OCLOCK) and U+1F55B (TWELVE OCLOCK), for the plain hours
|
# U+1F550 (ONE OCLOCK) and U+1F55B (TWELVE OCLOCK), for the plain hours
|
||||||
# U+1F55C (ONE-THIRTY) and U+1F567 (TWELVE-THIRTY), for the thirties
|
# U+1F55C (ONE-THIRTY) and U+1F567 (TWELVE-THIRTY), for the thirties
|
||||||
#
|
#
|
||||||
# Those codes may be output with unicode escapes or hexadecimal escapes,
|
|
||||||
# the later being the more portable.
|
|
||||||
#
|
|
||||||
# But we can iterate only over integers.
|
|
||||||
#
|
|
||||||
# We thus need the following conversion table:
|
|
||||||
# utf hex int
|
|
||||||
# hours 50:5B 90:9b 144:155
|
|
||||||
# half 5C:67 9c:a7 156:167
|
|
||||||
|
|
||||||
# The characters being grouped bas plain/thirty, we must first now
|
plain=(🕐 🕑 🕒 🕓 🕔 🕕 🕖 🕗 🕘 🕙 🕚 🕛 )
|
||||||
# if we are close to the 0 or 30 minutes.
|
half=(🕜 🕝 🕞 🕟 🕠 🕡 🕢 🕣 🕤 🕥 🕦 🕧 )
|
||||||
# Bash using integer arithmetic by default, we do not need rounding.
|
|
||||||
# We thus add 0 (plain hour) or 12 (half).
|
|
||||||
# Then we add 144, which is the first index (as an integer).
|
|
||||||
mi=$((144+12*($min/30)))
|
|
||||||
|
|
||||||
# Add the computed minutes index (144 or 156) minus 1 (because the first hour starts at 0).
|
# array index starts at 0
|
||||||
hi=$(($mi+$hour-1))
|
hi=$((hour-1))
|
||||||
|
|
||||||
# Get the hexadecimal representation of this integer
|
# add a space for correct alignment
|
||||||
hex=$(printf "%x" $hi)
|
if [[ $min -lt 15 ]] ; then
|
||||||
|
echo -n "${plain[$hi]} "
|
||||||
# Print the first three bytes (that are always the same) and the computed last one.
|
elif [[ $min -lt 45 ]] ; then
|
||||||
# Add a space for correct alignement
|
echo -n "${half[$hi]} "
|
||||||
echo -ne "\xf0\x9f\x95\x$hex "
|
else
|
||||||
|
echo -n "${plain[$((hi+1))]} "
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
_lp_time()
|
_lp_time()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user