Never been to TextSnippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)

TPUT and TERMINFO (See related posts)

Using the command line as UI ? try to remember some of these useful commands !

# save cursor position
tput sc
# move cursor to 10th line and 20th column
tput cup 10 20
# write some text from here in standout mode
tput smso
echo "j ecris a partir de la 10eme ligne et la 20eme colonne"     
# restore cursor position
tput rc
# exit from standout mode
tput rmso


Some more advanced stuff can be done :
# save your prompt
PS1_SAVE=$PS1
# set the prompt to blank
PS1=''
# save the number of colums of the terminal
COLUMNS=$(tput cols)
# save the number of lines of the terminal
LINES=$(tput lines)
# set the message you want to display (here it's "hello I am at the center of the term")
message="coucou je suis au milieu du terminal"
# get the horizontal position to center your text
hpos=$(expr $LINES / 2)
# get the vertical position to center your text
vpos=$(expr \( $COLUMNS - $(echo "$message" | wc -c) \) / 2)
# move the cursor to that position
tput cup $hpos $vpos
# enter in reverse video mode
tput rev
# display the message
echo "$message"
# wait for 3 second to see the message
sleep 3
# recall your default prompt
PS1=$PS1_SAVE
# reset all terminal settings
tput sgr0
# clear the screen
tput clear

You need to create an account or log in to post comments to this site.


Related Posts