Skip to content

Instantly share code, notes, and snippets.

@fuzzy
Created May 28, 2020 06:23
Show Gist options
  • Save fuzzy/9a9b49d6c34a2384fa06cd9eb93c094e to your computer and use it in GitHub Desktop.
Save fuzzy/9a9b49d6c34a2384fa06cd9eb93c094e to your computer and use it in GitHub Desktop.
drawing text boxes with Sh and printf
#!/bin/sh -e
clr="\033[0m"
pad=" "
spad=" "
setbg() {
echo "\033[1;${1};${2}m"
}
setyx() {
echo "\033[${1};${2}H"
}
clear
left_row=10
left_col=20
for color in 41 42 43 44 45 46; do
printf "$(setyx ${left_row} ${left_col})$(setbg ${color} 37)${pad}${pad}"
printf "$(setyx $((${left_row}+1)) ${left_col})$(setbg ${color} 37)${pad}${pad}"
printf "$(setyx $((${left_row}+2)) ${left_col})$(setbg ${color} 37)${pad}${pad}"
printf "$(setyx $((${left_row}+3)) ${left_col})$(setbg ${color} 37)${spad}TEST${spad}"
printf "$(setyx $((${left_row}+4)) ${left_col})$(setbg ${color} 37)${pad}${pad}"
printf "$(setyx $((${left_row}+5)) ${left_col})$(setbg ${color} 37)${pad}${pad}"
printf "$(setyx $((${left_row}+6)) ${left_col})$(setbg ${color} 37)${pad}${pad}"
left_col=$((left_col - 2))
left_row=$((left_row - 1))
sleep 1
done
printf "$(setyx 17 1)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment