[英]Can I push/pop attributes with tput?
在这个问题的答案中,它使用了以下内容(简化):
echo "this is $(tput bold)bold$(tput sgr0) but this isn't"
但是那个tput sgr0
重置了所有的文本属性。
我想要 output 彩色文本,其中只有一部分是粗体。 所以我想要这样的东西:
echo "$(tput setaf 1)this is red; $(tput bold)this is bold; $(tput unbold)this is red, but not bold"
但是tput unbold
不是问题。
有没有办法推送/弹出终端属性,以便我可以执行以下操作?
echo "$(tput setaf 1)this is red; $(tput push; tput bold)this is bold; $(tput pop)this is red, but not bold"
否 - tput
没有推送/弹出的概念。 Just set :就像双关语一样, tput
是比tset
更通用的工具,如手册页中所述:
- 一年后,SVr3 用一个更广泛的程序取代了它,该程序的init和reset子命令(超过程序的一半)是从 Eric Allman 编写的 BSD
tset
的重置功能中合并的。
tput
与 push/pop 完全不同,因为它必须依赖于询问终端当前的视频属性是什么(只有少数终端可以这样做)。
一些终端可以/能够做到这一点,例如, XTerm Control Sequences中提到的 DEC VT420 的DECRQSS控件。 大多数不这样做(甚至将其限制为 xterm 模仿器)。
tput
与终端功能一起工作; terminfo(5)中没有预定义的处理堆栈。
这并不是说有人可能会开发像tput
这样的应用程序,它可以与支持堆栈的终端一起工作,通过支持推送/弹出或设置/获取控件。 (xterm 两者都做)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.