使用 terminfo 仅重置前景色 [英] Reset only the foreground color using terminfo

查看:27
本文介绍了使用 terminfo 仅重置前景色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过在终端中使用 ANSI 序列 Esc[39m,可以在不改变其他属性(如粗体、下划线或背景颜色)的情况下清除前景色.例如:

By using the ANSI sequence Esc[39m in a terminal, it is possible to clear the foreground color without altering other attributes like bold, underline, or the background color. For example:

echo -e "e[31;1mRed and bold.e[39m Bold only."

我想从 terminfo 功能中检索此序列,但找不到;当尝试使用 setaf 9 时,它通过给出序列 Esc[91m:

I would like to retrieve this sequence from a terminfo capability, but I'm unable to find it; when trying with setaf 9, it switches to bright colors by giving the sequence Esc[91m:

$ tput setaf 1 | xxd
00000000: 1b5b 3331 6d                             .[31m
$ tput setaf 9 | xxd
00000000: 1b5b 3931 6d                             .[91m

我发现重置前景色的唯一功能是 sgr0,但它也会重置所有其他属性.

The only capability I found to reset the foreground color is sgr0, but it resets all the other attributes as well.

是否可以从 terminfo 访问这些功能?

Is it possible to access these capabilities from terminfo ?

  • 默认前景Esc[39m;
  • 默认背景Esc[49m;

推荐答案

您必须自己定义它.X/Open 没有定义它,也没有确定的用途.假设您使用的是 ncurses(可扩展),则可以可以通过修改终端描述并为其创建自己的名称来完成,例如,

You'll have to define it yourself. X/Open doesn't define it, and there's no established use for it. Assuming you're using ncurses (which is extensible), that can be done by modifying a terminal description and making up your own name for it, e.g.,

infocmp -x > myinfo.src
printf '	resetf=\E[39m,
' >> myinfo.src
tic -x myinfo.src

(通常会在中创建您的副本$HOME/.terminfo/).

(which would generally create your copy in $HOME/.terminfo/).

这篇关于使用 terminfo 仅重置前景色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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