Print at specific coordinates
With cup
, it's possible to echo
a string at specific coordinates:
function print_at {
x=$1
y=$2
text=$3
# Note: first the row, then the column:
tput cup $y $x; printf "$text (x=$x, y=$y)"
}
clear
print_at 5 10 "hello world"
print_at 8 3 "twenty-four"
print_at 30 8 "bit to the left"
print_at 50 6 "more to the left"
print_at 0 20 "finish"
Decorating text
Text can be decorated with a bold or underlined attribute:
y=2
function display_text {
capname=$1
tput sgr0 # Turn off all attributes
tput cup $y 3; printf "This is ";
tput $capname; printf $capname;
y=$((y+2)) # move y coordinate downj
}
clear
display_text bold
display_text smul # underlined text. Can be ended with rmul.
display_text blink # should blink. Does not always work.
display_text invis # invisible text