02. ANSI/VT100终端控制转义序列

2019-02-28  本文已影响25人  杨强AT南京

Many computer terminals and terminal emulators support colour and cursor control through a system of escape sequences. One such standard is commonly referred to as ANSI Colour. Several terminal specifications are based on the ANSI colour standard, including VT100.

The following is a partial listing of the VT100 control set.

<ESC> represents the ASCII "escape" character, 0x1B. Bracketed tags represent modifiable decimal parameters; eg. {ROW} would be replaced by a row number.


Device Status

  The following codes are used for reporting terminal/display settings, and vary depending on the implementation:

Query Device Code <ESC>[c
Report Device Code <ESC>[{code}0c
Query Device Status <ESC>[5n
Report Device OK <ESC>[0n
Report Device Failure <ESC>[3n
Query Cursor Position <ESC>[6n
Report Cursor Position <ESC>[{ROW};{COLUMN}R

Terminal Setup

The h and l codes are used for setting terminal/display mode, and vary depending on the implementation. Line Wrap is one of the few setup codes that tend to be used consistently:

Reset Device <ESC>c
Enable Line Wrap <ESC>[7h
Disable Line Wrap <ESC>[7l

Fonts

Some terminals support multiple fonts: normal/bold, swiss/italic, etc. There are a variety of special codes for certain terminals; the following are fairly standard:

Font Set G0 <ESC>(
Font Set G1 <ESC>)

Cursor Control

Cursor Home <ESC>[{ROW};{COLUMN}H
Cursor Up <ESC>[{COUNT}A
Cursor Down <ESC>[{COUNT}B
Cursor Forward <ESC>[{COUNT}C
Cursor Backward <ESC>[{COUNT}D
Force Cursor Position <ESC>[{ROW};{COLUMN}f
Save Cursor <ESC>[s
Unsave Cursor <ESC>[u
Save Cursor & Attrs <ESC>7
Restore Cursor & Attrs <ESC>8

Scrolling

Scroll Screen <ESC>[r
Scroll Screen <ESC>[{start};{end}r
Scroll Down <ESC>D
Scroll Up <ESC>M

Tab Control

Set Tab <ESC>H
Clear Tab <ESC>[g
Clear All Tabs <ESC>[3g

Erasing Text

Erase End of Line <ESC>[K
Erase Start of Line <ESC>[1K
Erase Line <ESC>[2K
Erase Down <ESC>[J
Erase Up <ESC>[1J
Erase Screen <ESC>[2J

Printing

Some terminals support local printing:

Print Screen <ESC>[i
Print Line <ESC>[1i
Stop Print Log <ESC>[4i
Start Print Log <ESC>[5i

Define Key

Set Key Definition <ESC>[{key};"{string}"p

Set Display Attributes

Set Attribute Mode <ESC>[{attr1};...;{attrn}m

上一篇 下一篇

猜你喜欢

热点阅读