-
Notifications
You must be signed in to change notification settings - Fork 10.8k
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
[llvm][Support] Support bright colors in raw_ostream #80017
Conversation
@llvm/pr-subscribers-platform-windows @llvm/pr-subscribers-llvm-support Author: Timm Baeder (tbaederr) ChangesFull diff: https://github.com/llvm/llvm-project/pull/80017.diff 4 Files Affected:
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index 42663a9adf2e5..696290a5d99cf 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -102,6 +102,14 @@ class raw_ostream {
MAGENTA,
CYAN,
WHITE,
+ BRIGHT_BLACK,
+ BRIGHT_RED,
+ BRIGHT_GREEN,
+ BRIGHT_YELLOW,
+ BRIGHT_BLUE,
+ BRIGHT_MAGENTA,
+ BRIGHT_CYAN,
+ BRIGHT_WHITE,
SAVEDCOLOR,
RESET,
};
@@ -114,6 +122,14 @@ class raw_ostream {
static constexpr Colors MAGENTA = Colors::MAGENTA;
static constexpr Colors CYAN = Colors::CYAN;
static constexpr Colors WHITE = Colors::WHITE;
+ static constexpr Colors BRIGHT_BLACK = Colors::BRIGHT_BLACK;
+ static constexpr Colors BRIGHT_RED = Colors::BRIGHT_RED;
+ static constexpr Colors BRIGHT_GREEN = Colors::BRIGHT_GREEN;
+ static constexpr Colors BRIGHT_YELLOW = Colors::BRIGHT_YELLOW;
+ static constexpr Colors BRIGHT_BLUE = Colors::BRIGHT_BLUE;
+ static constexpr Colors BRIGHT_MAGENTA = Colors::BRIGHT_MAGENTA;
+ static constexpr Colors BRIGHT_CYAN = Colors::BRIGHT_CYAN;
+ static constexpr Colors BRIGHT_WHITE = Colors::BRIGHT_WHITE;
static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
static constexpr Colors RESET = Colors::RESET;
diff --git a/llvm/lib/Support/Process.cpp b/llvm/lib/Support/Process.cpp
index f81c13970d521..f1ab8c7b9ebd8 100644
--- a/llvm/lib/Support/Process.cpp
+++ b/llvm/lib/Support/Process.cpp
@@ -70,20 +70,35 @@ Process::FindInEnvPath(StringRef EnvName, StringRef FileName,
#define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"
-#define ALLCOLORS(FGBG,BOLD) {\
- COLOR(FGBG, "0", BOLD),\
- COLOR(FGBG, "1", BOLD),\
- COLOR(FGBG, "2", BOLD),\
- COLOR(FGBG, "3", BOLD),\
- COLOR(FGBG, "4", BOLD),\
- COLOR(FGBG, "5", BOLD),\
- COLOR(FGBG, "6", BOLD),\
- COLOR(FGBG, "7", BOLD)\
+#define ALLCOLORS(FGBG, BRIGHT, BOLD) \
+ { \
+ COLOR(FGBG, "0", BOLD), \
+ COLOR(FGBG, "1", BOLD), \
+ COLOR(FGBG, "2", BOLD), \
+ COLOR(FGBG, "3", BOLD), \
+ COLOR(FGBG, "4", BOLD), \
+ COLOR(FGBG, "5", BOLD), \
+ COLOR(FGBG, "6", BOLD), \
+ COLOR(FGBG, "7", BOLD), \
+ COLOR(BRIGHT, "0", BOLD), \
+ COLOR(BRIGHT, "1", BOLD), \
+ COLOR(BRIGHT, "2", BOLD), \
+ COLOR(BRIGHT, "3", BOLD), \
+ COLOR(BRIGHT, "4", BOLD), \
+ COLOR(BRIGHT, "5", BOLD), \
+ COLOR(BRIGHT, "6", BOLD), \
+ COLOR(BRIGHT, "7", BOLD), \
}
-static const char colorcodes[2][2][8][10] = {
- { ALLCOLORS("3",""), ALLCOLORS("3","1;") },
- { ALLCOLORS("4",""), ALLCOLORS("4","1;") }
+// bg
+// | bold
+// | |
+// | | codes
+// | | |
+// | | |
+static const char colorcodes[2][2][16][11] = {
+ { ALLCOLORS("3", "9", ""), ALLCOLORS("3", "9", "1;"),},
+ { ALLCOLORS("4", "10", ""), ALLCOLORS("4", "10", "1;")}
};
// A CMake option controls wheter we emit core dumps by default. An application
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index 551f0d7f0f029..f94eec6963c18 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -417,7 +417,7 @@ bool Process::ColorNeedsFlush() {
}
const char *Process::OutputColor(char code, bool bold, bool bg) {
- return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7];
+ return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
}
const char *Process::OutputBold(bool bg) { return "\033[1m"; }
diff --git a/llvm/lib/Support/Windows/Process.inc b/llvm/lib/Support/Windows/Process.inc
index a54c06d46870b..6b4b723d4744a 100644
--- a/llvm/lib/Support/Windows/Process.inc
+++ b/llvm/lib/Support/Windows/Process.inc
@@ -376,7 +376,7 @@ const char *Process::OutputBold(bool bg) {
const char *Process::OutputColor(char code, bool bold, bool bg) {
if (UseANSI)
- return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7];
+ return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
WORD current = DefaultColors::GetCurrentColor();
WORD colors;
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
I am aware the code is not formatted, because the output looks so bad. |
Is there any test coverage for the existing colours that can/should be extended for these?
There's format disabling comments you can put around code that is manually formatted for better readability. |
I could't find any. |
No description provided.