I'd like to create multiple progress bars and update them on the go, without the need to clear the whole screen (I'd like the previous stdout contents to remain on the screen).
I need to:
- Write a few lines with
echo
- Wait with
sleep
- Get my cursor back to the start of the first line
- Overwrite my few lines with updated information
- Repeat from step 2.
The think is I'd like the user to be able to scroll back to read the previous stdout contents.
If I didn't care about the scrollback, I'd just use clear
and write out again what I need:
while [ true ]; do echo "$SECONDS"; sleep 0.1; clear; done
This however makes the scrollback completely unreadable, because clear
simply prints out enough newlines to push previous terminal output out of view.
When I run htop
and close it - it restores my terminal to the exact same state where it started htop. Can something like this be achieved in a bash script?