Last active
October 1, 2023 16:25
-
-
Save dideler/b0a0ef8b95e683752883 to your computer and use it in GitHub Desktop.
Basic CLI loading animation
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
#!/usr/bin/env bash | |
for i in {0..12}; do | |
if ! (($i % 4)); then | |
printf "\e[1K\rloading" | |
else | |
printf "." | |
fi | |
sleep 1 | |
done && printf "\e[2K\r" |
you don't put $i
in (( ))
. Just i
is enough.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The terminal escapes are the interesting part.
\033[1K
or\e[1K
will clear from the cursor position to the beginning of the line.\033[2K
or\e[2K
will clear everything on the line.