Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is there both setf/setb and setaf/setab in tput?

I'm trying to use tput to set foreground and background colors in my terminal in a device independent way.

If the whole purpose of termcap/terminfo/tput is to become device independent, why are there both versions that explicitly use ANSI controls (setaf/setab) and versions that do not (should not)?

This discussion quotes terminfo(5) which in turn quotes standards that explicitly says that those are to be implemented using ANSI and not ANSI, respectively.

Why isn't there just setf/setb and they always set the foreground and background colors. I don't care how it's done, that's why I use tput!

like image 763
thoni56 Avatar asked Sep 19 '13 11:09

thoni56


1 Answers

Why isn't there just setf/setb and they always set the foreground and background colors are actually two questions!

The first part, why there are ANSI and non-ANSI terminal commands takes too long to exaplin, and it's unnecessary as the history is quite well explained on Wikipedia.

The second part could perhaps be freely rephrased to "what's the difference?" or "what can I do about it?".

Difference: ANSI type terminals use another mapping between colour number and colours than non-ANSI terminals. For example, the code for yellow on one would be cyan on the other. There are simply two different mapping tables. Those things are described quite well on Wikipedia.

What you can do about it: Discover which type of terminal you have, and use corresponding command. Or modify your termcap. None of these solutions are fully generic though, unfortunately.

like image 61
Rein Avatar answered Nov 17 '22 08:11

Rein