-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Color on Windows #21
Comments
I'm okay with b342b1b, but please use _getenv_s or _dupenv_s (I would probably use the former with a small stack based buffer, but whatever) to avoid that CRT warning. I guess it would be possible to use SetConsoleTextAttribute to set colors on Windows, but TBH I'm not sure it's worth it. I don't think anyone takes the default command prompt seriously, and if conemu supports colors that's good enough for me. |
Also, since you only want to check that ANSICON != NULL, you don't even need a buffer. Something like this should work: if (isatty(fileno(stream))) {
size_t ansicon_size;
getenv_s(&ansicon_size, NULL, 0, "ANSICON");
return ansicon_size != 0;
}
return false; |
I've updated the branch, but Quite oddly, only the mingw builds appear to break. |
Only mingw breaks because the getenv call is in guarded by an I pushed a fix which will just call the standard getenv on mingw, getenv_s on non-mingw windows, and still just use isatty everywhere else. |
Ah, of course -- thanks. |
On Windows, we should probably try to detect if the command window supports ANSI escapes, and default to not using color if we are not sure. The situation is a bit tricky, as different console emulators set different environment variables.
ANSICON
(related to https://github.com/adoxa/ansicon, which also appears to setCLICOLOR
)TERM
(mostly bash, but for instance MSYS2 bash returns 0 forisatty()
, explained here)Most importantly though, the default command prompt does not support ANSI colors and returns true for
isatty()
.The text was updated successfully, but these errors were encountered: