In the answer to this question , it uses the following (simplified):
echo "this is $(tput bold)bold$(tput sgr0) but this isn't"
But that tput sgr0
resets all of the text attributes.
I'd like to output coloured text, with only some of it in bold. So I want something like this:
echo "$(tput setaf 1)this is red; $(tput bold)this is bold; $(tput unbold)this is red, but not bold"
But tput unbold
isn't a thing.
Is there any way to push/pop the terminal attributes so that I could do something like the following?
echo "$(tput setaf 1)this is red; $(tput push; tput bold)this is bold; $(tput pop)this is red, but not bold"
No - tput
has no notion of push/pop. Just set : like a pun, tput
is a more general tool than tset
, as noted in themanual page :
- SVr3 replaced that, a year later, by a more extensive program whose init and reset subcommands (more than half the program) were incorporated from the reset feature of BSD
tset
written by Eric Allman.
tput
does nothing like push/pop, because it would have to rely upon asking the terminal what the current video attributes are (something that only a minority of the terminals could do).
Some terminals could/can do this, eg, the DEC VT420's DECRQSS control mentioned in XTerm Control Sequences . Most do not (even limiting this to xterm-imitators).
tput
works with terminal capabilities; none of the predefined ones in terminfo(5) deal with stacks.
That's not to say that someone might develop an application like tput
which could work with a terminal that supports stacking, either by supporting push/pop or set/get controls. (xterm does both).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.