When I ran this command on linux $ gcc
, it gave me an output like this:
gcc: fatal error: no input files
compilation terminated.
Where, gcc
was in bold white color and fatal error:
was in bold red color.
And then I ran this command $ gcc &> err.txt
and the content of err.txt was:
gcc: fatal error: no input files
compilation terminated.
With no ANSI color codes, just the plain text.
But with my program written in C++, the text file's content was:
[1;91merr:[0m no arguments were passed, try using '--help'
Where err:
was in bold red color with showed up in terminal but the file too contains those characters.
My sample code is:
if (argc == 1)
{
std::fprintf(stderr, "\033[1;91merr:\033[0m no arguments were passed, try using '--help'\n");
return EXIT_FAILURE;
}
My Question:
- How does
gcc
and other linux programs prints colored text on terminal without using ANSI color codes? - Are there any other methods to print colored output on terminal except ANSI color codes?
- Are there any cross-platform libraries todo so?