I'm writing a C program that outputs test results, and I'd like it to print them in color so it's easier to scan through the results. I initially just used ANSI color codes (per https://stackoverflow.com/a/23657072/4954731), but a code reviewer wanted it to be more terminal-independent and suggested using ncurses instead.
The problem with using ncurses is that the test results outputted by my C program are interspersed with other test results from bash scripts. Something like this:
Test Name | Result
------------------------------
1+1 == 2 | PASS <-- outputted by a C executable
!(!true) == true | PASS <-- outputted by a bash script
0+0 == 0 | PASS <-- outputted by a C executable
...
So I can't use a regular ncurses screen - I have to play nicely with other output.
The bash scripts use tput
and setaf
to print with color, but I'm not sure if there's a way to use these tools in a C context without directly finding and calling the tput
executable...
Is there some way I can do terminal-agnostic color printing in C without using ncurses?