获取终端中光标颜色

问题描述 投票:0回答:2

有什么方法可以确定运行 vim 之类的终端中光标的颜色吗?我知道您可以使用

tput cols
tput rows
来确定终端的高度和宽度,是否有类似的工具用于光标颜色/获取当前终端中任何字符位置的 ansi 标准前景色/背景色?

bash terminal tty terminfo tput
2个回答
1
投票

您问题的答案是“不,没有标准方法可以做到这一点。”

考虑您的终端是根据古代文本终端(如 DEC VT100 等)建模的,它通过串行端口或调制解调器与服务器进行通信。这些终端又以 20 世纪 60 年代连接到计算机的 TeleTYpe (tty) 设备为模型。

电传打字机(“哑”终端)不会向服务器提供未输入键盘的数据。像 VT100(“智能”终端)这样的设备向服务器提供的数据非常少,但是可用的列表多年来没有改变。

其他资源:

请注意,并非所有终端都是 VT100/VT220,您的系统可能具有锁定扩展,以非标准方式提供您所需的功能。

如需额外阅读,请查看

man termcap

man terminfo
。查看这些页面的“另请参阅”部分中的参考资料。


1
投票
简短回答:不

长答案:该功能如果广泛可用,将是

tput

的另一种功能,它允许您检索任何用于脚本编写的终端功能。这些记录在terminfo手册页面中。这些都不涉及光标颜色,仅涉及(相当模糊)cvvis
(非常可见)、
cnorm
(正常)和
civis
(不可见)光标属性。

也就是说,大部分终端都没有

    提供一种方法来
  • 设置光标颜色或
  • 提供一种方法来
  • 检索光标颜色
xterm 是一个罕见的例外,它同时提供了这两种功能。但模仿 xterm 的终端通常不支持该功能。它作为

动态颜色功能的一部分记录在 XTerm 控制序列中:

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)。

© www.soinside.com 2019 - 2024. All rights reserved.