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
Merged
Merged
Added -color #3705
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
|
||
/* Compiler implementation of the D programming language | ||
* Copyright (c) 1999-2014 by Digital Mars | ||
* All Rights Reserved | ||
* written by Walter Bright | ||
* http://www.digitalmars.com | ||
* Distributed under the Boost Software License, Version 1.0. | ||
* http://www.boost.org/LICENSE_1_0.txt | ||
* https://github.com/D-Programming-Language/dmd/blob/master/src/mars.c | ||
*/ | ||
|
||
#include "color.h" | ||
|
||
#include <stdio.h> | ||
|
||
#if _WIN32 | ||
#define WIN32_LEAN_AND_MEAN | ||
#include <windows.h> | ||
#include <io.h> | ||
#endif | ||
|
||
#if __linux__ || __APPLE__ || __FreeBSD__ || __OpenBSD__ || __sun | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <string.h> | ||
#endif | ||
|
||
#if _WIN32 | ||
static CONSOLE_SCREEN_BUFFER_INFO sbi; | ||
static const BOOL sbi_inited = GetConsoleScreenBufferInfo(GetStdHandle(STD_ERROR_HANDLE), &sbi); | ||
#endif | ||
|
||
int isConsoleColorSupported() | ||
{ | ||
#if _WIN32 | ||
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"); | ||
#else | ||
return 0; | ||
#endif | ||
} | ||
|
||
void setConsoleColorBright() | ||
{ | ||
#if _WIN32 | ||
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), sbi.wAttributes | FOREGROUND_INTENSITY); | ||
#else | ||
fprintf(stderr, "\033[1m"); | ||
#endif | ||
} | ||
|
||
void setConsoleColorError() | ||
{ | ||
#if _WIN32 | ||
enum { FOREGROUND_WHITE = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE }; | ||
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), (sbi.wAttributes & ~FOREGROUND_WHITE) | FOREGROUND_RED | FOREGROUND_INTENSITY); | ||
#else | ||
fprintf(stderr, "\033[1;31m"); | ||
#endif | ||
} | ||
|
||
void resetConsoleColor() | ||
{ | ||
#if _WIN32 | ||
SetConsoleTextAttribute(GetStdHandle(STD_ERROR_HANDLE), sbi.wAttributes); | ||
#else | ||
fprintf(stderr, "\033[m"); | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
|
||
/* Compiler implementation of the D programming language | ||
* Copyright (c) 1999-2014 by Digital Mars | ||
* All Rights Reserved | ||
* written by Walter Bright | ||
* http://www.digitalmars.com | ||
* Distributed under the Boost Software License, Version 1.0. | ||
* http://www.boost.org/LICENSE_1_0.txt | ||
* https://github.com/D-Programming-Language/dmd/blob/master/src/mars.c | ||
*/ | ||
|
||
extern int isConsoleColorSupported(); | ||
extern void setConsoleColorBright(); | ||
extern void setConsoleColorError(); | ||
extern void resetConsoleColor(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 checkisatty
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.