Last active
February 29, 2020 03:38
-
-
Save paradigm/b9855739bf3fe39437c5ad46d7005323 to your computer and use it in GitHub Desktop.
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
#!/bedrock/libexec/busybox sh | |
norm_color='\033[2;97m' | |
high_color='\033[0;97m' | |
drawing='__ | |
\ \___ | |
\ _ \ | |
\___/ | |
' | |
order='0,0 | |
1,0 | |
2,1 | |
3,1 | |
4,1 | |
5,1 | |
6,2 | |
6,3 | |
5,3 | |
4,3 | |
3,3 | |
2,3 | |
1,2 | |
0,1' | |
delay_usec="80000" | |
cursor_hide='\033[?25l' | |
cursor_save='\033[s' | |
cursor_restore='\033[u' | |
cursor_left='\033[1D' | |
draw() { | |
i="${1}" | |
color="${2}" | |
x="$(echo "${order}" | awk -F',' -v"i=${i}" 'NR==i {print $1}')" | |
y="$(echo "${order}" | awk -F',' -v"i=${i}" 'NR==i {print $2}')" | |
if [ -n "${color}" ]; then | |
c="$(echo "${drawing}" | awk -v"x=${x}" -v"y=${y}" 'NR==(y+1) {print substr($0,(x+1),1);exit}')" | |
else | |
c=" " | |
fi | |
printf "${cursor_restore}" | |
[ "${x}" -gt 0 ] && printf "\033[${x}C" | |
[ "${y}" -gt 0 ] && printf "\033[${y}B" | |
printf "${color}%s${cursor_left}" "${c}" | |
} | |
spin() { | |
max="$(echo "${order}" | wc -l)" | |
printf "\033[4C\033[2B${norm_color}_" | |
h=$((max/2)) | |
n=$((h-2)) | |
b=0 | |
while :; do | |
h=$((h+1)) | |
n=$((n+1)) | |
b=$((b+1)) | |
[ "${h}" -gt "${max}" ] && h=1 | |
[ "${n}" -gt "${max}" ] && n=1 | |
[ "${b}" -gt "${max}" ] && b=1 | |
draw "${h}" "${high_color}" | |
draw "${n}" "${norm_color}" | |
draw "${b}" "" | |
usleep "${delay_usec}" | |
done | |
} | |
clear | |
printf "${cursor_hide}" | |
printf "${cursor_save}" | |
stty -echo | |
printf "\n\n\n\n\n(input will be invisible because this is an ugly hack)\nprompt:" | |
printf "${cursor_restore}" | |
spin & | |
export pid="${!}" | |
trap 'kill "${pid}"; stty echo' EXIT INT | |
read input | |
printf "${cursor_show}" | |
kill "${pid}" ; trap '' EXIT INT | |
reset | |
echo "you entered: ${input}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment