console_codes 中文man页面

系统
Linux控制台实现了VT102和ECMA-48/ISO 6429/ANSI X3.64终端控制的子集, 这个子集很庞大,当然还有Linux自己私有的控制序列,以改变颜色配置,字符集映像,等等.在下面将要给出的表格中,第二列为指定的功能给出了ECMA-48 或者DEC助记符(如果是后者会在前面加有DEC前缀).没有给出助记符的序列既不是ECMA-48也不是VT102字符.

NAME 名称

控制终端代码 - Linux 控制终端转义和控制序列  

DESCRIPTION 描述

Linux控制台实现了VT102和ECMA-48/ISO 6429/ANSI X3.64终端控制的子集, 这个子集很庞大,当然还有Linux自己私有的控制序列,以改变颜色配置,字符集映像,等等.在下面将要给出的表格中,第二列为指定的功能给出了ECMA-48 或者DEC助记符(如果是后者会在前面加有DEC前缀).没有给出助记符的序列既不是ECMA-48也不是VT102字符.

在所有标准输出进程执行完毕,并且一个字符流被送到控制台驱动程序准备显示出来的时候,所发生的第一件事就是将进程使用的代码转换成显示使用的代码.

如果控制台工作于 UTF-8 模式,那么输入的字节会首先编码成16位的 Unicode 代码.如果不是UTF-8模式,那么每个字节会按照当前的字符映射表完成转换(转换成Unicode编码的值). 参看下面将要讨论的 CHARACTER SETS 一章. 在一般情况下,Unicode 代码被转换成为存储在视频存储器中的字体索引,这样对应的具体字符(字符存储在视频ROM中)就显示在屏幕上了. 注意使用 Unicode 编码允许我们同时使用 512 种不同的字体(和计算机硬件有关).

如果当前的 Unicode 代码是一个控制字符,或者系统目前正在处理一个转义序列,处理的方式有些特别.它不会被转换成字体索引,也不会直接显示在屏幕上.它可能控制光标的移动,或者实现其它控制功能.参看下面的 LINUX CONSOLE CONTROLS 一节所进行的讨论.

一般来说直接在程序中插入终端控制字符并不是很好.Linux 支持终端兼容的 terminfo(5) 数据库. 除了直接插入控制和转义序列,也可以使用象 ncurses(3), tput(1), 或者 reset(1). 这样的显示库或者工具.

LINUX CONSOLE CONTROLS Linux终端控制

这一段描述了所有在Linux控制台下使用的调用特殊功能的控制字符和转义序列(例如.任何不在当前光标处插入可见字符的序列).  

Control characters 控制字符

当一个字符在通过字符映射表转换之前含有以下14个代码之一的时候表明它是一个控制字符. 00(NUL),07(BEL),08(BS),09(HT),0a(LF),0b(VT), 0c(FF),0d(CR),0e(SO),0f(SI),18(CAN),1a(SUB), 1b(ESC),7f(DEL). 我们可以通过设置 `显示控制字符' 模式(见下文)以允许07,09,0b, 18,1a,7f 像普通字符一样显示在屏幕上.另一方面,在UTF-8模式下所有位于 00-1f之间的代码都被认为是控制字符,而不管是否处于 `显示控制字符'模式.

一个控制字符会立刻生效,然后被丢弃(即使是在转义序列中间), 之后转义序列才继续处理下一个字符. (在任何情况下,ESC都表示一个新的转义序列的开始,可能导致 前一个序列的非正常终止,CAN和SUB 终止任何转义序列.) 可识别的控制字符是BEL,BS,HT,LF,VT,FF,CR,SO,SI,CAN, SUB,ESC,DEL,CSI.他们的功能如下.:

