console_codes 中文man頁面
NAME 名稱
控制終端代碼 - Linux 控制終端轉(zhuǎn)義和控制序列
DESCRIPTION 描述
Linux控制臺(tái)實(shí)現(xiàn)了VT102和ECMA-48/ISO 6429/ANSI X3.64終端控制的子集, 這個(gè)子集很龐大,當(dāng)然還有Linux自己私有的控制序列,以改變顏色配置,字符集映像,等等.在下面將要給出的表格中,第二列為指定的功能給出了ECMA-48 或者DEC助記符(如果是后者會(huì)在前面加有DEC前綴).沒有給出助記符的序列既不是ECMA-48也不是VT102字符.
在所有標(biāo)準(zhǔn)輸出進(jìn)程執(zhí)行完畢,并且一個(gè)字符流被送到控制臺(tái)驅(qū)動(dòng)程序準(zhǔn)備顯示出來的時(shí)候,所發(fā)生的第一件事就是將進(jìn)程使用的代碼轉(zhuǎn)換成顯示使用的代碼.
如果控制臺(tái)工作于 UTF-8 模式,那么輸入的字節(jié)會(huì)首先編碼成16位的 Unicode 代碼.如果不是UTF-8模式,那么每個(gè)字節(jié)會(huì)按照當(dāng)前的字符映射表完成轉(zhuǎn)換(轉(zhuǎn)換成Unicode編碼的值). 參看下面將要討論的 CHARACTER SETS 一章. 在一般情況下,Unicode 代碼被轉(zhuǎn)換成為存儲(chǔ)在視頻存儲(chǔ)器中的字體索引,這樣對(duì)應(yīng)的具體字符(字符存儲(chǔ)在視頻ROM中)就顯示在屏幕上了. 注意使用 Unicode 編碼允許我們同時(shí)使用 512 種不同的字體(和計(jì)算機(jī)硬件有關(guān)).
如果當(dāng)前的 Unicode 代碼是一個(gè)控制字符,或者系統(tǒng)目前正在處理一個(gè)轉(zhuǎn)義序列,處理的方式有些特別.它不會(huì)被轉(zhuǎn)換成字體索引,也不會(huì)直接顯示在屏幕上.它可能控制光標(biāo)的移動(dòng),或者實(shí)現(xiàn)其它控制功能.參看下面的 LINUX CONSOLE CONTROLS 一節(jié)所進(jìn)行的討論.
一般來說直接在程序中插入終端控制字符并不是很好.Linux 支持終端兼容的 terminfo(5) 數(shù)據(jù)庫. 除了直接插入控制和轉(zhuǎn)義序列,也可以使用象 ncurses(3), tput(1), 或者 reset(1). 這樣的顯示庫或者工具.
LINUX CONSOLE CONTROLS Linux終端控制
這一段描述了所有在Linux控制臺(tái)下使用的調(diào)用特殊功能的控制字符和轉(zhuǎn)義序列(例如.任何不在當(dāng)前光標(biāo)處插入可見字符的序列).
Control characters 控制字符
當(dāng)一個(gè)字符在通過字符映射表轉(zhuǎn)換之前含有以下14個(gè)代碼之一的時(shí)候表明它是一個(gè)控制字符. 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). 我們可以通過設(shè)置 `顯示控制字符' 模式(見下文)以允許07,09,0b, 18,1a,7f 像普通字符一樣顯示在屏幕上.另一方面,在UTF-8模式下所有位于 00-1f之間的代碼都被認(rèn)為是控制字符,而不管是否處于 `顯示控制字符'模式.
一個(gè)控制字符會(huì)立刻生效,然后被丟棄(即使是在轉(zhuǎn)義序列中間), 之后轉(zhuǎn)義序列才繼續(xù)處理下一個(gè)字符. (在任何情況下,ESC都表示一個(gè)新的轉(zhuǎn)義序列的開始,可能導(dǎo)致 前一個(gè)序列的非正常終止,CAN和SUB 終止任何轉(zhuǎn)義序列.) 可識(shí)別的控制字符是BEL,BS,HT,LF,VT,FF,CR,SO,SI,CAN, SUB,ESC,DEL,CSI.他們的功能如下.:
- BEL(0x07,^G)鈴聲;
- BS(0x08,^H)后退一格(在行首不起作用);
- HT(0x09,^I)跳至下一個(gè)制表位.如果后面已沒有制表位則跳至行尾;
- LF(0x0A,^J),VT(0x0B,^K),FF(0x0C,^L)三者都表示換行;
- CR(0x0D,^M)回車并換行;
- SO(0x0E,^N)激活 G1 字符集, 如果設(shè)置了 LF/NL(新行模式)還要加上回車換行;
- SI(0x0F,^O)激活 G0 字符集;
- CAN(0x18,^X),SUB(0x1A,^Z)兩者都表示中斷轉(zhuǎn)義序列;
- ESC(0x1B,^[)開始一個(gè)新的轉(zhuǎn)義序列;
- DEL(0x7F)忽略;
- CSI(0x9B)等同于 ESC [;
ESC- but not CSI-sequences 非控制轉(zhuǎn)義序列
ESC c | RIS | 重繪屏幕. |
ESC D | IND | 換行. |
ESC E | NEL | 新的一行. |
ESC H | HTS | 設(shè)置當(dāng)前列為制表位. |
ESC M | RI | 翻轉(zhuǎn)換行(Reverse linefeed). |
ESC Z | DECID | DEC 私有定義.內(nèi)核將其解釋為 |
VT102字符,返回字符ESC [ ? 6 c. |
||
ESC 7 | DECSC | 存儲(chǔ)當(dāng)前狀態(tài)(光標(biāo)坐標(biāo), |
屬性,字符集). |
||
ESC 8 | DECRC | 恢復(fù)上一次儲(chǔ)存的設(shè)置 |
ESC [ | CSI | 控制序列介紹 |
ESC % | 開始一個(gè)字符集選擇序列 |
|
ESC % @ | 選擇默認(rèn)字符集(ISO 646 / ISO 8859-1) | |
ESC % G | 選擇 UTF-8 |
|
ESC % 8 | 選擇 UTF-8(已不用) |
|
ESC # 8 | DECALN | DEC 屏幕校準(zhǔn)測試 - 以E's填充屏幕. |
ESC( | 開始一個(gè) G0 字符集定義序列 |
|
ESC( B | 選擇默認(rèn)字符集(ISO 8859-1 mapping) |
|
ESC( 0 | 選擇 vt100 圖形映射 |
|
ESC( U | 選擇空映射 - 直接訪問字符ROM |
|
ESC( K | 選擇用戶映射 - 由程序mapscrn(8) |
|
加載. |
||
ESC ) | 開始一個(gè) G1 字符集定義 |
|
(后面跟 B,0,U,K,同上). |
||
ESC > | DECPNM | 設(shè)置數(shù)字小鍵盤模式 |
ESC = | DECPAM | 設(shè)置程序鍵盤模式 |
ESC ] | OSC | (是perating system command的縮寫) |
ESC ] P nrrggbb: 設(shè)置調(diào)色板,后面緊跟7個(gè) |
||
十六進(jìn)制數(shù),再跟一個(gè) P :-(. |
||
這里 n 是顏色(0-16),而 rrggbb 表示 |
||
紅/綠/藍(lán) 值(0-255). |
||
ESC ] R: 重置調(diào)色板 |
ECMA-48 CSI sequence ECMA-48 CSI 序列
CSI(或者 ESC [)后面跟的參數(shù)序列大部分是NPAR(16), 就是由分號(hào)隔開的十進(jìn)制數(shù).空參數(shù)或缺少的參數(shù)以0處理. 可以用一個(gè)問號(hào)代替參數(shù)序列.
在任何情況下,系統(tǒng)讀取 CSI [(或者 ESC [ [)后的單個(gè)字符, 而忽略整個(gè)序列.(用于忽略回顯功能鍵.)
CSI 序列的動(dòng)作由其最后一個(gè)字符決定.
@ | ICH | 用#符號(hào)指示空格. |
A | CUU | 光標(biāo)上移到#標(biāo)識(shí)的行. |
B | CUD | 光標(biāo)下移到#標(biāo)識(shí)的行. |
C | CUF | 光標(biāo)右移到#標(biāo)識(shí)的列. |
D | CUB | 光標(biāo)左移到#標(biāo)識(shí)的列. |
E | CNL | 將光標(biāo)下移到#指示的行的第一列. |
F | CPL | 將光標(biāo)上移到#指示的行的第一列. |
G | CHA | 光標(biāo)移動(dòng)到當(dāng)前行的指定列. |
H | CUP | 光標(biāo)移動(dòng)到指定行和列(以1行1列為參照). |
J | ED | 刪除(默認(rèn)從當(dāng)前光標(biāo)處到行尾的)內(nèi)容. |
ESC [ 1 J: 刪除從開始到光標(biāo)處的內(nèi)容. |
||
ESC [ 2 J: 清空整個(gè)屏幕. |
||
K | EL | 刪除行(默認(rèn)從當(dāng)前光標(biāo)處到結(jié)尾). |
ESC [ 1 K: 刪除從行首到當(dāng)前光標(biāo)處的內(nèi)容. |
||
ESC [ 2 K: 刪除整行. |
||
L | IL | 在空行插入#. |
M | DL | 刪除#標(biāo)記的行. |
P | DCH | 刪除當(dāng)前行中#標(biāo)記的字符. |
X | ECH | 刪除當(dāng)前行中#標(biāo)記的單詞. |
a | HPR | 光標(biāo)移動(dòng)到#標(biāo)記的右邊. |
c | DA | 以`I am a VT102'應(yīng)答 ESC [ ? 6 c: |
d | VPA | 光標(biāo)移動(dòng)到當(dāng)前列指定行 |
e | VPR | 光標(biāo)移動(dòng)到#標(biāo)記的下一行. |
f | HVP | 光標(biāo)移動(dòng)到指定的行和列. |
g | TBC | 沒有參數(shù): 清除當(dāng)前位置的制表站. |
ESC [ 3 g: 刪除所有制表站. |
||
h | SM | 設(shè)置模式(見下文). |
l | RM | 重置模式(見下文). |
m | SGR | 設(shè)置屬性(見下文). |
n | DSR | 狀態(tài)報(bào)告(見下文). |
q | DECLL | 設(shè)置鍵盤指示燈. |
ESC [ 0 q: 熄滅所有指示燈 |
||
ESC [ 1 q: 點(diǎn)亮 Scroll Lock 燈 |
||
ESC [ 2 q: 點(diǎn)亮 Num Lock 燈 |
||
ESC [ 3 q: 點(diǎn)亮 Caps Lock 燈 |
||
r | DECSTBM | 設(shè)置滾動(dòng)范圍; 參數(shù)為首行和末行. |
s | ? | 存儲(chǔ)光標(biāo)位置. |
u | ? | 恢復(fù)光標(biāo)位置. |
` | HPA | 光標(biāo)移動(dòng)到當(dāng)前行指定列. |
ECMA-48 Set Graphics Rendition 設(shè)置圖形屬性
ECMA-48 SGR 序列 ESC [ <parameters> m 設(shè)置顯示屬性. 同樣的序列可以設(shè)置一個(gè)或多個(gè)屬性.
par | 作用 |
0 | 所有屬性重設(shè)為默認(rèn)值 |
1 | 設(shè)置邊框 |
2 | 設(shè)置亮度減半(用一種顏色模擬另一種顏色) |
4 | 設(shè)置底紋(用一種顏色模擬另一種顏色) |
(用于模擬的顏色由using ESC ] ...設(shè)置) |
|
5 | 設(shè)置閃爍 |
7 | 設(shè)置反轉(zhuǎn)視頻(reverse video) |
10 | 重設(shè)選定映像,顯示控制標(biāo)記, |
反轉(zhuǎn)元素標(biāo)記. |
|
11 | 選擇空映像,設(shè)置顯示控制標(biāo)記, |
重設(shè)反轉(zhuǎn)標(biāo)記. |
|
12 | 選擇空映像,設(shè)置顯示控制標(biāo)記, |
重設(shè)反轉(zhuǎn)標(biāo)記.(在完成映像表轉(zhuǎn) |
|
換之前反轉(zhuǎn)標(biāo)記引起每一字節(jié)的 |
|
高位反轉(zhuǎn).) |
|
21 | 設(shè)置正常亮度(和 ECMA-48 不兼容) |
22 | 設(shè)置正常亮度 |
24 | 關(guān)閉下劃線 |
25 | 不閃爍 |
27 | 反轉(zhuǎn)視頻關(guān)閉 |
30 | 黑色背景 |
31 | 紅色前景 |
32 | 綠色前景 |
33 | 棕色前景 |
34 | 藍(lán)色前景 |
35 | 品紅前景 |
36 | 孔雀藍(lán)前景 |
37 | 白色前景 |
38 | 打開下劃線,設(shè)置默認(rèn)前景色 |
39 | 關(guān)閉下劃線,設(shè)置默認(rèn)前景色 |
40 | 黑色背景 |
41 | 紅色背景 |
42 | 綠色背景 |
43 | 棕色背景 |
44 | 藍(lán)色背景 |
45 | 品紅背景 |
46 | 孔雀藍(lán)背景 |
47 | 白色背景 |
49 | 設(shè)置默認(rèn)背景色 |
ECMA-48 Mode Switches ECMA-48模式選擇
- ESC [ 3 h
- DECCRM(默認(rèn)關(guān)閉): 顯示控制字符.
- ESC [ 4 h
- DECIM(默認(rèn)關(guān)閉): 設(shè)置插入模式.
- ESC [ 20 h
- LF/NL(默認(rèn)關(guān)閉): 自動(dòng)在CR后加上 LF,VT 或者 FF.
ECMA-48 狀態(tài)報(bào)告命令.
- ESC [ 5 n
- 設(shè)備狀態(tài)報(bào)告(DSR): 以 ESC [ 0 n 應(yīng)答(終端準(zhǔn)備好).
- ESC [ 6 n
- 光標(biāo)位置報(bào)告(CPR): 以ESC [ y ; x R 應(yīng)答, 這里 x,y 指光標(biāo)位置.
DEC Private Mode(DECSET/DECRST)sequences DEC私有模式序列.
這里給出的序列在 ECMA-48中沒有描述.我們列出了設(shè)置模式序列; 用l替換最后一個(gè)h就是重設(shè)模式序列.
- ESC [ ? 1 h
- DECCKM(默認(rèn)關(guān)閉): 打開時(shí)光標(biāo)鍵送出 ESC O 前綴, 而不是 ESC [.
- ESC [ ? 3 h
- DECCOLM(默認(rèn) = 80 行): 交替選擇 80/132 行模式.當(dāng)原顯示模式不足以滿足要求的時(shí)候,象 resizecons(8) 這樣的用戶程序會(huì)改變終端顯示卡的硬件注冊(cè).
- ESC [ ? 5 h
- DECSCNM(默認(rèn)關(guān)閉): 設(shè)置視頻反轉(zhuǎn)模式.
- ESC [ ? 6 h
- DECOM(默認(rèn)關(guān)閉): 打開時(shí),光標(biāo)位置用相對(duì)于滾動(dòng)條左上角的位置表示.
- ESC [ ? 7 h
- DECAWM(默認(rèn)關(guān)閉): 打開自動(dòng)換行.在這種模式下,一行中超過80列的字符將自動(dòng)換行(在DECCOLM打開時(shí)是132列).
- ESC [ ? 8 h
- DECARM(默認(rèn)關(guān)閉): 打開鍵盤自動(dòng)重復(fù).
- ESC [ ? 9 h
- X10 鼠標(biāo)報(bào)告(默認(rèn)關(guān)閉): 設(shè)置報(bào)告模式 1(或者重設(shè)為 0)- 見下文.
- ESC [ ? 25 h
- DECCM(默認(rèn)打開): 設(shè)置光標(biāo)可見.
- ESC [ ? 1000 h
- X11 鼠標(biāo)報(bào)告(默認(rèn)關(guān)閉): 設(shè)置報(bào)告模式 2(或者重設(shè)為 0)- 見下文.
Linux Console Private CSI Sequences Linux控制臺(tái)私有控制序列
下面的序列既不屬于 ECMA-48 字符也不屬于 VT102.它們只在 Linux控制臺(tái)上使用.顏色采用 SGR 參數(shù): 0 = 黑色,1 = 紅色,2 = 綠色,3 =褐色 ,4 = 藍(lán)色,5 = 洋紅,6 = 孔雀藍(lán),7 = 白色.
ESC [ 1 ; n ] | 設(shè)置下劃線顏色為 n |
ESC [ 2 ; n ] | 設(shè)置暗色為 n |
ESC [ 8 ] | 設(shè)置當(dāng)前顏色對(duì)為默認(rèn)屬性. |
ESC [ 9 ; n ] | 設(shè)置屏幕空白超時(shí)為 n 分鐘. |
ESC [ 10 ; n ] | 設(shè)置機(jī)箱喇叭鳴叫頻率,單位: Hz. |
ESC [ 11 ; n ] | 設(shè)置機(jī)箱喇叭鳴叫持續(xù)時(shí)間,單位:微秒. |
ESC [ 12 ; n ] | 設(shè)置指定控制臺(tái)前臺(tái)運(yùn)行. |
ESC [ 13 ] | 設(shè)置指定控制臺(tái)黑色 |
ESC [ 14 ; n ] | 設(shè)置 VESA 關(guān)閉間隔,單位: 分鐘. |
CHARACTER SETS 字符集
內(nèi)核可以完成以下四種字符轉(zhuǎn)換,使字符能在屏幕上顯示. a)Latin1 -> PC,b)VT100 graphics -> PC,c)PC -> PC, d)user-defined(用戶自定義).
有兩種字符集設(shè)置,以 G0 和 G1定義,當(dāng)前字符集必定是其中之一.(初始化為G0.)鍵入 ^N 使 G1 成為當(dāng)前字符集,鍵入 ^O 使 G0 成為當(dāng)前設(shè)置.
變量 G0 and G1 指向字符映射關(guān)系表,并且這種指向關(guān)系可以由用戶改變. 系統(tǒng)初始化時(shí)它們分別指向表 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 重置一個(gè)終端,當(dāng)屏幕顯示出現(xiàn)混亂時(shí)可以使用這個(gè)序列. 另一個(gè)序列 "echo ^V^O" 僅僅將G0設(shè)為當(dāng)前字符集,但并不保證 G0 指向映射表 a). 有的Linux發(fā)行版中提供一個(gè)叫做 reset(1) 的程序用來送出序列 "echo ^[c". 如果你的系統(tǒng)終端變量沒有錯(cuò)誤( rs1=\Ec), 那么使用"tput reset"也可以達(dá)到同樣效果.
用戶自定義映射表可以用程序 mapscrn(8). 定義.這個(gè)程序工作時(shí)會(huì)將送入的字符c通過關(guān)系式s=map[c]映射到字符s然后送入顯存.字符s所對(duì)應(yīng)的位圖放在字符ROM里面,可以使用程序 setfont(8).
來改變.
MOUSE TRACKING 鼠標(biāo)軌跡
鼠標(biāo)軌跡工具可以返回與 xterm 兼容的鼠標(biāo)狀態(tài)報(bào)告.因?yàn)榭刂婆_(tái)驅(qū)動(dòng)沒有辦法知道鼠標(biāo)類型,只有當(dāng)虛擬終端驅(qū)動(dòng)接收到鼠標(biāo)輸入輸出消息更新時(shí)才會(huì)將這些報(bào)告返回給控制臺(tái)輸入流..這些鼠標(biāo)輸入輸出消息由 gpm(8) 守護(hù)進(jìn)程產(chǎn)生.
所有鼠標(biāo)軌跡轉(zhuǎn)義序列參數(shù)由xterm 編碼成象value+040 這樣的單一字符形式的數(shù)字參數(shù).比如,`!' 編碼成 1.屏幕坐標(biāo)系統(tǒng)以'1'為基準(zhǔn).
X10 兼容模式在鼠標(biāo)鍵按下時(shí)將按下的鍵和鼠標(biāo)位置編碼后送出. ESC [ ? 9 h 允許這一動(dòng)作,ESC [ ? 9 l禁止這一動(dòng)作. 有鍵按下時(shí),xterm 送出ESC [ M bxy(6 個(gè)字符).這里 b 代表 鍵-1,而 x 和 y 是鼠標(biāo)的 x 和 y 坐標(biāo).這和內(nèi)核產(chǎn)生的序列相同.
常規(guī)的軌跡模式(Linux 2.0.24不再支持)在左右兩鍵同時(shí)按下然后釋放時(shí)送出轉(zhuǎn)義序列.組合鍵編碼也被送出.ESC [ ? 1000 h 允許這個(gè)動(dòng)作而ESC [ 1000 l 禁止這個(gè)動(dòng)作.當(dāng)有鍵按下或者釋放時(shí), xterm 送出 ESC [ M bxy.b 的低兩位對(duì)按鍵信息編碼: 0=鼠標(biāo)鍵1按下,1=鼠標(biāo)鍵2 按下,2=鼠標(biāo)鍵3 按下,3=釋放. 高位編碼代表組合鍵,和上述編碼一起送出: 4=Shift,8=Meta(Alt),16=Control(Ctrl).x 和y為發(fā)生鼠標(biāo)事件的x和y坐標(biāo).以左上角為(1,1).
和其它終端的比較
我們已經(jīng)討論了幾種終端類型,比如Linux 控制臺(tái).這類終端稱為 "VT100兼容"的終端.這里我們?cè)俳榻B其他兩種重要的終端類型: DEC VT102 和 xterm(1) 以及他們和Linux控制終端的區(qū)別.
Control-character handling 控制字符處理
vt102 也使用以下控制序列:
- NUL(0x00)忽略;
- ENQ(0x05)觸發(fā)應(yīng)答消息;
- DC1(0x11,^Q,XON)繼續(xù)傳送;
- DC3(0x13,^S,XOFF)使 vt100 忽略(并停止傳送) 除 XOFF and XON 以外的一切字符.
VT100-like DC1/DC3 進(jìn)程可以由 tty 驅(qū)動(dòng)激活.
程序 xterm (在 vt100 模式 中)使用控制序列 BEL,BS,HT,LF,VT,FF,CR,SO,SI,ESC.
Escape sequences 轉(zhuǎn)義序列
VT100 控制臺(tái)序列不完全支持Linux控制臺(tái)序列:
ESC N | SS2 | 僅僅為下一個(gè)字符選擇 G2 字符集 |
(Single shift 2). |
||
ESC O | SS3 | 僅僅為下一個(gè)字符選擇 G2 字符集 |
(Single shift 2). |
||
ESC P | DCS | 設(shè)備控制字符,由ESC \ 終止 |
(Device control string). |
||
ESC X | SOS | 字符串開始. |
(Start of string) |
||
ESC ^ | PM | 私有消息,由 ESC \ 終結(jié) |
(Privacy message) |
||
ESC \ | ST | 字符串終結(jié) |
(String terminator) |
||
ESC * ... | 指定 G2 字符集 |
|
ESC + ... | 指定 G3 字符集 |
程序 xterm (vt100 模式)承認(rèn) 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'回應(yīng)) 以及 ESC ^ ...ESC ,意義同上. 接受 ESC(,ESC ),ESC *,ESC + 后跟 0,A,B 的字符序列,分別代表的DEC 特殊字符,畫線設(shè)置,UK 和 US ASCII碼. 接受 ESC ] 作為特定資源設(shè)置:
ESC ] 0 ; txt BEL | 將圖標(biāo)名和窗口標(biāo)題設(shè)為文本. |
ESC ] 1 ; txt BEL | 將圖標(biāo)名設(shè)為文本. |
ESC ] 2 ; txt BEL | 將窗口名設(shè)為文本. |
ESC ] 4 6 ; name BEL | 改變?nèi)罩疚募?一般 |
由編譯時(shí)選項(xiàng)禁止) |
|
ESC ] 5 0 ; fn BEL | 字體設(shè)置為 fn. |
以下字符的含義略有不同::
ESC 7 DECSC | 存儲(chǔ)光標(biāo)位置 | |
ESC 8 DECRC | 恢復(fù)光標(biāo)位置 |
它還接受以下序列:
ESC F | 光標(biāo)移動(dòng)到屏幕左下角(由 |
|
hpLowerleftBugCompat 打開這項(xiàng)設(shè)置) |
||
ESC l | 內(nèi)存鎖定(對(duì)于 HP 終端). |
|
鎖定光標(biāo)以上的內(nèi)存. |
||
ESC m | 內(nèi)存解鎖(對(duì)于 HP 終端). |
|
ESC n | LS2 | 調(diào)用 G2 字符集. |
ESC o | LS3 | 調(diào)用 G3 字符集. |
ESC | | LS3R | 以GR調(diào)用 G3 字符集. |
在xterm上看不到效果. |
||
ESC } | LS2R | 以GR調(diào)用 G3 字符集. |
在xterm上看不到效果. |
||
ESC ~ | LS1R | 以GR調(diào)用 G3 字符集. |
在xterm上看不到效果. |
它不識(shí)別 ESC % ...
CSI Sequences CSI 序列
程序 xterm (直到 XFree86 3.1.2G)不能識(shí)別閃爍或者不可見模式的 SGR值.X11R6 也不能識(shí)別以 SGRs 為參數(shù)設(shè)置的色彩. xterm 可以識(shí)別其他的 ECMA-48 CSI 序列,只要Linux可以識(shí)別. 反之亦然.
xterm 可以識(shí)別以上列出的所有 DEC 私有序列,但是不包括 Linux 私有模式序列. 在 Xterm Control Sequences 中有關(guān)于 xterm 的私有模式序列的討論.
document by Edward Moy and Stephen Gildea,available with the X distribution.
BUGS
在版本為 2.0.23 的內(nèi)核中,CSI 序列的識(shí)別有些問題: 不能識(shí)別轉(zhuǎn)義序列中的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)