有什么方法可以确定运行 vim 之类的终端中光标的颜色吗?我知道您可以使用
tput cols
和 tput rows
来确定终端的高度和宽度,是否有类似的工具用于光标颜色/获取当前终端中任何字符位置的 ansi 标准前景色/背景色?
您问题的答案是“不,没有标准方法可以做到这一点。”
考虑您的终端是根据古代文本终端(如 DEC VT100 等)建模的,它通过串行端口或调制解调器与服务器进行通信。这些终端又以 20 世纪 60 年代连接到计算机的 TeleTYpe (tty) 设备为模型。
电传打字机(“哑”终端)不会向服务器提供未输入键盘的数据。像 VT100(“智能”终端)这样的设备向服务器提供的数据非常少,但是可用的列表多年来没有改变。
其他资源:
如需额外阅读,请查看
man termcap
和
man terminfo
。查看这些页面的“另请参阅”部分中的参考资料。
长答案:该功能如果广泛可用,将是的另一种功能,它允许您检索任何用于脚本编写的终端功能。这些记录在terminfo手册页面中。这些都不涉及光标颜色,仅涉及(相当模糊)
cvvis
(非常可见)、
cnorm
(正常)和
civis
(不可见)光标属性。也就是说,大部分终端都没有
OSC Ps ; Pt ST
OSC Ps ; Pt BEL
Set Text Parameters. For colors and font, if Pt is a "?", the
control sequence elicits a response which consists of the con-
trol sequence which would set the corresponding value. The
dtterm control sequences allow you to determine the icon name
and window title.
The 10 colors (below) which may be set or queried using 1 0
through 1 9 are denoted dynamic colors, since the correspond-
ing control sequences were the first means for setting xterm's
colors dynamically, i.e., after it was started. They are not
the same as the ANSI colors. These controls may be disabled
using the allowColorOps resource. At least one parameter is
expected for Pt. Each successive parameter changes the next
color in the list. The value of Ps tells the starting point
in the list. The colors are specified by name or RGB specifi-
cation as per XParseColor.
If a "?" is given rather than a name or RGB specification,
xterm replies with a control sequence of the same form which
can be used to set the corresponding dynamic color. Because
more than one pair of color number and specification can be
given in one control sequence, xterm can make more than one
reply.
Ps = 1 2 -> Change text cursor color to Pt.
命令行程序
xtermcontrol 使用这些转义序列来设置和获取光标颜色:
--cursor=COLOR
Set cursor color to COLOR.
--get-cursor
Report cursor color.
例如
$ xtermcontrol --get-cursor
rgb:0000/0000/0000
$ xtermcontrol --cursor limegreen
$ xtermcontrol --get-cursor
rgb:3232/cdcd/3232
就其价值而言,它由 VTE 支持(例如 gnome-terminal)。