From 13e7af7ee037b6db0a598a4e54242dd9c63a4c45 Mon Sep 17 00:00:00 2001 From: James Dinsdale Date: Tue, 4 Jul 2017 21:26:13 +0100 Subject: [PATCH] Clear the line before writing to prevent overflow --- revolver | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/revolver b/revolver index eaf657f..51c3dba 100755 --- a/revolver +++ b/revolver @@ -138,6 +138,10 @@ function _revolver_spin() { # Calculate the screen width lim=$(tput cols) + # Clear the line and move the cursor to the start + printf ' %.0s' {1..$lim} + echo -n "\r" + # Echo the current frame and message, and overwrite # the rest of the line with white space msg="\033[0;38;5;242m${msg}\033[0;m" @@ -174,6 +178,10 @@ function _revolver_stop() { state=($(cat $statefile)) pid="$state[1]" + # Clear the line and move the cursor to the start + printf ' %.0s' {1..$(tput cols)} + echo -n "\r" + # If a PID has been found, kill the process [[ ! -z $pid ]] && kill "$pid" > /dev/null unset pid @@ -204,6 +212,10 @@ function _revolver_update() { state=($(cat $statefile)) pid="$state[1]" + # Clear the line and move the cursor to the start + printf ' %.0s' {1..$(tput cols)} + echo -n "\r" + # Echo the new message to the statefile, to be # picked up by the spinner process echo "$pid $msg" >! $statefile