Skip to content

Commit

Permalink
Clear the line before writing to prevent overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
molovo committed Jul 4, 2017
1 parent b132c0e commit 13e7af7
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions revolver
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 13e7af7

Please sign in to comment.