Last active
August 29, 2015 13:56
-
-
Save dekarrin/8884468 to your computer and use it in GitHub Desktop.
Overwrites the last line of the terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Outputs without a newline and overwrites anything that was already on the last line of | |
# the terminal | |
overwrite () | |
{ | |
output="$1" | |
if [ -z "$output" ] | |
then | |
read output | |
fi | |
printf "\r" | |
if [ -n "$LAST_OVERWRITE_LENGTH" ] | |
then | |
if [ "$LAST_OVERWRITE_LENGTH" -gt 0 ] | |
then | |
clear_space_count=0 | |
while [ $clear_space_count -lt $LAST_OVERWRITE_LENGTH ] | |
do | |
printf " " | |
let clear_space_count++ | |
done | |
printf "\r" | |
fi | |
fi | |
# only save length of last line | |
while read -r line | |
do | |
LAST_OVERWRITE_LENGTH=${#line} | |
printf "$line" | |
done <<< "$output" | |
} | |
# Outputs with a newline and overwrites anything that was already on the last line of | |
# the terminal | |
overwriteln () | |
{ | |
overwrite "$@" | |
printf "\n" | |
LAST_OVERWRITE_LENGTH=0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment