batwatch: Buffer to reduce flickering from redraw

This commit is contained in:
Ethan P 2021-08-11 01:15:46 -07:00
parent 20cdf5a998
commit d989b0bfde
No known key found for this signature in database
GPG Key ID: 6963FD04F6CF35EA

View File

@ -284,9 +284,22 @@ else
fi fi
main() { main() {
local last_rendered
local rendered
local term_width="$(term_width)"
BAT_ARGS+=("--terminal-width=$term_width")
while true; do while true; do
clear IFS='' rendered="$("${FILES[@]}" 2>&1 | "$EXECUTABLE_BAT" "${BAT_ARGS[@]}")"
"${FILES[@]}" 2>&1 | "$EXECUTABLE_BAT" "${BAT_ARGS[@]}" if [ "$rendered" != "$last_rendered" ]; then
# Only clear and redraw if there's a change.
# This reduces excessive flickering.
last_rendered="$rendered"
clear
printf "%s\n" "$rendered"
rendered=''
fi
sleep "${OPT_INTERVAL}" || exit 1 sleep "${OPT_INTERVAL}" || exit 1
done done
} }