You are on page 1of 10

Linux console

The Linux
console provides
a way for the
kernel and other
processes to
send text output
to the user, and
to receive text
input from the
user.
Capability databases

The actions controlled by the escape


sequences are often called capabilities .

Two databases that describe terminals in


terms of the capabilities:
• Termcap
• Terminfo
Linux console capabilities
printf("this is a line\na \033[1mbold\033[0m word\n");

Starting from the current cursor position, the console prints the words " this is a
line ".

\n control character - moves the cursor to the beginning of the next line and
displays “a”

It reads the " [ "character, and moves into Command Sequence Introduction (CSI)
mode.
In CSI mode, it reads a series of ASCII-coded decimal numbers separated
by " ; ", which are called parameters, until a letter is encountered .

The letter determines what action to take, modified by the data in the
parameters.

In this case, there is one parameter, " 1 ", and the letter " m " means
that the parameter is used to determine character rendition ; the " 1
" sets the bold attribute on.
prints the string " bold " in a Another character rendition
bold rendition. sequence follows , which resets all
attributes to their default, so it
prints " word " in a normal rendition.
Control characters
Control Character ASCII Name Description
^G BEL Sounds a tone
^H BS Moves cursor to
previous character
without overwriting it if
the cursor is not in the
first column already
^I HT Horizontal tab;
^J LF Line feed;
^K VT Vertical tab
^L FF Form feed; treated like
a line feed
^M CR Carriage return; moves
Control sequences
Control sequence Description
^[M Reverse line feed
^[D Line feed
^[E Carriage return and line feed
^[H Set tab stop
^[7 Store cursor
^[8 Restore cursor
^[> Switch keypad to numeric mode
^[= Switch keypad to application mode
^[c Reset terminal settings
^[Z Print terminal ID
Testing sequences

Cat > /tmp/somefile

Type the commands followed by return


& ^D.
$ echo -e "\033[34m   Hello Colorful  World!"
Hello Colorful  World!

Above echo statement uses ANSI escape sequence (\033[34m), above entire string ( i.e.  "\
033[34m   Hello Colorful  World!" ) is process as follows

1) First \033, is escape character, which causes to take some action


2) Here it set screen foreground color to Blue using [34m escape code.
3) Then it prints our normal message Hello Colorful  World! in blue color.

Note that ANSI escape sequence begins with \033 (Octal value) which is represented as ^[ in
termcap and terminfo files of terminals and documentation.
You can use echo statement to print message, to use ANSI escape sequence you must use -
e option (switch) with echo statement, general syntax is as follows
Syntax
echo   -e  "\033[escape-code    your-message"
\033 Escape character

[Start of CSI

34 is parameter

m is letter (specifies action)

You might also like