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
Added -color #3705
Added -color #3705
Conversation
PR for dlang.org: dlang/dlang.org#605 |
@@ -19,6 +19,11 @@ | |||
#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun | |||
#include <errno.h> | |||
#endif | |||
#if _WIN32 | |||
#define WIN32_LEAN_AND_MEAN | |||
#include <Windows.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lower case w
We should not print colors if |
@alexrp: I'm not sure if checking Once such situation is with parallel build tools such as Ninja that cache the output to later print it to the console (and can't use a pseudo-tty per child process for performance/availability reasons). I found it very helpful that Clang's |
@klickverbot if we don't check I agree that forcing colors can be useful, but let's have two flags then. |
@alexrp: That, or just enable them by default. |
Please, no. Every additional switch is a failure of design, and a burden on the user. |
@WalterBright: So are you okay with just enabling colors by default, and providing an explicit on/off switch that disregards tty detection? (Edit: "by default" == "if output is going to a terminal") |
@klickverbot yes that sounds better |
I think I've addressed all the raised points. Defaults to on based on TTY/TERM, can be forced on/off with the -color or -color=[on|off] flag. I'm a bit worried that the TTY/TERM auto-detection is a black hole. Other projects I've seen get into full-fletched terminal capability testing. Only colors errors at the moment. What about warnings/deprecation? |
Defaults to colored output if stderr is a TTY and TERM is not dumb.
Isn't it standard for a trailing '-' to mean 'off' ? |
Let's see how this one plays out first. |
@WalterBright I've checked a few other tools and grep and git use --color[=auto|always|never], whereas dmd already has an on/off switch with -boundscheck=[on|safeonly|off] so I decided to stick to on/off for -color as well. As far as I know only the "-o-" switch has a trailing '-' but it always has it (and FWIW I don't like it.) |
return _isatty(_fileno(stderr)); | ||
#elif __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun | ||
const char *term = getenv("TERM"); | ||
return isatty(STDERR_FILENO) && term && term[0] && 0 != strcmp(term, "dumb"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexrp care to comment on this logic? Is this what you had in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does DMD never use stdout
? If it does, we should probably check isatty
for that too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The colors are only ever used on stderr so I only check stderr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then it looks fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alexrp - I believe I fixed dmd diagnostics a while back to only send verbose (-vtls, etc) messages to stdout. All warnings and errors are sent to stderr.
I'd be opined to suggest that these functions and all error/warning/deprecation functions should be in one file named diag.c or something like that. Other than that, gdc has had this for a while. ('error' in red, 'warning' in purple, supplementary 'note' in cyan) |
This one is good to go. Please open new bugzilla/PRs for any enhancements. I'm not sure why nobody has enabled auto-merge on this. Go go go! |
Auto-merge toggled on |
Why do we need a switch for this? |
@MartinNowak: See my comment above for a situation where you might want to force colored output ("proper" parallel build tools that don't randomly interleave subprocess output). |
Well, once again, a PR was merged that added a new file, but failed to add that file to either of the VC projects, or the xcode projects. Will make a PR to fix the MSVC projects momentarily. |
@Orvid sorry :S Now I know |
Without auto-testing this is always going to be a problem. Especially since we're relying on this more and more often now. |
Can we automate the adding or at least testthat the list is complete without actually running Xcode or VisualStudio? |
Testing could be done by a module in the dmd test suite that extracts the source files from the VC/XCode project files and the makefiles and compares them. |
The only thing that's really different between building and testing for MSVC is compiling DMD, for instance, I use this pair of scripts to build DMD, phobos, and druntime for 32 and 64 bit, and then also install them. (I run the scripts via git bash) The only real difference would be what is done in the build_dmd_msvc64 function. In my case I call out to a batch file which sets the environment variables I need, and then just runs msbuild. After DMD is built, you could easily run the tests in the exact same way you currently run tests for a non-MSVC build. The same can be done on OSX, except that an external script isn't needed to do the building of DMD. |
https://issues.dlang.org/show_bug.cgi?id=12273