ANSI转义序列(ANSI escape sequences)是一种的转义序列标准,用于控制视频文本终端上的光标位置、颜色和其他选项。在文本中嵌入确定的字节序列,大部分以ESC转义字符和"["字符开始,终端会把这些字节序列解释为相应的指令,而不是普通的字符编码。
ANSI序列是在二十世纪七十年代引入的标准,用以取代特定于终端供应商的序列,并在二十世纪八十年代早期开始在计算机设备市场上广泛使用。与早期缺少光标移动功能的系统相比,新生的电子公告板系统使用ANSI序列改进其显示。正是因为这个原因,ANSI序列变成了所有制造商共同采用的标准。
在21世纪,尽管硬件文本终端已经越来越少了,但ANSI标准依然存在,因为大多数终端模拟器会对部分ANSI转义序列进行解释。一个值得注意的例外是,在微软Windows 10更新TH2之前,Windows操作系统的Win32控制台是不支持ANSI转义序列的。
历史
最初,几乎每个视频终端制造商都各自添加了特定的转义序列用于执行一些特殊操作,比如把光标置于屏幕上的某个位置。举例来说,终端允许通过发送ESC字符、y字符,后面跟上两个等于x,y位置的数值加上32的字符(这是为了从ASCII空格字符开始,并避开控制字符),将光标置于屏幕上的x,y位置。
由于这些序列对于不同的终端并不一样,因此人们不得不开发了一些复杂的库(比如)和实用程序(比如),以便程序可以使用同一套API应对各种终端。另外,在很多终端中需要借助字符的二进制值发送数字(如行和列)。对于某些编程语言,以及内部不使用ASCII的系统来说,把数字转换为正确的字符常常是有困难的,甚至完全做不到。
ANSI标准试图解决这些问题。标准制订了一种所有终端共用的指令集,并要求用ASCII的数字字符传递所有数值信息。该系列的第一个标准是1976年通过的ECMA-48。它是一系列字符编码标准的延续,其中第一个是从1965年的,一个7位标准,ISO 646就源自此标准。“ANSI转义序列”的名称可以追溯到1979年ANSI采用ANSI X3.64。此外,ANSI X3L2委员会与ECMA委员会TC 1合作制订了一个几乎一模一样的标准。以上两个标准合并为ISO 6429的国际标准。1994年,ANSI取消了其标准,以支持国际标准。
第一个支持这个标准的流行视频终端是1978年推出的Digital 。这个终端在市场上非常成功,引发了各种各样的仿制品,其中最早和最流行的是1979年的。其他品牌还有 QVT-108, TVI-970, WY-99GT。另外,许多其他品牌的终端也不同程度地兼容可选的“VT100”、“VT103”或“ANSI”模式。 随着越来越多的软件(尤其是BBS系统)普及,越来越多的软件依赖转义序列起作用,导致几乎所有新的终端和终端模拟器都支持了此标准。
1981年,ANSI X3.64被美国政府采用(FIPS 86)。后来,美国政府停止复制行业标准,所以FIPS 86又被撤回了。
ECMA-48已经经历了多次更新换代,目前是从1991年开始的第5版。它也被ISO和IEC用作标准ISO/IEC 6429。
平台支持
类Unix系统和AmigaOS
随着诸多BBS和线上服务广泛使用ANSI,到20世纪80年代中期,ANSI几乎得到了全平台支持。尽管许多操作系统在标准文本输出中越来越多地支持ANSI,但大多数情况下ANSI支持是由终端模拟器完成的(例如Unix/Linux上的xterm、、Konsole,MacOS上的OS X Terminal或,以及IBM PC上的许多通信程序)。
Unix和AmigaOS都在操作系统中包含了对ANSI的一些支持,因此在这些平台上运行的程序广泛使用ANSI。 类Unix操作系统可以通过像和之类的库来生成ANSI代码,许多软件使用这些库升级显示方式。这些库也应该支持非ANSI终端,但是现在很少有人测试,所以很可能已经不起作用了。许多游戏和shell脚本直接输出ANSI序列(如彩色的提示信息),因此无法在不支持ANSI的终端上运行。
AmigaOS不仅支持输出到屏幕上的文本使用ANSI序列,还支持打印机驱动程序使用ANSI序列(需要AmigaOS的专有扩展,这会将它们转换为与特定打印机实际通信所需的代码)。
尽管ANSI很普及,却并没有得到全平台支持。比如原始的“经典”Mac OS就没有内置对ANSI的支持,再比如Atari ST使用的是VT52改编的命令系统,需要用一些扩展程序来支持颜色显示。
Windows和DOS
MS-DOS 1.x不支持ANSI或任何其他转义序列,只有少数控制字符(BEL、CR、LF、BS)可以由底层BIOS解释,所以几乎不可能做出任何全屏应用程序。所有显示效果都必须通过BIOS调用,或者直接控制IBM PC硬件来完成,调用速度非常慢。
DOS 2.0引入了添加设备驱动程序来支持ANSI转义序列的功能(事实上的标准是ANSI.SYS,但也使用了ANSI.COM、NANSI.SYS和ANSIPLUS.EXE等其他程序。因为绕过了BIOS,所以这些程序的速度比以前快了不少)。但由于实际运行速度仍然比较慢,以及默认并没有安装,所以还是很少得到利用。应用程序往往还是继续用直接控制硬件的方式来显示所需的文本。ANSI.SYS和类似的驱动程序继续在Windows 9x上工作,直到Windows Me,在NT衍生系统中用于在下执行的16位传统程序。
Win32控制台完全不支持ANSI转义序列。不过有一些控制台的替代品或者附加软件具有解释程序输出的ANSI转义序列的功能,例如JP Software的TCC(以前的4NT)、Michael J. Mefford的ANSI.COM、Jason Hood的ANSICON和Maximus5的ConEmu。有一个Python软件包在内部解释了打印文本中的ANSI转义序列,将它们转换为系统调用来操纵颜色和光标位置,以便更容易地将使用ANSI的Python代码移植到Windows。
2016年,在Windows 10发布“Threshold 2”时,微软开始在控制台应用程序中支持ANSI转义序列,使得从Unix移植软件或者远程访问Unix变得更容易。这是与Windows Subsystem for Linux一起完成的,允许基于终端的类Unix软件在Win32控制台中使用转义序列。2019年,微软推出了Windows Terminal,并且正在用其替换掉Win32控制台
转义序列
序列具有不同的长度。所有序列都以ASCII字符ESC(27 / 十六进制 0x1B)开头,第二个字节则是0x40–0x5F(ASCII @A–Z[\]^_)范围内的字符。
|- id=OSC
| || 0x9d || || 启动操作系统使用的控制字符串。OSC序列与CSI序列相似,但不限于整数参数。通常,这些控制序列由ST终止
! CMD
! Terminal.app
! PuTTY
! mIRC
! xterm
!
! Ubuntu
|-
| 黑 || 30 || 40
| colspan="7" style="background: #000; color: white" | 0,0,0
| style="background: #010101; color: white" | 1,1,1
|-
| 红 || 31 || 41
| style="background: #AA0000; color: white" | 170,0,0
| style="background: #800000; color: white" | 128,0,0
| style="background: #c23621; color: white" | 194,54,33
| style="background: #bb0000; color: white" | 187,0,0
| style="background: #7f0000; color: white" | 127,0,0
| style="background: #cd0000; color: white" | 205,0,0
| style="background: #ff0000; color: white" | 255,0,0
| style="background: #de382b; color: white" | 222,56,43
|-
| 绿 || 32 || 42
| style="background: #00AA00; color: white" | 0,170,0
| style="background: #008000; color: white" | 0,128,0
| style="background: #25bc26; color: white" | 37,188,36
| style="background: #00bb00; color: white" | 0,187,0
| style="background: #009300; color: white" | 0,147,0
| style="background: #00cd00; color: white" | 0,205,0
| style="background: #00ff00; color: black" | 0,255,0
| style="background: #39b54a; color: black" | 57,181,74
|-
| 黄 || 33 || 43
| style="background: #AA5500; color: white" | 170,85,0
| style="background: #808000; color: white" | 128,128,0
| style="background: #adad27; color: white" | 173,173,39
| style="background: #bbbb00; color: black" | 187,187,0
| style="background: #fc7f00; color: white" | 252,127,0
| style="background: #cdcd00; color: black" | 205,205,0
| style="background: #ffff00; color: black" | 255,255,0
| style="background: #ffc706; color: black" | 255,199,6
|-
| 蓝 || 34 || 44
| style="background: #0000AA; color: white" | 0,0,170
| style="background: #000080; color: white" | 0,0,128
| style="background: #492ee1; color: white" | 73,46,225
| style="background: #0000bb; color: white" | 0,0,187
| style="background: #00007f; color: white" | 0,0,127
| style="background: #0000ee; color: white" | 0,0,238
| style="background: #0000ff; color: white" | 0,0,255
| style="background: #006fb8; color: white" | 0,111,184
|-
| 品红 || 35 || 45
| style="background: #AA00AA; color: white" | 170,0,170
| style="background: #800080; color: white" | 128,0,128
| style="background: #d338d3; color: white" | 211,56,211
| style="background: #bb00bb; color: white" | 187,0,187
| style="background: #9c009c; color: white" | 156,0,156
| style="background: #cd00cd; color: white" | 205,0,205
| style="background: #ff00ff; color: black" | 255,0,255
| style="background: #762671; color: white" | 118,38,113
|-
| 青 || 36 || 46
| style="background: #00AAAA; color: white" | 0,170,170
| style="background: #008080; color: white" | 0,128,128
| style="background: #33bbc8; color: white" | 51,187,200
| style="background: #00bbbb; color: black" | 0,187,187
| style="background: #009393; color: white" | 0,147,147
| style="background: #00cdcd; color: black" | 0,205,205
| style="background: #00ffff; color: black" | 0,255,255
| style="background: #2cb5e9; color: black" | 44,181,233
|-
| 白 || 37 || 47
| style="background: #AAAAAA; color: black" | 170,170,170
| style="background: #c0c0c0; color: black" | 192,192,192
| style="background: #cbcccd; color: black" | 203,204,205
| style="background: #bbbbbb; color: black" | 187,187,187
| style="background: #d2d2d2; color: black" | 210,210,210
| style="background: #e5e5e5; color: black" | 229,229,229
| style="background: #ffffff; color: black" | 255,255,255
| style="background: #cccccc; color: black" | 204,204,204
|-
| 亮黑(灰) || 90 || 100
| style="background: #555555; color: white" | 85,85,85
| style="background: #808080; color: black" | 128,128,128
| style="background: #818383; color: black" | 129,131,131
| style="background: #555555; color: white" | 85,85,85
| style="background: #7f7f7f; color: white" | 127,127,127
| style="background: #7f7f7f; color: white" | 127,127,127
|
| style="background: #808080; color: black" | 128,128,128
|-
| 亮红 || 91 || 101
| style="background: #FF5555; color: white" | 255,85,85
| style="background: #ff0000; color: white" | 255,0,0
| style="background: #fc391f; color: white" | 252,57,31
| style="background: #ff5555; color: white" | 255,85,85
| style="background: #ff0000; color: white" | 255,0,0
| style="background: #ff0000; color: white" | 255,0,0
|
| style="background: #ff0000; color: white" | 255,0,0
|-
|| 亮绿 || 92 || 102
| style="background: #55FF55; color: black" | 85,255,85
| style="background: #00ff00; color: black" | 0,255,0
| style="background: #31e722; color: black" | 49,231,34
| style="background: #55ff55; color: black" | 85,255,85
| style="background: #00fc00; color: black" | 0,252,0
| style="background: #00ff00; color: black" | 0,255,0
| style="background: #90ee90; color: black" | 144,238,144
| style="background: #00ff00; color: black" | 0,255,0
|-
|| 亮黄 || 93 || 103
| style="background: #FFFF55; color: black" | 255,255,85
| style="background: #ffff00; color: black" | 255,255,0
| style="background: #eaec23; color: black" | 234,236,35
| style="background: #ffff55; color: black" | 255,255,85
| style="background: #ffff00; color: black" | 255,255,0
| style="background: #ffff00; color: black" | 255,255,0
| style="background: #ffffe0; color: black" | 255,255,224
| style="background: #ffff00; color: black" | 255,255,0
|-
|| 亮蓝 || 94 || 104
| style="background: #5555FF; color: white" | 85,85,255
| style="background: #0000ff; color: white" | 0,0,255
| style="background: #5833ff; color: black" | 88,51,255
| style="background: #5555ff; color: black" | 85,85,255
| style="background: #0000fc; color: white" | 0,0,252
| style="background: #5c5cff; color: black" | 92,92,255
| style="background: #acd8e6; color: black" | 173,216,230
| style="background: #0000ff; color: white" | 0,0,255
|-
|| 亮品红 || 95 || 105
| style="background: #FF55FF; color: black" | 255,85,255
| style="background: #ff00ff; color: white" | 255,0,255
| style="background: #f935f8; color: black" | 249,53,248
| style="background: #ff55ff; color: black" | 255,85,255
| style="background: #ff00ff; color: white" | 255,0,255
| style="background: #ff00ff; color: white" | 255,0,255
|
| style="background: #ff00ff; color: white" | 255,0,255
|-
|| 亮青 || 96 || 106
| style="background: #55FFFF; color: black" | 85,255,255
| style="background: #00ffff; color: black" | 0,255,255
| style="background: #14f0f0; color: black" | 20,240,240
| style="background: #55ffff; color: black" | 85,255,255
| style="background: #00ffff; color: black" | 0,255,255
| style="background: #00ffff; color: black" | 0,255,255
| style="background: #e0ffff; color: black" | 224,255,255
| style="background: #00ffff; color: black" | 0,255,255
|-
|| 亮白 || 97 || 107
| style="background: #FFFFFF; color: black" | 255,255,255
| style="background: #ffffff; color: black" | 255,255,255
| style="background: #e9ebeb; color: black" | 233,235,235
| style="background: #ffffff; color: black" | 255,255,255
| style="background: #ffffff; color: black" | 255,255,255
| style="background: #ffffff; color: black" | 255,255,255
|
| style="background: #ffffff; color: black" | 255,255,255
|}
8位
随着256色查找表在显卡上越来越常见,相应的转义序列也增加了,以从预定义的256种颜色中选择:使用“:”作为分隔符:
ESC[ … 38:5: … m选择前景色(n是下表中的一种)
ESC[ … 48:5: … m选择背景色
|-
| colspan="36" |216色
|-
| style="color:#ffffff;background:#000000;" title="#000000" |16
| style="color:#ffffff;background:#00005f;" title="#00005f" |17
| style="color:#ffffff;background:#000087;" title="#000087" |18
| style="color:#ffffff;background:#0000af;" title="#0000af" |19
| style="color:#ffffff;background:#0000d7;" title="#0000d7" |20
| style="color:#ffffff;background:#0000ff;" title="#0000ff" |21
| style="color:#ffffff;background:#005f00;" title="#005f00" |22
| style="color:#ffffff;background:#005f5f;" title="#005f5f" |23
| style="color:#ffffff;background:#005f87;" title="#005f87" |24
| style="color:#ffffff;background:#005faf;" title="#005faf" |25
| style="color:#ffffff;background:#005fd7;" title="#005fd7" |26
| style="color:#ffffff;background:#005fff;" title="#005fff" |27
| style="color:#ffffff;background:#008700;" title="#008700" |28
| style="color:#ffffff;background:#00875f;" title="#00875f" |29
| style="color:#ffffff;background:#008787;" title="#008787" |30
| style="color:#ffffff;background:#0087af;" title="#0087af" |31
| style="color:#ffffff;background:#0087d7;" title="#0087d7" |32
| style="color:#ffffff;background:#0087ff;" title="#0087ff" |33
| style="color:#000000;background:#00af00;" title="#00af00" |34
| style="color:#000000;background:#00af5f;" title="#00af5f" |35
| style="color:#000000;background:#00af87;" title="#00af87" |36
| style="color:#000000;background:#00afaf;" title="#00afaf" |37
| style="color:#000000;background:#00afd7;" title="#00afd7" |38
| style="color:#000000;background:#00afff;" title="#00afff" |39
| style="color:#000000;background:#00d700;" title="#00d700" |40
| style="color:#000000;background:#00d75f;" title="#00d75f" |41
| style="color:#000000;background:#00d787;" title="#00d787" |42
| style="color:#000000;background:#00d7af;" title="#00d7af" |43
| style="color:#000000;background:#00d7d7;" title="#00d7d7" |44
| style="color:#000000;background:#00d7ff;" title="#00d7ff" |45
| style="color:#000000;background:#00ff00;" title="#00ff00" |46
| style="color:#000000;background:#00ff5f;" title="#00ff5f" |47
| style="color:#000000;background:#00ff87;" title="#00ff87" |48
| style="color:#000000;background:#00ffaf;" title="#00ffaf" |49
| style="color:#000000;background:#00ffd7;" title="#00ffd7" |50
| style="color:#000000;background:#00ffff;" title="#00ffff" |51
|-
| style="color:#ffffff;background:#5f0000;" title="#5f0000" |52
| style="color:#ffffff;background:#5f005f;" title="#5f005f" |53
| style="color:#ffffff;background:#5f0087;" title="#5f0087" |54
| style="color:#ffffff;background:#5f00af;" title="#5f00af" |55
| style="color:#ffffff;background:#5f00d7;" title="#5f00d7" |56
| style="color:#ffffff;background:#5f00ff;" title="#5f00ff" |57
| style="color:#ffffff;background:#5f5f00;" title="#5f5f00" |58
| style="color:#ffffff;background:#5f5f5f;" title="#5f5f5f" |59
| style="color:#ffffff;background:#5f5f87;" title="#5f5f87" |60
| style="color:#ffffff;background:#5f5faf;" title="#5f5faf" |61
| style="color:#ffffff;background:#5f5fd7;" title="#5f5fd7" |62
| style="color:#ffffff;background:#5f5fff;" title="#5f5fff" |63
| style="color:#ffffff;background:#5f8700;" title="#5f8700" |64
| style="color:#ffffff;background:#5f875f;" title="#5f875f" |65
| style="color:#ffffff;background:#5f8787;" title="#5f8787" |66
| style="color:#ffffff;background:#5f87af;" title="#5f87af" |67
| style="color:#ffffff;background:#5f87d7;" title="#5f87d7" |68
| style="color:#ffffff;background:#5f87ff;" title="#5f87ff" |69
| style="color:#000000;background:#5faf00;" title="#5faf00" |70
| style="color:#000000;background:#5faf5f;" title="#5faf5f" |71
| style="color:#000000;background:#5faf87;" title="#5faf87" |72
| style="color:#000000;background:#5fafaf;" title="#5fafaf" |73
| style="color:#000000;background:#5fafd7;" title="#5fafd7" |74
| style="color:#000000;background:#5fafff;" title="#5fafff" |75
| style="color:#000000;background:#5fd700;" title="#5fd700" |76
| style="color:#000000;background:#5fd75f;" title="#5fd75f" |77
| style="color:#000000;background:#5fd787;" title="#5fd787" |78
| style="color:#000000;background:#5fd7af;" title="#5fd7af" |79
| style="color:#000000;background:#5fd7d7;" title="#5fd7d7" |80
| style="color:#000000;background:#5fd7ff;" title="#5fd7ff" |81
| style="color:#000000;background:#5fff00;" title="#5fff00" |82
| style="color:#000000;background:#5fff5f;" title="#5fff5f" |83
| style="color:#000000;background:#5fff87;" title="#5fff87" |84
| style="color:#000000;background:#5fffaf;" title="#5fffaf" |85
| style="color:#000000;background:#5fffd7;" title="#5fffd7" |86
| style="color:#000000;background:#5fffff;" title="#5fffff" |87
|-
| style="color:#ffffff;background:#870000;" title="#870000" |88
| style="color:#ffffff;background:#87005f;" title="#87005f" |89
| style="color:#ffffff;background:#870087;" title="#870087" |90
| style="color:#ffffff;background:#8700af;" title="#8700af" |91
| style="color:#ffffff;background:#8700d7;" title="#8700d7" |92
| style="color:#ffffff;background:#8700ff;" title="#8700ff" |93
| style="color:#ffffff;background:#875f00;" title="#875f00" |94
| style="color:#ffffff;background:#875f5f;" title="#875f5f" |95
| style="color:#ffffff;background:#875f87;" title="#875f87" |96
| style="color:#ffffff;background:#875faf;" title="#875faf" |97
| style="color:#ffffff;background:#875fd7;" title="#875fd7" |98
| style="color:#ffffff;background:#875fff;" title="#875fff" |99
| style="color:#ffffff;background:#878700;" title="#878700" |100
| style="color:#ffffff;background:#87875f;" title="#87875f" |101
| style="color:#ffffff;background:#878787;" title="#878787" |102
| style="color:#ffffff;background:#8787af;" title="#8787af" |103
| style="color:#ffffff;background:#8787d7;" title="#8787d7" |104
| style="color:#ffffff;background:#8787ff;" title="#8787ff" |105
| style="color:#000000;background:#87af00;" title="#87af00" |106
| style="color:#000000;background:#87af5f;" title="#87af5f" |107
| style="color:#000000;background:#87af87;" title="#87af87" |108
| style="color:#000000;background:#87afaf;" title="#87afaf" |109
| style="color:#000000;background:#87afd7;" title="#87afd7" |110
| style="color:#000000;background:#87afff;" title="#87afff" |111
| style="color:#000000;background:#87d700;" title="#87d700" |112
| style="color:#000000;background:#87d75f;" title="#87d75f" |113
| style="color:#000000;background:#87d787;" title="#87d787" |114
| style="color:#000000;background:#87d7af;" title="#87d7af" |115
| style="color:#000000;background:#87d7d7;" title="#87d7d7" |116
| style="color:#000000;background:#87d7ff;" title="#87d7ff" |117
| style="color:#000000;background:#87ff00;" title="#87ff00" |118
| style="color:#000000;background:#87ff5f;" title="#87ff5f" |119
| style="color:#000000;background:#87ff87;" title="#87ff87" |120
| style="color:#000000;background:#87ffaf;" title="#87ffaf" |121
| style="color:#000000;background:#87ffd7;" title="#87ffd7" |122
| style="color:#000000;background:#87ffff;" title="#87ffff" |123
|-
| style="color:#ffffff;background:#af0000;" title="#af0000" |124
| style="color:#ffffff;background:#af005f;" title="#af005f" |125
| style="color:#ffffff;background:#af0087;" title="#af0087" |126
| style="color:#ffffff;background:#af00af;" title="#af00af" |127
| style="color:#ffffff;background:#af00d7;" title="#af00d7" |128
| style="color:#ffffff;background:#af00ff;" title="#af00ff" |129
| style="color:#ffffff;background:#af5f00;" title="#af5f00" |130
| style="color:#ffffff;background:#af5f5f;" title="#af5f5f" |131
| style="color:#ffffff;background:#af5f87;" title="#af5f87" |132
| style="color:#ffffff;background:#af5faf;" title="#af5faf" |133
| style="color:#ffffff;background:#af5fd7;" title="#af5fd7" |134
| style="color:#ffffff;background:#af5fff;" title="#af5fff" |135
| style="color:#ffffff;background:#af8700;" title="#af8700" |136
| style="color:#ffffff;background:#af875f;" title="#af875f" |137
| style="color:#ffffff;background:#af8787;" title="#af8787" |138
| style="color:#ffffff;background:#af87af;" title="#af87af" |139
| style="color:#ffffff;background:#af87d7;" title="#af87d7" |140
| style="color:#ffffff;background:#af87ff;" title="#af87ff" |141
| style="color:#000000;background:#afaf00;" title="#afaf00" |142
| style="color:#000000;background:#afaf5f;" title="#afaf5f" |143
| style="color:#000000;background:#afaf87;" title="#afaf87" |144
| style="color:#000000;background:#afafaf;" title="#afafaf" |145
| style="color:#000000;background:#afafd7;" title="#afafd7" |146
| style="color:#000000;background:#afafff;" title="#afafff" |147
| style="color:#000000;background:#afd700;" title="#afd700" |148
| style="color:#000000;background:#afd75f;" title="#afd75f" |149
| style="color:#000000;background:#afd787;" title="#afd787" |150
| style="color:#000000;background:#afd7af;" title="#afd7af" |151
| style="color:#000000;background:#afd7d7;" title="#afd7d7" |152
| style="color:#000000;background:#afd7ff;" title="#afd7ff" |153
| style="color:#000000;background:#afff00;" title="#afff00" |154
| style="color:#000000;background:#afff5f;" title="#afff5f" |155
| style="color:#000000;background:#afff87;" title="#afff87" |156
| style="color:#000000;background:#afffaf;" title="#afffaf" |157
| style="color:#000000;background:#afffd7;" title="#afffd7" |158
| style="color:#000000;background:#afffff;" title="#afffff" |159
|-
| style="color:#ffffff;background:#d70000;" title="#d70000" |160
| style="color:#ffffff;background:#d7005f;" title="#d7005f" |161
| style="color:#ffffff;background:#d70087;" title="#d70087" |162
| style="color:#ffffff;background:#d700af;" title="#d700af" |163
| style="color:#ffffff;background:#d700d7;" title="#d700d7" |164
| style="color:#ffffff;background:#d700ff;" title="#d700ff" |165
| style="color:#ffffff;background:#d75f00;" title="#d75f00" |166
| style="color:#ffffff;background:#d75f5f;" title="#d75f5f" |167
| style="color:#ffffff;background:#d75f87;" title="#d75f87" |168
| style="color:#ffffff;background:#d75faf;" title="#d75faf" |169
| style="color:#ffffff;background:#d75fd7;" title="#d75fd7" |170
| style="color:#ffffff;background:#d75fff;" title="#d75fff" |171
| style="color:#ffffff;background:#d78700;" title="#d78700" |172
| style="color:#ffffff;background:#d7875f;" title="#d7875f" |173
| style="color:#ffffff;background:#d78787;" title="#d78787" |174
| style="color:#ffffff;background:#d787af;" title="#d787af" |175
| style="color:#ffffff;background:#d787d7;" title="#d787d7" |176
| style="color:#ffffff;background:#d787ff;" title="#d787ff" |177
| style="color:#000000;background:#d7af00;" title="#d7af00" |178
| style="color:#000000;background:#d7af5f;" title="#d7af5f" |179
| style="color:#000000;background:#d7af87;" title="#d7af87" |180
| style="color:#000000;background:#d7afaf;" title="#d7afaf" |181
| style="color:#000000;background:#d7afd7;" title="#d7afd7" |182
| style="color:#000000;background:#d7afff;" title="#d7afff" |183
| style="color:#000000;background:#d7d700;" title="#d7d700" |184
| style="color:#000000;background:#d7d75f;" title="#d7d75f" |185
| style="color:#000000;background:#d7d787;" title="#d7d787" |186
| style="color:#000000;background:#d7d7af;" title="#d7d7af" |187
| style="color:#000000;background:#d7d7d7;" title="#d7d7d7" |188
| style="color:#000000;background:#d7d7ff;" title="#d7d7ff" |189
| style="color:#000000;background:#d7ff00;" title="#d7ff00" |190
| style="color:#000000;background:#d7ff5f;" title="#d7ff5f" |191
| style="color:#000000;background:#d7ff87;" title="#d7ff87" |192
| style="color:#000000;background:#d7ffaf;" title="#d7ffaf" |193
| style="color:#000000;background:#d7ffd7;" title="#d7ffd7" |194
| style="color:#000000;background:#d7ffff;" title="#d7ffff" |195
|-
| style="color:#ffffff;background:#ff0000;" title="#ff0000" |196
| style="color:#ffffff;background:#ff005f;" title="#ff005f" |197
| style="color:#ffffff;background:#ff0087;" title="#ff0087" |198
| style="color:#ffffff;background:#ff00af;" title="#ff00af" |199
| style="color:#ffffff;background:#ff00d7;" title="#ff00d7" |200
| style="color:#ffffff;background:#ff00ff;" title="#ff00ff" |201
| style="color:#ffffff;background:#ff5f00;" title="#ff5f00" |202
| style="color:#ffffff;background:#ff5f5f;" title="#ff5f5f" |203
| style="color:#ffffff;background:#ff5f87;" title="#ff5f87" |204
| style="color:#ffffff;background:#ff5faf;" title="#ff5faf" |205
| style="color:#ffffff;background:#ff5fd7;" title="#ff5fd7" |206
| style="color:#ffffff;background:#ff5fff;" title="#ff5fff" |207
| style="color:#ffffff;background:#ff8700;" title="#ff8700" |208
| style="color:#ffffff;background:#ff875f;" title="#ff875f" |209
| style="color:#ffffff;background:#ff8787;" title="#ff8787" |210
| style="color:#ffffff;background:#ff87af;" title="#ff87af" |211
| style="color:#ffffff;background:#ff87d7;" title="#ff87d7" |212
| style="color:#ffffff;background:#ff87ff;" title="#ff87ff" |213
| style="color:#000000;background:#ffaf00;" title="#ffaf00" |214
| style="color:#000000;background:#ffaf5f;" title="#ffaf5f" |215
| style="color:#000000;background:#ffaf87;" title="#ffaf87" |216
| style="color:#000000;background:#ffafaf;" title="#ffafaf" |217
| style="color:#000000;background:#ffafd7;" title="#ffafd7" |218
| style="color:#000000;background:#ffafff;" title="#ffafff" |219
| style="color:#000000;background:#ffd700;" title="#ffd700" |220
| style="color:#000000;background:#ffd75f;" title="#ffd75f" |221
| style="color:#000000;background:#ffd787;" title="#ffd787" |222
| style="color:#000000;background:#ffd7af;" title="#ffd7af" |223
| style="color:#000000;background:#ffd7d7;" title="#ffd7d7" |224
| style="color:#000000;background:#ffd7ff;" title="#ffd7ff" |225
| style="color:#000000;background:#ffff00;" title="#ffff00" |226
| style="color:#000000;background:#ffff5f;" title="#ffff5f" |227
| style="color:#000000;background:#ffff87;" title="#ffff87" |228
| style="color:#000000;background:#ffffaf;" title="#ffffaf" |229
| style="color:#000000;background:#ffffd7;" title="#ffffd7" |230
| style="color:#000000;background:#ffffff;" title="#ffffff" |231
|-
|-
| colspan="36" |灰度色
|-
| colspan="36" |
|}
24位
随着16位到24位颜色的“真彩色”显卡的普及,Xterm、KDE的Konsole,以及所有基于libvte的终端(包括)支持了ISO-8613-3的24位前景色和背景色设置。
ESC[ … 38;2;;;<b> … m选择RGB前景色
ESC[ … 48;2;;;<b> … m选择RGB背景色
作为ISO / IEC国际标准8613-6采用的ITU的T.416信息技术-开放文档体系结构(ODA)和交换格式:字符内容体系结构
make 2>&1 | sed -e 's/.\bWARN./\x1b[7m&\x1b[0m/i' -e 's/.\bERR./\x1b[93;41 m&\x1b[0m/i'
以下Bash函数会使终端闪烁(通过交替发送反相和正常显示模式代码),直到用户按下任意键。这个函数可以用于当一个冗长的命令终止时提醒用户,用法如make; flasher。
flasher () { while true; do printf \\e[?5h; sleep 0.1; printf \\e[?5l; read -s -n1 -t1 && break; done; }
下面这个命令可以重置控制台,类似现代Linux系统的reset命令。然而,即使在较早的Linux系统和其他(非Linux)UNIX变体上,也应该能起作用。
printf \\033c
参见
- 控制字符
脚注
参考资料
外部链接
- [http://www.ecma-international.org/publications/standards/Ecma-048.htm Standard ECMA-48, Control Functions For Coded Character Sets]. (5th edition, June 1991), European Computer Manufacturers Association, Geneva 1991 (also published by ISO and IEC as standard ISO/IEC 6429)
- [http://vt100.net/docs/ vt100.net DEC Documents]
*
- [http://invisible-island.net/xterm/ctlseqs/ctlseqs.html Xterm / Escape Sequences]
- [http://publib.boulder.ibm.com/infocenter/aix/v6r1/index.jsp?topic=%2Fcom.ibm.aix.cmds%2Fdoc%2Faixcmds1%2Faixterm.htm AIXterm / Escape Sequences]
- [http://bjh21.me.uk/all-escapes/all-escapes.txt A collection of escape sequences for terminals that are vaguely compliant with ECMA-48 and friends.]
- [http://ascii-table.com/ansi-escape-sequences.php ANSI Escape Sequences]
- [https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.416-199303-I!!PDF-E&type=items ITU-T Rec. T.416 (03/93) Information technology – Open Document Architecture (ODA) and interchange format: Character content architectures]
评论 (0)