There is no portable way to determine if a given device supports colors. There are several programming interfaces (some portable, some not) which attempt to determine this information, but rely upon being configured properly. For instance, curses (including ncurses) relies upon your setting TERM
correctly to tell the library what the terminal can do. A few terminals have the capability of providing this information, but that does not help with portability.
Noting comments: PDCurses is not a "port" but a separate program. ncurses has a workable port to Windows, for what it's worth.
In any case, you are not going to find a portable program which is supported, which can do what was asked. Long ago, printing escape sequences using ansi.sys
was the way to go with Windows, but it has been unsupported for more than ten years.
Likewise, long ago there was conio.h
, also unsupported. If you find a working version for Windows which supports color, it probably uses the Windows console api (which is not portable, but you may find comparable conio.h
implementations on other platforms). There are a few unsupported implementations of conio.h to consider. Since that niche appears to be what was requested, here are a few relevant links: