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!)

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed 

TPUT and TERMINFO

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

Windows' command prompt : How to DEFINITELY change default codepage

Want to use WinLatin1 (1252) instead of DOSLatin1 (850, default when cmd.exe is started) ?

You want to apply the new codepage to :
- the current opened command prompt
C:\> chcp 1252

- all the opened command prompt in the future
Start->Run->regedit
Go to [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Nls\CodePage]
And change the "OEMCP" value to "1252"

You need to restart your computer to see the changes.

So you'll be able to display extended characters (such as accents and so on)

==

Don't know how to check the command prompt's codepage ?
C:\> chcp


==

Want to see the result in practice ?
Edit a codepage.txt file and type "à la bonne heure, ça marche ! (peut être)", then open a command prompt and check this out :
C:\> type codepage.txt

« Newer Snippets
Older Snippets »
2 total  XML / RSS feed