登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

There's always a way

out. You just have to find it.

 
 
 

日志

 
 

ANSI escape sequences  

2011-04-21 17:18:48|  分类: LINUX&Shell |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

      ANSI escape sequences are characters embedded in the text used to control formatting, color, and other output options on video text terminals. Almost all terminal emulators designed to show text output from a remote computer, and (except for Windows) to show text output from local software, interpret at least some of the ANSI escape sequences.

      By default what ever you send to console it is printed as its. For e.g. consider following echo statement,
$ echo "Hello World"
Hello World
      Above echo statement prints sequence of character on screen, but if there is any special escape sequence (control character) in sequence , then first some action is taken according to escape sequence (or control character) and then normal character is printed on console. For e.g. following echo command prints message in Blue color on console
$ 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.

 

      Escape sequences start with the character ESC (ASCII decimal 27/hex 0x1B/octal 033). 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

 

      In above syntax you have to use\033[ as its with different escape-code for different operations. As soon as console receives the message it start to process/read it, and if it found escape character (\033) it moves to escape mode, then it read "[" character and moves into Command Sequence Introduction (CSI) mode. In CSI mode console reads a series of ASCII-coded decimal numbers (know as parameter) which are separated by semicolon (;) . This numbers are read until console action letter or character is not found (which determines what action to take).

 

Character or letter

Use in CSI

Examples

h

Set the ANSI mode

echo -e "\033[h"

l

Clears the ANSI mode

echo -e "\033[l"

m

Useful to show characters in different colors or effects such as BOLD and Blink, see below for parameter taken by m.

echo -e  "\033[35m Hello World"

q

Turns keyboard num lock, caps lock, scroll lock LED on or off, see below.

echo -e "\033[2q"

s

Stores the current cursor x,y position (col , row position) and attributes

echo -e "\033[7s"

u

Restores cursor position and attributes

echo -e "\033[8u"

 

And m understood following parameters:

0

reset all attributes to their defaults

1

set bold

2

set half-bright (simulated with color on a color display)

4

set underscore (simulated with color on a color display)(the colors used to simulate dim or underline are set using ESC ] ...)

5

set blink

7

set reverse video

10

reset selected mapping, display control flag, and toggle meta flag (ECMA-48 says "primary font").

11

select null mapping, set display control flag, reset toggle meta flag (ECMA-48 says "first alternate font").

12

select null mapping, set display control flag, set toggle meta flag (ECMA-48 says "second alternate font"). The toggle   meta flag causes the high bit of a byte to be toggled before the mapping table translation is done.

21

 set normal intensity (ECMA-48 says "doubly underlined")

22

set normal intensity

24

underline off

25

blink off

27

reverse video off

30

set black foreground

31

set red foreground

32

set green foreground

33

set brown foreground

34

set blue foreground

35

set magenta foreground

36

set cyan foreground

37

set white foreground

38

set underscore on, set default foreground color

39

set underscore off, set default foreground color

40

set black background

41

set red background

42

set green background

43

set brown background

44

set blue background

45

set magenta background

46   

set cyan background

47

set white background

49

set default background color

 

  评论这张
 
阅读(2337)| 评论(1)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018