Feat: Process all requestd modules before drawing
This commit is contained in:
parent
8669361595
commit
1ad7087552
28
avdd
28
avdd
@ -96,18 +96,22 @@ draw_status() {
|
|||||||
# Draw the initial status
|
# Draw the initial status
|
||||||
draw_status
|
draw_status
|
||||||
|
|
||||||
# If the module value is in the cache, indicating that the module controls
|
# Process a list of mods. If a mod is in the status cache, call the module
|
||||||
# part of the status bar, execute the module function and redraw the status
|
# function to get the new value for that section of the status bar. If any
|
||||||
# bar if that part of the status bar has changed
|
# of the new values are different from the cached ones, update the cache
|
||||||
process_cmd () {
|
# and redraw the status bar once after all the mods are processed.
|
||||||
local -r mod="$1"
|
process_mods () {
|
||||||
|
local mod new_val is_changed
|
||||||
|
for mod in "$@"; do
|
||||||
if [[ -v stat_cache[${mod}] ]]; then
|
if [[ -v stat_cache[${mod}] ]]; then
|
||||||
local -r new_val="$(eval "$(mod_to_fn "${mod}")")"
|
new_val="$(eval "$(mod_to_fn "${mod}")")"
|
||||||
if [[ "${new_val}" != stat_cache["${mod}"] ]]; then
|
if [[ "${new_val}" != stat_cache["${mod}"] ]]; then
|
||||||
stat_cache["${mod}"]="${new_val}"
|
stat_cache["${mod}"]="${new_val}"
|
||||||
draw_status
|
is_changed=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
done
|
||||||
|
if [[ -v is_changed ]]; then draw_status; fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Setup the named pipe to receive commands
|
# Setup the named pipe to receive commands
|
||||||
@ -118,15 +122,19 @@ trap "rm -f ${FIFO}" EXIT
|
|||||||
# Each time the pipe is emptied out, the inner while loop will finish, so
|
# Each time the pipe is emptied out, the inner while loop will finish, so
|
||||||
# wrap it in an infinte loop to keep blocking until there is data on the pipe
|
# wrap it in an infinte loop to keep blocking until there is data on the pipe
|
||||||
while :; do
|
while :; do
|
||||||
while read -r cmd; do
|
while read -r fifo_mod_list; do
|
||||||
case "${cmd}" in
|
case "${fifo_mod_list}" in
|
||||||
|
res_all)
|
||||||
|
process_mods "${mods[@]}"
|
||||||
|
;;
|
||||||
res_quit)
|
res_quit)
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
res_*)
|
res_*)
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
process_cmd "${cmd}"
|
IFS=', ' read -r -a fifo_mods <<< "${fifo_mod_list}"
|
||||||
|
process_mods "${fifo_mods[@]}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done < "${FIFO}"
|
done < "${FIFO}"
|
||||||
|
13
avds
13
avds
@ -51,29 +51,30 @@ ms_to_s () {
|
|||||||
printf '%.3f' "${1}e-3"
|
printf '%.3f' "${1}e-3"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Validate the arguments
|
# Validate the number arguments
|
||||||
if [[ "$#" -lt 1 || "$#" -gt 3 ]]; then
|
if [[ "$#" -lt 1 || "$#" -gt 3 ]]; then
|
||||||
printf '%s' "${USAGE}" 1>&2
|
printf '%s' "${USAGE}" 1>&2
|
||||||
exit 128
|
exit 128
|
||||||
fi
|
fi
|
||||||
|
|
||||||
IFS=', ' read -r -a mods <<< "$1"
|
mod_list="$1"
|
||||||
|
|
||||||
# Check if the user needs help
|
# Check if the user needs help
|
||||||
# shellcheck disable=SC2128
|
if [[ "${mod_list}" =~ ^(-h|-(-)?help)$ ]]; then
|
||||||
if [[ "${mods}" =~ ^(-h|-(-)?help)$ ]]; then
|
|
||||||
printf '%s' "${USAGE}" 1>&2
|
printf '%s' "${USAGE}" 1>&2
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
when="${2:-0}"
|
when="${2:-0}"
|
||||||
repeat="$3"
|
|
||||||
|
|
||||||
|
# Validate when
|
||||||
if [[ ! "${when}" =~ ^[0-9]+|[mhd]$ ]]; then
|
if [[ ! "${when}" =~ ^[0-9]+|[mhd]$ ]]; then
|
||||||
printf 'Invalid argument <when>: %s\n' "${when}" 1>&2
|
printf 'Invalid argument <when>: %s\n' "${when}" 1>&2
|
||||||
exit 128
|
exit 128
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
repeat="$3"
|
||||||
|
|
||||||
# Write to the pipe if this is the first run or if repeat is on
|
# Write to the pipe if this is the first run or if repeat is on
|
||||||
first_run=1
|
first_run=1
|
||||||
while [[ "${first_run}" -eq 1 || -n "${repeat}" ]]; do
|
while [[ "${first_run}" -eq 1 || -n "${repeat}" ]]; do
|
||||||
@ -107,6 +108,6 @@ while [[ "${first_run}" -eq 1 || -n "${repeat}" ]]; do
|
|||||||
printf 'The daemon %s is not running\n' "${DAEMON}" 1>&2
|
printf 'The daemon %s is not running\n' "${DAEMON}" 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
for mod in "${mods[@]}"; do printf '%s\n' "${mod}" >> "${FIFO}"; done
|
printf '%s\n' "${mod_list}" >> "${FIFO}"
|
||||||
done
|
done
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user