ANSI 颜色代码表

・4 分钟阅读

3/4 bit

原始规格只有8种颜色,只是给它们起了名字。 SGR参数30-37选择前景色,而40-47选择背景色。 相当多的终端将"粗体"实现为更亮的颜色, 而不是不同的字体,从而提供8种额外的前景色。 通常你不能将这些作为背景颜色,尽管有时反向视频(SGR代码7)会允许这样做。 例子:在白色背景上获得黑色字母使用ESC [30; 47m,得到红色使用ESC [31m,得到鲜红色使用ESC [1; 31m。 要将颜色重置为默认值,请使用ESC [39; 49m(某些终端不支持),或使用ESC [0m重置所有属性]。 后来的终端增加了直接指定90-97和100-107的"明亮"颜色的能力。

当硬件开始使用8位DAC时,几个软件为这些名称分配了24位颜色编号。 下图显示了针对某些常见硬件和软件发送到DAC的值

NameFG CodeBG CodeVGA[nb 2]Windows Console[nb 3]Windows PowerShell[nb 4]Windows 10 Console[nb 5]
PowerShell 6
Terminal.appPuTTYmIRCxtermX[nb 6]Ubuntu[nb 7]
Black30400,0,012,12,120,0,01,1,1
Red3141170,0,0128,0,0197,15,31194,54,33187,0,0127,0,0205,0,0255,0,0222,56,43
Green32420,170,00,128,019,161,1437,188,360,187,00,147,00,205,00,255,057,181,74
Yellow3343170,85,0[nb 8]128,128,0238,237,240193,156,0173,173,39187,187,0252,127,0205,205,0255,255,0255,199,6
Blue34440,0,1700,0,1280,55,21873,46,2250,0,1870,0,1270,0,238[23]0,0,2550,111,184
Magenta3545170,0,170128,0,1281,36,86136,23,152211,56,211187,0,187156,0,156205,0,205255,0,255118,38,113
Cyan36460,170,1700,128,12858,150,22151,187,2000,187,1870,147,1470,205,2050,255,25544,181,233
White3747170,170,170192,192,192204,204,204203,204,205187,187,187210,210,210229,229,229255,255,255204,204,204
Bright Black9010085,85,85128,128,128118,118,118129,131,13185,85,85127,127,127127,127,127 128,128,128
Bright Red91101255,85,85255,0,0231,72,86252,57,31255,85,85255,0,0255,0,0 255,0,0
Bright Green9210285,255,850,255,022,198,1249,231,3485,255,850,252,00,255,0144,238,1440,255,0
Bright Yellow93103255,255,85255,255,0249,241,165234,236,35255,255,85255,255,0255,255,0255,255,224255,255,0
Bright Blue9410485,85,2550,0,25559,120,25588,51,25585,85,2550,0,25292,92,255[24]173,216,2300,0,255
Bright Magenta95105255,85,255255,0,255180,0,158249,53,248255,85,255255,0,255255,0,255 255,0,255
Bright Cyan9610685,255,2550,255,25597,214,21420,240,24085,255,2550,255,2550,255,255224,255,2550,255,255
Bright White97107255,255,255255,255,255242,242,242233,235,235255,255,255255,255,255255,255,255 255,255,255

8-bit

256-color mode — foreground: ESC[38;5;#m   background: ESC[48;5;#m
Standard colorsHigh-intensity colors
 0  1  2  3  4  5  6  7   8  9 101112131415
216 colors
161718192021222324252627282930313233343536373839404142434445464748495051
525354555657585960616263646566676869707172737475767778798081828384858687
888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
Grayscale colors
232233234235236237238239240241242243244245246247248249250251252253254255
Haojinghui profile image