share
Unix & LinuxCan tput be used with combined capabilities?
[0] [2] Edward Falk
[2020-04-15 23:07:16]
[ tput ]
[ https://unix.stackexchange.com/questions/580347/can-tput-be-used-with-combined-capabilities ]

For example, if I want the prefix for bold green, I might do Green=$(tput bold; tput setaf 2). This would set $Green to "\E[1m\E[32m". But on an Ansi terminal, it could just as easily have been "\E[1;32m".

Can this be done with tput, or am I asking too much?

[+2] [2020-04-15 23:18:57] Thomas Dickey [ACCEPTED]

No, tput won't do this (normally) because you're likely to use only the predefined/standard terminal capabilities, which don't have that combination.

With ncurses, you could define your own terminal description with a user-defined capability, and tput would work with that.

Something like this would combine colors:

infocmp -x >foo
printf '\tfgbg=\\E[3%p1%;4%p2%dm,\n' >>foo
sudo tic -x foo

Then (the example is for 8-colors)

tput fgbg 4 0

would set the foreground to blue and background to black. However, there are a lot of possibilities. Using the predefined capabilities involves less effort.


1
[+1] [2020-04-16 11:29:24] JdeBP

Another way to look at this is that knowing that you even can combine control sequences in this way is a terminal-family-specific thing, which is not the termcap/terminfo model. Whilst the 44-year-old ECMA-48 model for control sequences is widespread nowadays, termcap/terminfo are designed to allow for terminal types that do not adhere to it. It is not the case that one actually can always combine control sequences in this way.


Yes; that's about what I figured. It's one thing for tput to know how to look up control sequences in a database, it's another to know which sequences can be combined with others, and how. To do that would require terminal-specific code in tput. - Edward Falk
2