_lp_color_map is now able to adjust to different scales

Given a second parameters, _lp_color_map is now able to display
different colors depending on a scale. The second parameter is the
lowest step on the scale and ten times it the highest.
This commit is contained in:
François Schmidts 2013-06-05 15:32:21 +02:00 committed by Olivier Mengué
parent 43c7016c34
commit d104b275a1

View File

@ -1143,31 +1143,31 @@ _lp_battery_color()
}
_lp_color_map() {
local -i value
value=$1
if (( value < 100 )); then
if (( value < 60 )); then
if (( value < 20 )); then
local -i value=$1
local -i step=$2
if (( value < step * 5 )); then
if (( value < step * 3 )); then
if (( value < step )); then
echo -ne "${LP_COLORMAP_0}"
elif (( value < 40 )); then
elif (( value < step * 2 )); then
echo -ne "${LP_COLORMAP_1}"
else # 40..59
echo -ne "${LP_COLORMAP_2}"
fi
elif (( value < 80 )); then
elif (( value < step * 4 )); then
echo -ne "${LP_COLORMAP_3}"
else # 80..99
echo -ne "${LP_COLORMAP_4}"
fi
elif (( value < 160 )); then
if (( value < 120 )); then
elif (( value < step * 8 )); then
if (( value < step * 6 )); then
echo -ne "${LP_COLORMAP_5}"
elif (( value < 140 )); then
elif (( value < step * 7 )); then
echo -ne "${LP_COLORMAP_6}"
else
echo -ne "${LP_COLORMAP_7}"
fi
elif (( value < 180 )) ; then
elif (( value < step * 9 )) ; then
echo -ne "${LP_COLORMAP_8}"
else # (( value >= 180 ))
echo -ne "${LP_COLORMAP_9}"
@ -1197,7 +1197,7 @@ _lp_load_color()
local -i load=${tmp:-0}/$_lp_CPUNUM
if (( load > $LP_LOAD_THRESHOLD )); then
local ret="$(_lp_color_map $load)${LP_MARK_LOAD}"
local ret="$(_lp_color_map $load 20)${LP_MARK_LOAD}"
if [[ "$LP_PERCENTS_ALWAYS" == 1 ]]; then
if $_LP_SHELL_bash; then
@ -1245,7 +1245,7 @@ _lp_temperature() {
temperature="$($_lp_temp_function)"
if [[ $temperature -ge $LP_TEMP_THRESHOLD ]]; then
echo -ne "${LP_MARK_TEMP}$(_lp_color_map $temperature)$temperature°${NO_COL}"
echo -ne "${LP_MARK_TEMP}$(_lp_color_map $temperature 10)$temperature°${NO_COL}"
fi
}