- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我的问题是使用 ansi 颜色的一般 shell 脚本,但作为引用,我使用的是 Apple Mac OS X 10.9 Mavericks。我使用“iTerm”终端应用程序作为我的默认终端,但也使用内置的“终端”应用程序进行检查。我使用 ZSH (5.0.7) 作为我的默认 shell,但也检查了 BASH (3.2.51)。
我一直在试图找出是否有 256 种颜色索引的扩展前景/背景 Ansi 转义码的 RGB 值列表,这些值可以使用 esc[38;5;xm 和 esc[48;5;xm,其中 x 是一个从 0 到 255 的数字。我发现了一些将颜色打印为块(使用索引)的脚本,但我想知道索引中每种颜色的 rgb 值。
这是正在使用的 ansi 代码的示例:
printf '\e[38;5;222;48;5;238m Hi \e[m\n'
最佳答案
256色表及其分区
256 色终端的颜色范围由 4 部分组成,通常是 5 部分,在这种情况下,您实际上会得到 258 种颜色:
number = 16 + 36 * r + 6 * g + b
r
, g
和 b
在 0 - 5 范围内。print '\e[m'
)时,您会得到它们。 urxvt
联机帮助页:In addition to the default foreground and background colours, urxvt can display up to 88/256 colours: 8 ANSI colours plus high-intensity (potentially bold/blink) versions of the same, and 72 (or 240 in 256 colour mode) colours arranged in an 4x4x4 (or 6x6x6) colour RGB cube plus a 8 (24) colour greyscale ramp.
xterm
联机帮助页:These specify the colors for the 256-color extension. The default resource values are for colors 16 through 231 to make a 6x6x6 color cube, and colors 232 through 255 to make a grayscale ramp.
# example in Python: // is integer divison, % is modulo
rgb_R = ((number - 16) // 36) * 51
rgb_G = (((number - 16) % 36) // 6) * 51
rgb_B = ((number - 16) % 6) * 51
[0, 1, 2, 3, 4, 5]
红色、绿色和蓝色的值
[0, 95, 135, 175, 215, 255]
在 RGB 色轴上。 (我使用 XTerm (297) URxvt (v9.19)、ROXTerm (2.8.1)、gnome-terminal (3.6.2) 和 xfce4-terminal (0.6.3) 进行了测试)
# example in Python: 'a = b if c else d' is 'a = (c) ? b : d` in C, Perl, etc.
index_R = ((number - 16) // 36)
rgb_R = 55 + index_R * 40 if index_R > 0 else 0
index_G = (((number - 16) % 36) // 6)
rgb_G = 55 + index_G * 40 if index_G > 0 else 0
index_B = ((number - 16) % 6)
rgb_B = 55 + index_B * 40 if index_B > 0 else 0
rgb_R = rgb_G = rgb_B = (number - 232) * 10 + 8
256colres.pl
在
XTerm sources (version 313) 的根使用类似的算法生成
256colres.h
,其中包含 256 色模式的颜色定义:
$line1="COLOR_RES(\"%d\",";
$line2="\tscreen.Acolors[%d],";
$line3="\tDFT_COLOR(\"rgb:%2.2x/%2.2x/%2.2x\")),\n";
# colors 16-231 are a 6x6x6 color cube
for ($red = 0; $red < 6; $red++) {
for ($green = 0; $green < 6; $green++) {
for ($blue = 0; $blue < 6; $blue++) {
$code = 16 + ($red * 36) + ($green * 6) + $blue;
printf($line1, $code);
printf($line2, $code);
printf($line3,
($red ? ($red * 40 + 55) : 0),
($green ? ($green * 40 + 55) : 0),
($blue ? ($blue * 40 + 55) : 0));
}
}
}
# colors 232-255 are a grayscale ramp, intentionally leaving out
# black and white
$code=232;
for ($gray = 0; $gray < 24; $gray++) {
$level = ($gray * 10) + 8;
$code = 232 + $gray;
printf($line1, $code);
printf($line2, $code);
printf($line3,
$level, $level, $level);
}
TERM
设置为 256 色值):
function termcolors ()
{
print TERM
print -P "Foreground: >█<"
print -P "Background: >%S█%s<\n"
print " 0 1 2 3 4 5 6 7"
for b (0 1)
do
printf "%d %2d " $b $(( 8 * b ))
for r (0 1 2 3 4 5 6 7)
do
c=$(( 8 * b + r ))
print -nP "%K{$c} %k"
done
printf " %2d\n" $(( 8 * b + 7 ))
done
print
print RGB
for r (0 1 2 3 4 5)
do
print "$r $(( 16 + 36 * r )) - $(( 16 + 36 * r + 35 ))\n 0 1 2 3 4 5"
for g (0 1 2 3 4 5)
do
printf "%d %3d " $g $(( 16 + 36 * r + 6 * g ))
for b (0 1 2 3 4 5)
do
c=$(( 16 + 36 * r + 6 * g + b ))
print -nP "%K{$c} %k"
done
printf " %3d\n" $(( 16 + 36 * r + 6 * g + 5))
done
print
done
print
print GRAY
for g in $(seq 0 23)
do
c=$(( 232 + g ))
printf "%2d %3d " $g $c
print -P "%K{$c} %k"
done
}
xterm
、
gnome-terminal
、
termite
和
urxvt
)中,所有这些颜色都可以在运行时通过发送以下之一来更改
XTerm Control Sequences :
OSC 4; c ; spec BEL
OSC 4; c ; spec ST
OSC
是转义字符( \e
或 \033
)后跟 ]
c
是颜色编号 (0 - 255) spec
是颜色规范(例如 red
、 #ff0000
、 rgb:ff/00/00
、 rgbi:1/0/0
- 实际工作可能取决于终端)BEL
是铃字符( \a
或 \007
)ST
是字符串终止符 \e\\
或 \033\\
echo
打印它们来发送。 :
echo -en "\e]4;COLOR;SPEC\a"
echo -en "\e]4;COLOR;SPEC\a"
echo -en "\e]4;5;red\a"
echo -en "\e]4;5;#ff0000\e\\"
echo -en "\033]4;5;rgb:ff/00/00\007"
OSC 104 ; c BEL
OSC 104 ; c ST
for c in {0..255}; do
echo -en "\e]104;$c\a"
done
OSC 10 ; spec BEL
和
OSC 11 ; spec BEL
, 分别。例如:
echo -en "\e]10;red\a"
echo -en "\e]11;green\a"
OSC 110 BEL
重置和
OSC 111 BEL
分别:
echo -en "\e]110\a"
echo -en "\e]111\a"
关于bash - Ansi 扩展颜色索引中颜色的 RGB 值 (17-255),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27159322/
我正在寻找一个控制代码来使用 ANSI 或其他一些标准在终端中创建橙色文本,这可能吗?我只看到黄色和红色可用,我认为您不能将红色和黄色混合用于同一个角色:) 最佳答案 严格来说,不:ANSI 从未标准
我知道 \33[nC移动光标 n列向前;问题是,我不知道特定行包含多少个字符。 最佳答案 什么都没有显式 ,但是屏幕“小”,您可以使用任何光标移动命令移动到任意远的目的地,终端将通过屏幕大小限制移动。
这个问题在这里已经有了答案: Oracle Joins - Comparison between conventional syntax VS ANSI Syntax (11 个回答) 8 年前关闭。
我知道在 bash 终端中,一种可靠的变色方法是使用 ANSI 转义序列。例如: echo -e "\033[0;31mbrown text\033[0;00m" 应该输出 brown text (i
上次我检查时,说您正在使用 ANSI C 编码等同于说“这是符合 C99 的代码,其中没有任何其他内容”。现在有了 C11 和 C++11,这种区别还存在吗?它还有某种意义吗? 最佳答案 历史上,“A
我的业务逻辑包含在大约 7000 行 T-SQL 存储过程中,其中大多数都具有下一个 JOIN 语法: SELECT A.A, B.B, C.C FROM aaa AS A, bbb AS B, cc
我的业务逻辑包含在大约 7000 行 T-SQL 存储过程中,其中大多数都具有下一个 JOIN 语法: SELECT A.A, B.B, C.C FROM aaa AS A, bbb AS B, cc
我正在使用 CentOS 7 和 PHP 7.0 TERM=xterm-256color 我确实有一个彩色提示和 ls 颜色,如果我通过 --ansi然后它确实显示为彩色,但我不想总是添加 --ans
在我工作过的每家公司,我发现人们仍然按照 ANSI-89 标准编写 SQL 查询: select a.id, b.id, b.address_1 from person a, address b wh
我正在使用 Delphi RIO 10.3.3。 当我将 Ansi 字符串作为 const 数组的元素之一传递时,string() 转换对其不起作用。为了让它工作,我必须先将 VAnsiString
我正在使用 Delphi RIO 10.3.3。 当我将 Ansi 字符串作为 const 数组的元素之一传递时,string() 转换对其不起作用。为了让它工作,我必须先将 VAnsiString
很难说出这里问的是什么。这个问题是含糊的、模糊的、不完整的、过于宽泛的或修辞性的,无法以目前的形式得到合理的回答。如需帮助澄清此问题以便重新打开它,visit the help center 。 已关
当我在终端上调整大小时,它保持全屏显示。我想,有某种方法可以找出终端的屏幕尺寸。我怎样才能在 VT100 中做到这一点? 使用 ,当我列出文件夹时,它以蓝色显示文件夹。 (或者让我们说不同的颜色)但是
我的程序正在向某个日志文件发送characters-colored文本: echo -e "\\033[38;5;2m-->\\033[0m Starting program." | tee $Log
我刚开始使用 gsoap。我只使用 c++ 取得了 4 个小成功,但是我当前的项目限制了我设置源代码生成选项来创建纯 ANSI C(不是 c++)。我似乎无法成功调用该服务,错误返回为 0xC0000
来自 http://blocktronics.org/ 的 ANSI 文件似乎使用的是另一种 ANSI 编码,而不是我的 VT100 终端仿真器支持的编码。 如果我使用 tetraview 查看这些文
如何在 Java 中将十六进制字符串转换为 ansi(窗口 1252)以及将 ansi(窗口 1252)转换为十六进制字符串。 python(完美运行) q = "hex string value"
我用 java 编写了一个 android 应用程序来获取用户答案并将它们保存在一个文件中。问题是这个文件是以 utf-8 格式保存的。最终用户将在 IBM SPSS 中打开这些文件,这是一种适用于
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 7年前关闭。 锁定。这个问题及其答案
这个问题在这里已经有了答案: 关闭 11 年前。 Possible Duplicates: Floating point inaccuracy examples Is JavaScript's Ma
我是一名优秀的程序员,十分优秀!