我正在对日志进行一些后期格式化以提高可读性。
使用正则表达式,我的脚本可以识别流中的一些模式,并通过分别在文本的开头和结尾插入$(tput bold)和值来使对应的文本变为粗体。$(tput sgr0)流不是文本的,它已经包含一些特殊的格式转义序列,如颜色等。
$(tput setaf 6)
Part of this text can be $(tput bold)bold$(tput sgr0) but
the rest of the text has lost its initial color.
问题是我无法弄清楚如何仅关闭粗体模式。使用$(tput sgr0)会将所有其他当前终端设置降至默认值,包括颜色。
我曾经man terminfo知道我应该使用什么“capname”。例如,我知道如何将一些文本设置为斜体,因为列表包含两者sitm——capname toenter_italic_mode和ritmcapname to exit_italic_mode。
$(tput setaf 6)
Part of this text can be $(tput sitm)italic$(tput ritm) but
the rest of the text still has its initial color.
我想使用相同的方法使文本变为粗体,因为列表terminfo包含. 但是既没有“exit_bold_name”字符串变量,也没有对应的capname!boldenter_bold_mode
我错过了什么吗?我应该使用另一种方法吗?在我在 Internet 上找到的所有文章中,它仅使用sgr0capname 解决方案。