BEL(0x07,^G)铃声;
BS(0x08,^H)后退一格(在行首不起作用);
HT(0x09,^I)跳至下一个制表位.如果后面已没有制表位则跳至行尾;
LF(0x0A,^J),VT(0x0B,^K),FF(0x0C,^L)三者都表示换行;
CR(0x0D,^M)回车并换行;
SO(0x0E,^N)激活 G1 字符集, 如果设置了 LF/NL(新行模式)还要加上回车换行;
SI(0x0F,^O)激活 G0 字符集;
CAN(0x18,^X),SUB(0x1A,^Z)两者都表示中断转义序列;
ESC(0x1B,^[)开始一个新的转义序列;
DEL(0x7F)忽略;
CSI(0x9B)等同于 ESC [;

ESC- but not CSI-sequences 非控制转义序列

ESC c RIS 重绘屏幕.
 
ESC D IND 换行.
 
ESC E NEL 新的一行.
 
ESC H HTS 设置当前列为制表位.
 
ESC M RI 翻转换行(Reverse linefeed).
 
ESC Z DECID DEC 私有定义.内核将其解释为
 
    VT102字符,返回字符ESC [ ? 6 c.
 
ESC 7 DECSC 存储当前状态(光标坐标,
 
    属性,字符集).
 
ESC 8 DECRC 恢复上一次储存的设置
 
ESC [ CSI 控制序列介绍
 
ESC %   开始一个字符集选择序列
 
ESC % @    选择默认字符集(ISO 646 / ISO 8859-1)
 
ESC % G      选择 UTF-8
 
ESC % 8      选择 UTF-8(已不用)
 
ESC # 8 DECALN DEC 屏幕校准测试 - 以E's填充屏幕.
 
ESC(   开始一个 G0 字符集定义序列
 
ESC( B      选择默认字符集(ISO 8859-1 mapping)
 
ESC( 0      选择 vt100 图形映射
 
ESC( U      选择空映射 - 直接访问字符ROM
 
ESC( K      选择用户映射 - 由程序mapscrn(8)
 
       加载.
 
ESC )   开始一个 G1 字符集定义
 
    (后面跟 B,0,U,K,同上).
 
ESC > DECPNM 设置数字小键盘模式
 
ESC = DECPAM 设置程序键盘模式
 
ESC ] OSC (是perating system command的缩写)
 
    ESC ] P nrrggbb: 设置调色板,后面紧跟7个
 
    十六进制数,再跟一个 P :-(.
 
    这里 n 是颜色(0-16),而 rrggbb 表示
 
    红/绿/蓝 值(0-255).
 
    ESC ] R: 重置调色板
 
 

ECMA-48 CSI sequence ECMA-48 CSI 序列

CSI(或者 ESC [)后面跟的参数序列大部分是NPAR(16), 就是由分号隔开的十进制数.空参数或缺少的参数以0处理. 可以用一个问号代替参数序列.

在任何情况下,系统读取 CSI [(或者 ESC [ [)后的单个字符, 而忽略整个序列.(用于忽略回显功能键.)

CSI 序列的动作由其最后一个字符决定.

@ ICH 用#符号指示空格.
 
A CUU 光标上移到#标识的行.
 
B CUD 光标下移到#标识的行.
 
C CUF 光标右移到#标识的列.
 
D CUB 光标左移到#标识的列.
 
E CNL 将光标下移到#指示的行的第一列.
 
F CPL 将光标上移到#指示的行的第一列.
 
G CHA 光标移动到当前行的指定列.
 
H CUP 光标移动到指定行和列(以1行1列为参照).
 
J ED 删除(默认从当前光标处到行尾的)内容.
 
    ESC [ 1 J: 删除从开始到光标处的内容.
 
    ESC [ 2 J: 清空整个屏幕.
 
K EL 删除行(默认从当前光标处到结尾).
 
    ESC [ 1 K: 删除从行首到当前光标处的内容.
 
    ESC [ 2 K: 删除整行.
 
L IL 在空行插入#.
 
M DL 删除#标记的行.
 
P DCH 删除当前行中#标记的字符.
 
X ECH 删除当前行中#标记的单词.
 
a HPR 光标移动到#标记的右边.
 
c DA 以`I am a VT102'应答 ESC [ ? 6 c:
 
d VPA 光标移动到当前列指定行
 
e VPR 光标移动到#标记的下一行.
 
f HVP 光标移动到指定的行和列.
 
g TBC 没有参数: 清除当前位置的制表站.
 
    ESC [ 3 g: 删除所有制表站.
 
h SM 设置模式(见下文).
 
l RM 重置模式(见下文).
 
m SGR 设置属性(见下文).
 
n DSR 状态报告(见下文).
 
q DECLL 设置键盘指示灯.
 
    ESC [ 0 q: 熄灭所有指示灯
 
    ESC [ 1 q: 点亮 Scroll Lock 灯
 
    ESC [ 2 q: 点亮 Num Lock 灯
 
    ESC [ 3 q: 点亮 Caps Lock 灯
 
r DECSTBM 设置滚动范围; 参数为首行和末行.
 
s ? 存储光标位置.
 
u ? 恢复光标位置.
 
` HPA 光标移动到当前行指定列.
 
 

ECMA-48 Set Graphics Rendition 设置图形属性

ECMA-48 SGR 序列 ESC [ <parameters> m 设置显示属性. 同样的序列可以设置一个或多个属性.

par 作用
 
0 所有属性重设为默认值
 
1 设置边框
 
2 设置亮度减半(用一种颜色模拟另一种颜色)
 
4 设置底纹(用一种颜色模拟另一种颜色)
 
  (用于模拟的颜色由using ESC ] ...设置)
 
5 设置闪烁
 
7 设置反转视频(reverse video)
 
10 重设选定映像,显示控制标记,
 
  反转元素标记.
 
11 选择空映像,设置显示控制标记,
 
  重设反转标记.
 
12 选择空映像,设置显示控制标记,
 
  重设反转标记.(在完成映像表转
 
  换之前反转标记引起每一字节的
 
  高位反转.)
 
21 设置正常亮度(和 ECMA-48 不兼容)
 
22 设置正常亮度
 
24 关闭下划线
 
25 不闪烁
 
27 反转视频关闭
 
30 黑色背景
 
31 红色前景
 
32 绿色前景
 
33 棕色前景
 
34 蓝色前景
 
35 品红前景
 
36 孔雀蓝前景
 
37 白色前景
 
38 打开下划线,设置默认前景色
 
39 关闭下划线,设置默认前景色
 
40 黑色背景
 
41 红色背景
 
42 绿色背景
 
43 棕色背景
 
44 蓝色背景
 
45 品红背景
 
46 孔雀蓝背景
 
47 白色背景
 
49 设置默认背景色
 
 

ECMA-48 Mode Switches ECMA-48模式选择

ESC [ 3 h
DECCRM(默认关闭): 显示控制字符.
ESC [ 4 h
DECIM(默认关闭): 设置插入模式.
ESC [ 20 h
LF/NL(默认关闭): 自动在CR后加上 LF,VT 或者 FF.

ECMA-48 状态报告命令.

ESC [ 5 n
设备状态报告(DSR): 以 ESC [ 0 n 应答(终端准备好).
ESC [ 6 n
光标位置报告(CPR): 以ESC [ y ; x R 应答, 这里 x,y 指光标位置.

DEC Private Mode(DECSET/DECRST)sequences DEC私有模式序列.

这里给出的序列在 ECMA-48中没有描述.我们列出了设置模式序列; 用l替换最后一个h就是重设模式序列.

ESC [ ? 1 h
DECCKM(默认关闭): 打开时光标键送出 ESC O 前缀, 而不是 ESC [.
ESC [ ? 3 h
DECCOLM(默认 = 80 行): 交替选择 80/132 行模式.当原显示模式不足以满足要求的时候,象 resizecons(8) 这样的用户程序会改变终端显示卡的硬件注册.
ESC [ ? 5 h
DECSCNM(默认关闭): 设置视频反转模式.
ESC [ ? 6 h
DECOM(默认关闭): 打开时,光标位置用相对于滚动条左上角的位置表示.
ESC [ ? 7 h
DECAWM(默认关闭): 打开自动换行.在这种模式下,一行中超过80列的字符将自动换行(在DECCOLM打开时是132列).
ESC [ ? 8 h
DECARM(默认关闭): 打开键盘自动重复.
ESC [ ? 9 h
X10 鼠标报告(默认关闭): 设置报告模式 1(或者重设为 0)- 见下文.
ESC [ ? 25 h
DECCM(默认打开): 设置光标可见.
ESC [ ? 1000 h
X11 鼠标报告(默认关闭): 设置报告模式 2(或者重设为 0)- 见下文.

Linux Console Private CSI Sequences Linux控制台私有控制序列

下面的序列既不属于 ECMA-48 字符也不属于 VT102.它们只在 Linux控制台上使用.颜色采用 SGR 参数: 0 = 黑色,1 = 红色,2 = 绿色,3 =褐色 ,4 = 蓝色,5 = 洋红,6 = 孔雀蓝,7 = 白色.

ESC [ 1 ; n ] 设置下划线颜色为 n
 
ESC [ 2 ; n ] 设置暗色为 n
 
ESC [ 8 ] 设置当前颜色对为默认属性.
 
ESC [ 9 ; n ] 设置屏幕空白超时为 n 分钟.
 
ESC [ 10 ; n ] 设置机箱喇叭鸣叫频率,单位: Hz.
 
ESC [ 11 ; n ] 设置机箱喇叭鸣叫持续时间,单位:微秒.
 
ESC [ 12 ; n ] 设置指定控制台前台运行.
 
ESC [ 13 ] 设置指定控制台黑色
 
ESC [ 14 ; n ] 设置 VESA 关闭间隔,单位: 分钟.
 

CHARACTER SETS 字符集

内核可以完成以下四种字符转换,使字符能在屏幕上显示. a)Latin1 -> PC,b)VT100 graphics -> PC,c)PC -> PC, d)user-defined(用户自定义).

有两种字符集设置,以 G0 和 G1定义,当前字符集必定是其中之一.(初始化为G0.)键入 ^N 使 G1 成为当前字符集,键入 ^O 使 G0 成为当前设置.

变量 G0 and G1 指向字符映射关系表,并且这种指向关系可以由用户改变. 系统初始化时它们分别指向表 a)and b). 序列 ESC( B ,ESC( 0 ,ESC( U 和 ESC( K 分别使 G0 指向字符映射表
 a),b),c)和 d). 序列 ESC )B ,ESC )0 ,ESC )U 和 ESC )K 分别使 G1 指向字符映射表 a),b),c)和 d).

序列 ESC c 重置一个终端,当屏幕显示出现混乱时可以使用这个序列. 另一个序列 "echo ^V^O" 仅仅将G0设为当前字符集,但并不保证 G0 指向映射表 a). 有的Linux发行版中提供一个叫做 reset(1) 的程序用来送出序列 "echo ^[c". 如果你的系统终端变量没有错误( rs1=\Ec), 那么使用"tput reset"也可以达到同样效果.

用户自定义映射表可以用程序 mapscrn(8). 定义.这个程序工作时会将送入的字符c通过关系式s=map[c]映射到字符s然后送入显存.字符s所对应的位图放在字符ROM里面,可以使用程序 setfont(8).

来改变.

MOUSE TRACKING 鼠标轨迹

鼠标轨迹工具可以返回与 xterm 兼容的鼠标状态报告.因为控制台驱动没有办法知道鼠标类型,只有当虚拟终端驱动接收到鼠标输入输出消息更新时才会将这些报告返回给控制台输入流..这些鼠标输入输出消息由 gpm(8) 守护进程产生.

所有鼠标轨迹转义序列参数由xterm 编码成象value+040 这样的单一字符形式的数字参数.比如,`!' 编码成 1.屏幕坐标系统以'1'为基准.

X10 兼容模式在鼠标键按下时将按下的键和鼠标位置编码后送出. ESC [ ? 9 h 允许这一动作,ESC [ ? 9 l禁止这一动作. 有键按下时,xterm 送出ESC [ M bxy(6 个字符).这里 b 代表 键-1,而 xy 是鼠标的 x 和 y 坐标.这和内核产生的序列相同.

常规的轨迹模式(Linux 2.0.24不再支持)在左右两键同时按下然后释放时送出转义序列.组合键编码也被送出.ESC [ ? 1000 h 允许这个动作而ESC [ 1000 l 禁止这个动作.当有键按下或者释放时, xterm 送出 ESC [ M bxy.b 的低两位对按键信息编码: 0=鼠标键1按下,1=鼠标键2 按下,2=鼠标键3 按下,3=释放. 高位编码代表组合键,和上述编码一起送出: 4=Shift,8=Meta(Alt),16=Control(Ctrl).xy为发生鼠标事件的x和y坐标.以左上角为(1,1).

和其它终端的比较

我们已经讨论了几种终端类型,比如Linux 控制台.这类终端称为 "VT100兼容"的终端.这里我们再介绍其他两种重要的终端类型: DEC VT102 和 xterm(1) 以及他们和Linux控制终端的区别.

Control-character handling 控制字符处理

vt102 也使用以下控制序列:

NUL(0x00)忽略;
ENQ(0x05)触发应答消息;
DC1(0x11,^Q,XON)继续传送;
DC3(0x13,^S,XOFF)使 vt100 忽略(并停止传送) 除 XOFF and XON 以外的一切字符.

VT100-like DC1/DC3 进程可以由 tty 驱动激活.

程序 xterm (在 vt100 模式 中)使用控制序列 BEL,BS,HT,LF,VT,FF,CR,SO,SI,ESC.

Escape sequences 转义序列

VT100 控制台序列不完全支持Linux控制台序列:

ESC N SS2 仅仅为下一个字符选择 G2 字符集
 
    (Single shift 2).
 
ESC O SS3 仅仅为下一个字符选择 G2 字符集
 
    (Single shift 2).
 
ESC P DCS 设备控制字符,由ESC \ 终止
 
    (Device control string).
 
ESC X SOS 字符串开始.
 
    (Start of string)
 
ESC ^ PM 私有消息,由 ESC \ 终结
 
    (Privacy message)
 
ESC \ ST 字符串终结
 
    (String terminator)
 
ESC * ...   指定 G2 字符集
 
ESC + ...   指定 G3 字符集
 

程序 xterm (vt100 模式)承认 ESC c,ESC # 8,ESC >,ESC =, ESC D,ESC E,ESC H,ESC M,ESC N,ESC O,ESC P ...ESC , ESC Z(以 [ ? 1 ; 2 c,`I am a vt100 with advanced video option'回应) 以及 ESC ^ ...ESC ,意义同上. 接受 ESC(,ESC ),ESC *,ESC + 后跟 0,A,B 的字符序列,分别代表的DEC 特殊字符,画线设置,UK 和 US ASCII码. 接受 ESC ] 作为特定资源设置:

ESC ] 0 ; txt BEL 将图标名和窗口标题设为文本.
 
ESC ] 1 ; txt BEL 将图标名设为文本.
 
ESC ] 2 ; txt BEL 将窗口名设为文本.
 
ESC ] 4 6 ; name BEL 改变日志文件名(一般
 
  由编译时选项禁止)
 
ESC ] 5 0 ; fn BEL 字体设置为 fn.
 

以下字符的含义略有不同::

ESC 7 DECSC 存储光标位置
 
ESC 8 DECRC 恢复光标位置
 

它还接受以下序列:

ESC F   光标移动到屏幕左下角(由
 
    hpLowerleftBugCompat 打开这项设置)
 
ESC l   内存锁定(对于 HP 终端).
 
    锁定光标以上的内存.
 
ESC m   内存解锁(对于 HP 终端).
 
ESC n LS2 调用 G2 字符集.
 
ESC o LS3 调用 G3 字符集.
 
ESC | LS3R 以GR调用 G3 字符集.
 
    在xterm上看不到效果.
 
ESC } LS2R 以GR调用 G3 字符集.
 
    在xterm上看不到效果.
 
ESC ~ LS1R 以GR调用 G3 字符集.
 
    在xterm上看不到效果.
 

它不识别 ESC % ...

CSI Sequences CSI 序列

程序 xterm (直到 XFree86 3.1.2G)不能识别闪烁或者不可见模式的 SGR值.X11R6 也不能识别以 SGRs 为参数设置的色彩. xterm 可以识别其他的 ECMA-48 CSI 序列,只要Linux可以识别. 反之亦然.

xterm 可以识别以上列出的所有 DEC 私有序列,但是不包括 Linux 私有模式序列. 在 Xterm Control Sequences 中有关于 xterm 的私有模式序列的讨论.

document by Edward Moy and Stephen Gildea,available with the X distribution.

BUGS

在版本为 2.0.23 的内核中,CSI 序列的识别有些问题: 不能识别转义序列中的NUL.

参见

console(4), console_ioctl(4), charsets(7)

#p#

NAME

console_codes - Linux console escape and control sequences  

DESCRIPTION

The Linux console implements a large subset of the VT102 and ECMA-48/ISO 6429/ANSI X3.64 terminal controls, plus certain private-mode sequences for changing the color palette, character-set mapping, etc. In the tabular descriptions below, the second column gives ECMA-48 or DEC mnemonics (the latter if prefixed with DEC) for the given function. Sequences without a mnemonic are neither ECMA-48 nor VT102.

After all the normal output processing has been done, and a stream of characters arrives at the console driver for actual printing, the first thing that happens is a translation from the code used for processing to the code used for printing.

If the console is in UTF-8 mode, then the incoming bytes are first assembled into 16-bit Unicode codes. Otherwise each byte is transformed according to the current mapping table (which translates it to a Unicode value). See the CHARACTER SETS section below for discussion.

In the normal case, the Unicode value is converted to a font index, and this is stored in video memory, so that the corresponding glyph (as found in video ROM) appears on the screen. Note that the use of Unicode (and the design of the PC hardware) allows us to use 512 different glyphs simultaneously.

If the current Unicode value is a control character, or we are currently processing an escape sequence, the value will treated specially. Instead of being turned into a font index and rendered as a glyph, it may trigger cursor movement or other control functions. See the LINUX CONSOLE CONTROLS section below for discussion.

It is generally not good practice to hard-wire terminal controls into programs. Linux supports a terminfo(5) database of terminal capabilities. Rather than emitting console escape sequences by hand, you will almost always want to use a terminfo-aware screen library or utility such as ncurses(3), tput(1), or reset(1).

LINUX CONSOLE CONTROLS

This section describes all the control characters and escape sequences that invoke special functions (i.e. anything other than writing a glyph at the current cursor location) on the Linux console.  

Control characters

A character is a control character if (before transformation according to the mapping table) it has one of the 14 codes 00 (NUL), 07 (BEL), 08 (BS), 09 (HT), 0a (LF), 0b (VT), 0c (FF), 0d (CR), 0e (SO), 0f (SI), 18 (CAN), 1a (SUB), 1b (ESC), 7f (DEL). One can set a `display control characters' mode (see below), and allow 07, 09, 0b, 18, 1a, 7f to be displayed as glyphs. On the other hand, in UTF-8 mode all codes 00-1f are regarded as control characters, regardless of any `display control characters' mode.

If we have a control character, it is acted upon immediately and then discarded (even in the middle of an escape sequence) and the escape sequence continues with the next character. (However, ESC starts a new escape sequence, possibly aborting a previous unfinished one, and CAN and SUB abort any escape sequence.) The recognized control characters are BEL, BS, HT, LF, VT, FF, CR, SO, SI, CAN, SUB, ESC, DEL, CSI. They do what one would expect:

BEL (0x07, ^G) beeps;
BS (0x08, ^H) backspaces one column (but not past the beginning of the line);
HT (0x09, ^I) goes to the next tab stop or to the end of the line if there is no earlier tab stop;
LF (0x0A, ^J), VT (0x0B, ^K) and FF (0x0C, ^L) all give a linefeed;
CR (0x0D, ^M) gives a carriage return;
SO (0x0E, ^N) activates the G1 character set, and if LF/NL (new line mode) is set also a carriage return;
SI (0x0F, ^O) activates the G0 character set;
CAN (0x18, ^X) and SUB (0x1A, ^Z) interrupt escape sequences;
ESC (0x1B, ^[) starts an escape sequence;
DEL (0x7F) is ignored;
CSI (0x9B) is equivalent to ESC [.

ESC- but not CSI-sequences

ESC c RIS Reset.
 
ESC D IND Linefeed.
 
ESC E NEL Newline.
 
ESC H HTS Set tab stop at current column.
 
ESC M RI Reverse linefeed.
 
ESC Z DECID DEC private identification. The kernel
 
    returns the string ESC [ ? 6 c, claiming
 
    that it is a VT102.
 
ESC 7 DECSC Save current state (cursor coordinates,
 
    attributes, character sets pointed at by G0, G1).
 
ESC 8 DECRC Restore state most recently saved by ESC 7.
 
ESC [ CSI Control sequence introducer
 
ESC %   Start sequence selecting character set
 
ESC % @      Select default (ISO 646 / ISO 8859-1)
 
ESC % G      Select UTF-8
 
ESC % 8      Select UTF-8 (obsolete)
 
ESC # 8 DECALN DEC screen alignment test - fill screen with E's.
 
ESC (   Start sequence defining G0 character set
 
ESC ( B      Select default (ISO 8859-1 mapping)
 
ESC ( 0      Select vt100 graphics mapping
 
ESC ( U      Select null mapping - straight to character ROM
 
ESC ( K      Select user mapping - the map that is loaded by
 
       the utility mapscrn(8).
 
ESC )   Start sequence defining G1
 
    (followed by one of B, 0, U, K, as above).
 
ESC > DECPNM Set numeric keypad mode
 
ESC = DECPAM Set application keypad mode
 
ESC ] OSC (Should be: Operating system command)
 
    ESC ] P nrrggbb: set palette, with parameter
 
    given in 7 hexadecimal digits after the final P :-(.
 
    Here n is the color (0-15), and rrggbb indicates
 
    the red/green/blue values (0-255).
 
    ESC ] R: reset palette
 
 

ECMA-48 CSI sequences

CSI (or ESC [) is followed by a sequence of parameters, at most NPAR (16), that are decimal numbers separated by semicolons. An empty or absent parameter is taken to be 0. The sequence of parameters may be preceded by a single question mark.

However, after CSI [ (or ESC [ [) a single character is read and this entire sequence is ignored. (The idea is to ignore an echoed function key.)

The action of a CSI sequence is determined by its final character.

@ ICH Insert the indicated # of blank characters.
 
A CUU Move cursor up the indicated # of rows.
 
B CUD Move cursor down the indicated # of rows.
 
C CUF Move cursor right the indicated # of columns.
 
D CUB Move cursor left the indicated # of columns.
 
E CNL Move cursor down the indicated # of rows, to column 1.
 
F CPL Move cursor up the indicated # of rows, to column 1.
 
G CHA Move cursor to indicated column in current row.
 
H CUP Move cursor to the indicated row, column (origin at 1,1).
 
J ED Erase display (default: from cursor to end of display).
 
    ESC [ 1 J: erase from start to cursor.
 
    ESC [ 2 J: erase whole display.
 
K EL Erase line (default: from cursor to end of line).
 
    ESC [ 1 K: erase from start of line to cursor.
 
    ESC [ 2 K: erase whole line.
 
L IL Insert the indicated # of blank lines.
 
M DL Delete the indicated # of lines.
 
P DCH Delete the indicated # of characters on the current line.
 
X ECH Erase the indicated # of characters on the current line.
 
a HPR Move cursor right the indicated # of columns.
 
c DA Answer ESC [ ? 6 c: `I am a VT102'.
 
d VPA Move cursor to the indicated row, current column.
 
e VPR Move cursor down the indicated # of rows.
 
f HVP Move cursor to the indicated row, column.
 
g TBC Without parameter: clear tab stop at the current position.
 
    ESC [ 3 g: delete all tab stops.
 
h SM Set Mode (see below).
 
l RM Reset Mode (see below).
 
m SGR Set attributes (see below).
 
n DSR Status report (see below).
 
q DECLL Set keyboard LEDs.
 
    ESC [ 0 q: clear all LEDs
 
    ESC [ 1 q: set Scroll Lock LED
 
    ESC [ 2 q: set Num Lock LED
 
    ESC [ 3 q: set Caps Lock LED
 
r DECSTBM Set scrolling region; parameters are top and bottom row.
 
s ? Save cursor location.
 
u ? Restore cursor location.
 
` HPA Move cursor to indicated column in current row.
 
 

ECMA-48 Set Graphics Rendition

The ECMA-48 SGR sequence ESC [ <parameters> m sets display attributes. Several attributes can be set in the same sequence.

par result
 
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.
 
11 select null mapping, set display control flag,
 
  reset toggle meta flag.
 
12 select null mapping, set display control flag,
 
  set toggle meta flag. (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 (this is not compatible with ECMA-48)
 
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
 
 

ECMA-48 Mode Switches

ESC [ 3 h
DECCRM (default off): Display control chars.
ESC [ 4 h
DECIM (default off): Set insert mode.
ESC [ 20 h
LF/NL (default off): Automatically follow echo of LF, VT or FF with CR.

ECMA-48 Status Report Commands

ESC [ 5 n
Device status report (DSR): Answer is ESC [ 0 n (Terminal OK).
ESC [ 6 n
Cursor position report (CPR): Answer is ESC [ y ; x R, where x,y is the cursor location.

DEC Private Mode (DECSET/DECRST) sequences.

These are not described in ECMA-48. We list the Set Mode sequences; the Reset Mode sequences are obtained by replacing the final `h' by `l'.

ESC [ ? 1 h
DECCKM (default off): When set, the cursor keys send an ESC O prefix, rather than ESC [.
ESC [ ? 3 h
DECCOLM (default off = 80 columns): 80/132 col mode switch. The driver sources note that this alone does not suffice; some user-mode utility such as resizecons(8) has to change the hardware registers on the console video card.
ESC [ ? 5 h
DECSCNM (default off): Set reverse-video mode.
ESC [ ? 6 h
DECOM (default off): When set, cursor addressing is relative to the upper left corner of the scrolling region.
ESC [ ? 7 h
DECAWM (default on): Set autowrap on. In this mode, a graphic character emitted after column 80 (or column 132 of DECCOLM is on) forces a wrap to the beginning of the following line first.
ESC [ ? 8 h
DECARM (default on): Set keyboard autorepreat on.
ESC [ ? 9 h
X10 Mouse Reporting (default off): Set reporting mode to 1 (or reset to 0) - see below.
ESC [ ? 25 h
DECCM (default on): Make cursor visible.
ESC [ ? 1000 h
X11 Mouse Reporting (default off): Set reporting mode to 2 (or reset to 0) - see below.

Linux Console Private CSI Sequences

The following sequences are neither ECMA-48 nor native VT102. They are native to the Linux console driver. Colors are in SGR parameters: 0 = black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan, 7 = white.

ESC [ 1 ; n ] Set color n as the underline color
 
ESC [ 2 ; n ] Set color n as the dim color
 
ESC [ 8 ] Make the current color pair the default attributes.
 
ESC [ 9 ; n ] Set screen blank timeout to n minutes.
 
ESC [ 10 ; n ] Set bell frequency in Hz.
 
ESC [ 11 ; n ] Set bell duration in msec.
 
ESC [ 12 ; n ] Bring specified console to the front.
 
ESC [ 13 ] Unblank the screen.
 
ESC [ 14 ; n ] Set the VESA powerdown interval in minutes.
 

CHARACTER SETS

The kernel knows about 4 translations of bytes into console-screen symbols. The four tables are: a) Latin1 -> PC, b) VT100 graphics -> PC, c) PC -> PC, d) user-defined.

There are two character sets, called G0 and G1, and one of them is the current character set. (Initially G0.) Typing ^N causes G1 to become current, ^O causes G0 to become current.

These variables G0 and G1 point at a translation table, and can be changed by the user. Initially they point at tables a) and b), respectively. The sequences ESC ( B and ESC ( 0 and ESC ( U and ESC ( K cause G0 to point at translation table a), b), c) and d), respectively. The sequences ESC ) B and ESC ) 0 and ESC ) U and ESC ) K cause G1 to point at translation table a), b), c) and d), respectively.

The sequence ESC c causes a terminal reset, which is what you want if the screen is all garbled. The oft-advised "echo ^V^O" will only make G0 current, but there is no guarantee that G0 points at table a). In some distributions there is a program reset(1) that just does "echo ^[c". If your terminfo entry for the console is correct (and has an entry rs1=\Ec), then "tput reset" will also work.

The user-defined mapping table can be set using mapscrn(8). The result of the mapping is that if a symbol c is printed, the symbol s = map[c] is sent to the video memory. The bitmap that corresponds to s is found in the character ROM, and can be changed using setfont(8).

MOUSE TRACKING

The mouse tracking facility is intended to return xterm-compatible mouse status reports. Because the console driver has no way to know the device or type of the mouse, these reports are returned in the console input stream only when the virtual terminal driver receives a mouse update ioctl. These ioctls must be generated by a mouse-aware user-mode application such as the gpm(8) daemon.

Parameters for all mouse tracking escape sequences generated by xterm encode numeric parameters in a single character as value+040. For example, `!' is 1. The screen coordinate system is 1-based.

The X10 compatibility mode sends an escape sequence on button press encoding the location and the mouse button pressed. It is enabled by sending ESC [ ? 9 h and disabled with ESC [ ? 9 l. On button press, xterm sends ESC [ M bxy (6 characters). Here b is button-1, and x and y are the x and y coordinates of the mouse when the button was pressed. This is the same code the kernel also produces.

Normal tracking mode (not implemented in Linux 2.0.24) sends an escape sequence on both button press and release. Modifier information is also sent. It is enabled by sending ESC [ ? 1000 h and disabled with ESC [ 1000 l. On button press or release, xterm sends ESC [ M bxy. The low two bits of b encode button information: 0=MB1 pressed, 1=MB2 pressed, 2=MB3 pressed, 3=release. The upper bits encode what modifiers were down when the button was pressed and are added together: 4=Shift, 8=Meta, 16=Control. Again x and y are the x and y coordinates of the mouse event. The upper left corner is (1,1).

COMPARISONS WITH OTHER TERMINALS

Many different terminal types are described, like the Linux console, as being `VT100-compatible'. Here we discuss differences vbetween the Linux console an the two most important others, the DEC VT102 and xterm(1).  

Control-character handling

The vt102 also recognized the following control characters:

NUL (0x00) was ignored;
ENQ (0x05) triggered an answerback message;
DC1 (0x11, ^Q, XON) resumed transmission;
DC3 (0x13, ^S, XOFF) caused vt100 to ignore (and stop transmitting) all codes except XOFF and XON.

VT100-like DC1/DC3 processing may be enabled by the tty driver.

The xterm program (in vt100 mode) recognizes the control characters BEL, BS, HT, LF, VT, FF, CR, SO, SI, ESC.  

Escape sequences

VT100 console sequences not implemented on the Linux console:

ESC N SS2 Single shift 2. (Select G2 character set for the next
 
    character only.)
 
ESC O SS3 Single shift 3. (Select G3 character set for the next
 
    character only.)
 
ESC P DCS Device control string (ended by ESC \)
 
ESC X SOS Start of string.
 
ESC ^ PM Privacy message (ended by ESC \)
 
ESC \ ST String terminator
 
ESC * ...   Designate G2 character set
 
ESC + ...   Designate G3 character set
 

The program xterm (in vt100 mode) recognizes ESC c, ESC # 8, ESC >, ESC =, ESC D, ESC E, ESC H, ESC M, ESC N, ESC O, ESC P ... ESC , ESC Z (it answers ESC [ ? 1 ; 2 c, `I am a vt100 with advanced video option') and ESC ^ ... ESC  with the same meanings as indicated above. It accepts ESC (, ESC ), ESC *, ESC + followed by 0, A, B for the DEC special character and line drawing set, UK, and USASCII, respectively. It accepts ESC ] for the setting of certain resources:

ESC ] 0 ; txt BEL Set icon name and window title to txt.
 
ESC ] 1 ; txt BEL Set icon name to txt.
 
ESC ] 2 ; txt BEL Set window title to txt.
 
ESC ] 4 6 ; name BEL Change log file to name (normally disabled
 
  by a compile-time option)
 
ESC ] 5 0 ; fn BEL Set font to fn.
 

It recognizes the following with slightly modified meaning:

ESC 7 DECSC Save cursor
 
ESC 8 DECRC Restore cursor
 

It also recognizes

ESC F   Cursor to lower left corner of screen (if enabled by
 
    the hpLowerleftBugCompat resource)
 
ESC l   Memory lock (per HP terminals).
 
    Locks memory above the cursor.
 
ESC m   Memory unlock (per HP terminals).
 
ESC n LS2 Invoke the G2 character set.
 
ESC o LS3 Invoke the G3 character set.
 
ESC | LS3R Invoke the G3 character set as GR.
 
    Has no visible effect in xterm.
 
ESC } LS2R Invoke the G2 character set as GR.
 
    Has no visible effect in xterm.
 
ESC ~ LS1R Invoke the G1 character set as GR.
 
    Has no visible effect in xterm.
 

It does not recognize ESC % ...  

CSI Sequences

The xterm program (as of XFree86 3.1.2G) does not recognize the blink or invisible-mode SGRs. Stock X11R6 versions do not recognize the color-setting SGRs. All other ECMA-48 CSI sequences recognized by Linux are also recognized by xterm, and vice-versa.

The xterm program will recognize all of the DEC Private Mode sequences listed above, but none of the Linux private-mode sequences. For discussion of xterm's own private-mode sequences, refer to the Xterm Control Sequences document by Edward Moy and Stephen Gildea, available with the X distribution.

BUGS

In 2.0.23, CSI is broken, and NUL is not ignored inside escape sequences.

SEE ALSO

console(4), console_ioctl(4), charsets(7)

责任编辑:韩亚珊 来源: CMPP.net
相关推荐

2011-08-24 16:48:36

man中文man

2011-08-15 10:21:09

man中文man

2011-08-11 16:11:49

at中文man

2011-08-25 10:21:56

man.conf中文man

2011-08-12 14:58:05

killall中文man

2011-07-15 16:58:36

ac中文man

2011-08-15 11:10:48

more中文man

2011-08-25 17:03:51

pclose中文man

2011-08-15 14:10:37

tar中文man

2011-08-16 10:42:30

rmmod中文man

2011-08-18 13:57:38

acct中文man

2011-08-23 17:49:36

zdump中文man

2011-08-15 15:10:49

wall中文man

2011-08-23 15:06:03

quotastats中文man

2011-08-15 17:35:50

ar中文man

2011-08-25 09:07:16

suffixes中文man

2011-08-18 15:21:37

autofs中文man

2011-08-25 15:19:39

dirname中文man

2011-08-25 17:34:50

setlinebuf中文man

2011-08-15 15:17:14

ac中文man
点赞
收藏

51CTO技术栈公众号