【问题标题】:Reset only the foreground color using terminfo使用 terminfo 仅重置前景色
【发布时间】:2023-12-03 09:53:01
【问题描述】:

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

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

我想从 terminfo 功能中检索此序列,但我找不到它;尝试使用setaf 9 时,它会通过给出序列Esc[91m 切换到明亮的颜色:

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

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

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

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

【问题讨论】:

    标签: terminal ansi terminfo


    【解决方案1】:

    您必须自己定义它。 X/Open 没有定义它,也没有确定的用途。假设您使用的是 ncurses(即extensible),可以通过修改终端描述并为其命名,例如,

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

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

    【讨论】: