如何从 perl 脚本设置调色板颜色?

How to set the palette Colors from perl script?

我有一个 perl 脚本,可以为我的终端随机选择 FG 和 BG 颜色。 我使用以下打印命令即时设置 FG 和 BG:

   print "3]10;<fg_color>[=10=]7";
   print "3]11;<bg_color>[=10=]7";

我也需要设置调色板颜色,但我无法找到有关如何设置的示例。 谁能帮帮我?

我不认为你可以设置调色板。您只需从调色板 select 即可。有关示例,请参阅 here

调色板取决于您的终端。对于 XTerm,调色板设置在 ~/.Xresources 中。这是我当前的配置:

XTerm*color0:     rgb:00/00/00
XTerm*color1:     rgb:80/00/00
XTerm*color2:     rgb:00/80/00
XTerm*color3:     rgb:80/80/00
XTerm*color4:     rgb:00/00/80
XTerm*color5:     rgb:80/00/80
XTerm*color6:     rgb:00/80/80
XTerm*color7:     rgb:c0/c0/c0
XTerm*color8:     rgb:80/80/80
XTerm*color9:     rgb:aa/00/00
XTerm*color10:    rgb:00/aa/00
XTerm*color11:    rgb:aa/aa/00
XTerm*color12:    rgb:00/00/aa
XTerm*color13:    rgb:aa/00/aa
XTerm*color14:    rgb:00/aa/aa
XTerm*color15:    rgb:ff/ff/ff

如果您的终端实现了 xterm 的 OSC 10 and OSC 11 as indicated in the question, then it probably also implements OSC 4:

Ps = 4 ; c ; spec ⇒ Change Color Number c to the color specified by spec.

例如

print "3]4;1;green[=10=]7";
print "3]4;1;green3\";

使用绿色替换颜色 1(红色),其中 xterm 也接受 RGB setting:

/*
 * Set or query entries in the Acolors[] array by parsing pairs of color/name
 * values from the given buffer.
 *
 * The color can be any legal index into Acolors[], which consists of the
 * 16/88/256 "ANSI" colors, followed by special color values for the various
 * colorXX resources.  The indices for the special color values are not
 * simple to work with, so an alternative is to use the calls which pass in
 * 'first' set to the beginning of those indices.
 *
 * If the name is "?", report to the host the current value for the color.
 */

规范的合法值由 XParseColor (in xterm 确定——对于其他终端,它依赖于实现并且通常没有记录,这使得该方面偏离主题)。