问题描述
我正在寻找使用 ANSI 或其他标准在终端中创建橙色文本的控制代码,这可能吗?我只看到黄色和红色可用,我认为您不能将红色和黄色混合用于同一个角色:)
I am looking for a control code to create orange text in a terminal using ANSI or some other standard, is this possible? I only see yellow and red available, and I don't think you can mix red and yellow for the same character :)
推荐答案
严格来说,没有:ANSI 从未标准化任何称为橙色"的东西(对于终端的控制序列).一些终端可以做到这一点,但这超出了标准的范围.
Strictly speaking, no: ANSI never standardized anything (for a terminal's control sequences) which was called "orange". Some terminals can do this, but that lies outside the scope of the standards.
xterm(参见 XTerm Control Sequences)使用遵循ANSI"(实际上早就退出标准化了)ECMA-48 语法.
xterm (see XTerm Control Sequences) uses control sequences following the "ANSI" (actually withdrawn from standardization long ago) ECMA-48 syntax.
- 其中一些是 SGR 提供的标准 8 种颜色(不包括橙色).
- 它还(使用 aixterm SGR 扩展)添加了另外 8 种颜色.仍然没有橙色.
- 但是,xterm 扩展了(以不完全标准的方式)SGR 代码 38 和 48,以提供使用 RGB(红/绿/蓝)值的调色板.最大调色板大小编译为 88 或 256 色.
- Some of those are the standard 8 colors via SGR (which do not include orange).
- It also (using the aixterm SGR extension) adds another 8 colors. Still no orange.
- However, xterm extends (in a way not exactly standard) SGR codes 38 and 48 to provide a palette of colors using RGB (red/green/blue) values. The maximum palette size is compiled in as either 88 or 256 colors.
Orange 可以由 RGB 代码组成.例如 X 的 rgb.txt 文件将其定义为
Orange can be composed by an RGB code. For instance X's rgb.txt file defines it as
255 165 0 orange
(亮红色加上适度的亮绿色).要在 shell 脚本中获取它,可以使用
(bright red plus a moderately bright green). To get that in a shell script, one could use
#!/bin/sh
printf " 33[48:2:255:165:0m%s 33[m
" "Hello world"
printf " 33[48;2;255;165;0m%s 33[m
" "Hello world"
这两行之间的区别在于使用冒号作为参数分隔符(ECMA-48 有一些偏爱的措辞,对于 xterm 中使用的 子参数,这在早期被忽略了).为了兼容性(包括从 xterm 的早期实现中复制的终端),xterm 尊重两者.
The difference between the two lines is the use of colon as a parameter separator (ECMA-48 has some verbiage which prefers that, for subparameters as used in xterm, which was overlooked early on). For compatibility (including with terminals copied from xterm's early implementation), xterm honors both.
xterm 还支持称为动态颜色的非 ANSI"方案,它接受颜色名称,但它会设置整个屏幕的文本颜色.
xterm also supports a "non-ANSI" scheme referred to as dynamic colors, which accepts a color name, but that sets the text color for the whole screen.
最后,xterm 可以为显示指定颜色,而不是闪烁、粗体、斜体、反转和下划线(例如,参见 colorBD
的讨论).这是通过 X 资源设置完成的(在转义序列的帮助下).可以通过相同的 88/256 色扩展设置分配给这些资源的颜色.
Finally, xterm can assign colors to display instead of blink, bold, italics, reverse and underline (see the discussion of colorBD
for instance). That is done though X resource settings (with some help from escape sequences). The colors assigned to those resources can be set via the same 88/256 color extension.
这篇关于有没有办法从 ANSI 转义字符创建橙色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!