Table of Contents
If you want to send us your comments, please do so. Thanks
More on comments
Bash colors and cursor movements
Show what the terminal is capable of: msgcat --color=test
You can show what terminal you have with echo $TERM
When used with echo use echo -e
tput can also be used
Code | Explanation |
---|---|
\e | Code for the escape character. See also \033 (octal) |
\n | New line |
\r | Move to the beginning of the line |
\t | Tab |
\v | Vertical tab |
\033 | C-style octal code for the escape character |
\x1B | hex code for the escape character |
[9D | Moves the cursor back 9 columns |
[2K | Erases the current line |
echo -e “\e[20A” | Moves the cursor 20 lines up |
echo -e “\e[20F” | Moves the cursor 20 lines up and to position 1 |
echo -e “\eD” | Linefeed |
\e[ | CSI Control sequence introducer |
\x9B | CSI. Is equivalent to “ESC [”. Does not seem to work in bash |
Syntax
The default syntax
echo -e "\033[MODIFIER;BACKGROUND;FOREGROUNDmTEXT\033[00m"
See Colors for more ways
Colors
A line with a new line and colored text can be made with
echo -e "\e[32mGreen text on the default background\e[0m" echo -e "\n\033[01;44;37mWhite bold text on a blue background\033[00m" echo -e '\n\e[32;40m'"\e[1mGreen bold text on a black background color\e[0m" for i in {0..255}; do printf "\x1b[38;5;${i}mcolour${i}\x1b[0m\n"; done
Foreground colors
For background colors replace the leading 3 with a 4
Color | Code | Light color | Code |
---|---|---|---|
Black | 0;30 | Dark Gray | 1;30 |
Red | 0;31 | Light Red | 1;31 |
Green | 0;32 | Light Green | 1;32 |
Brown | 0;33 | Yellow | 1;33 |
Blue | 0;34 | Light Blue | 1;34 |
Magenta | 0;35 | Light Magenta | 1;35 |
Cyan | 0;36 | Light Cyan | 1;36 |
Light Gray | 0;37 | White | 1;37 |
Show them (the echo statement makes a new ling)
printf '\e[%sm ' {40..47} 0; echo
Modifiers
Modifier | Effect | Remark |
---|---|---|
\e[0m | Default | Color off |
\e[1m | Bold | |
\e[2m | Half intensity | |
\e[3m | Italic | |
\e[4m | Underline | |
\e[5m | Blink | |
\e[6m | Normal | |
\e[7m | Inverted | |
\e[8m | Hidden | |
\e[9m | Strike trough |
Parameters
Parameters are used in 24 bit color schemes. In
echo -e "\e[48;2;128;34;177m"
the '2' is the parameter
Parameter | Explanation |
---|---|
0 | Defined by the implementation |
1 | Transparent |
2 | Red Green Blue (optional). This is used in 24 bit color schemes. Example: ESC[48;2;128;34;177m Sets the background color. Command: echo -e "\e[48;2;128;34;177m" |
3 | Cyan Magenta Yellow (optional) |
4 | Cyan Magenta Yellow Black (optional) |
5 | 0-255 indexed color. This is used in 8 bit color schemes. Example: ESC[48;5;177m Sets the background color and underlines. Command: echo -e "\e[48;5;177m\e[4m" |
6 | |
7 | |
8 | |
9 |
tput
tput, reset - initialize a terminal or query terminfo database
tput is an interface to the terminfo library
Option | Function |
---|---|
cup x y | Move the cursor to position x,y |
clear | Echo the clear-screen sequence for the current terminal |
cols | Print the number of columns for the current terminal |
rc | Restores the cursor where tput sc was called |
sc | Saves the current cursor position |
Useful links and info
Info
man console_codes - Linux console escape and control sequences
man termcap - terminal capability database
man terminfo - terminal capability data base
useful links
VT ANSI
ANSI Escape Sequences Chapter 6: Colours and Cursor Movement:
6.1. Colours
6.2. Cursor Movement
and
All-escapes
ANSI escape code on Wikipedia
Bash tip colors and formatting
Terminalcodes
man 4 console codes
tput
Bash Prompt customization
Colours and Cursor Movement With tput
Discover tput
Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy
RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2024 Webevaluation.nl and the authors
Changes reserved.