Is there another way than isatty
to know if cout
outputs to a terminal which accepts colors properly?
I'm using this header for colors, and I'm already using if(isatty(1))
to know if the output goes to a terminal.
Unfortunately when I output colors to Xcode's console I get unescaped sequences - but it works fine when executing the app itself from Terminal.app or iTerm in OS X.
I suppose that Xcode's console identifies itself as a terminal but still ignores color sequences...
So I'd like to have a better detection - if possible.
My code itself is trivial, something like this, returning a colored string if isatty
is true, then it goes to cout
:
std::string Slot::description()
{
if(isatty(1))
{
return FBLU("my_string");
}
else
{
return "my_string";
}
}
Xcode's output:
iTerm's output: