有没有办法从ANSI转义字符创建橙色? [英] Is there a way to create an Orange color from ANSI escape characters?

查看:222
本文介绍了有没有办法从ANSI转义字符创建橙色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种控制代码,以在使用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控制序列)使用遵循"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.

橙色可以由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 "\033[48:2:255:165:0m%s\033[m\n" "Hello world"
printf "\033[48;2;255;165;0m%s\033[m\n" "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"方案,该方案接受颜色 name ,但可以设置整个屏幕的文本颜色.

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转义字符创建橙色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