Last active
February 8, 2020 14:36
-
-
Save glacion/7a29ab8955eab2ca291581596b6873d6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
col=0 | |
line=0 | |
# $1 -> Count | |
# $2 -> Char | |
function put_n_chars { | |
# Read $1 amount of characters from /dev/zero | |
# Replace them with $2 | |
head -c "$1" < /dev/zero | tr '\0' "$2" | |
} | |
function get_start_position { | |
local cols=`tput cols` | |
local lines=`tput lines` | |
# Width of screen | |
col=$cols | |
# In the middle of the screen | |
line=$(( $lines / 2 )) | |
} | |
function setup_screen { | |
tput init # See `man tput` line 79 | |
tput clear # Clear screen | |
tput civis # Toggle cursor invisible | |
} | |
function cleanup { | |
tput reset | |
tput clear | |
# Unset variables | |
unset col | |
unset line | |
} | |
# $1 -> Position | |
# $2 -> String | |
function print_str_from_position { | |
# Put screen width minus string length spaces to screen. | |
put_n_chars $(( $1 - ${#2} )) ' ' | |
# Put string without newline | |
echo -n $2 | |
tput el # Erase line | |
tput cup $line # Go to the start of the line | |
} | |
# $1 -> String | |
function slide_str { | |
# Start from the width of screen, | |
# Decrease until the length of string. | |
for ((i=$col;i>=${#1};i--)) | |
do | |
print_str_from_position $i $1 | |
sleep 0.1 | |
done | |
} | |
# $1 -> String | |
function main { | |
setup_screen | |
get_start_position | |
tput cup $line | |
slide_str "$1" | |
cleanup | |
} | |
main $1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment