0

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

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
  • OK, thanks. It was mostly an academic question. Apr 15 '20 at 23:25
1

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.

1
  • 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. Apr 17 '20 at 0:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.