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

1

6

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!

Fauteuil answered 19/9, 2013 at 11:33 Comment(1)
There is a better answer on unix.SE's version of this question, What is the difference between tput's 'setf' and 'setaf'?. In short, setf is old and setaf (with the A for ANSI) is new. Only setaf supports 256 color modes.Genital
A
1

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.

Avilla answered 16/10, 2014 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.