Skip to content

Commit

Permalink
Kill sleep when resizing and delay size checking a bit
Browse files Browse the repository at this point in the history
Signed-off-by: Christian König <ckoenig@posteo.de>
  • Loading branch information
yubiuser committed Oct 24, 2022
1 parent c4a5b14 commit a107871
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions padd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,13 @@ BarGenerator() {
echo "$out"
}

# Checks the size of the screen and sets the value of padd_size
# Checks the size of the screen and sets the value of $padd_size
SizeChecker(){
# adding a tiny delay here to to give the kernel a bit time to
# report new sizes correctly after a terminal resize
# this reduces "flickering" of GenerateSizeDependendOutput() items
# after a terminal re-size
sleep 0.1
console_height=$(stty size | awk '{ print $1 }')
console_width=$(stty size | awk '{ print $2 }')

Expand Down Expand Up @@ -1193,11 +1198,11 @@ NormalPADD() {

# Sleep for 5 seconds
# sending sleep in the background and wait for it
# this way the TerminalResize trap can re-draw the dashboard even when
# sleep is running
# this way the TerminalResize trap can kill the sleep
# and force a instant re-draw of the dashboard
# https://stackoverflow.com/questions/32041674/linux-how-to-kill-sleep
#
# saving the PID of the background sleep process to kill it on exit
# saving the PID of the background sleep process to kill it on exit and resize
sleep 5 &
sleepPID=$!
wait $!
Expand Down Expand Up @@ -1281,18 +1286,17 @@ CleanExit(){

# if background sleep is running, kill it
# http://mywiki.wooledge.org/SignalTrap#When_is_the_signal_handled.3F
if [ -n "${sleepPID}" ]; then
kill "${sleepPID}"
fi
kill $sleepPID > /dev/null 2>&1

exit $err # exit the script with saved $?
}

TerminalResize(){
# if a terminal resize is trapped, check the new size and immediately print a new Dashboard
# if a terminal resize is trapped, check the new terminal size and
# kill the sleep function within NormalPADD() to trigger redrawing
# of the Dashboard
SizeChecker
GenerateSizeDependendOutput ${padd_size}
PrintDashboard ${padd_size}
kill $sleepPID > /dev/null 2>&1
}

main(){
Expand Down

0 comments on commit a107871

Please sign in to comment.