Skip to content

Commit 24a8041

Browse files
authored
[llvm][Support] Support bright colors in raw_ostream (#80017)
1 parent 44ba4c7 commit 24a8041

File tree

4 files changed

+47
-15
lines changed

4 files changed

+47
-15
lines changed

llvm/include/llvm/Support/raw_ostream.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,14 @@ class raw_ostream {
102102
MAGENTA,
103103
CYAN,
104104
WHITE,
105+
BRIGHT_BLACK,
106+
BRIGHT_RED,
107+
BRIGHT_GREEN,
108+
BRIGHT_YELLOW,
109+
BRIGHT_BLUE,
110+
BRIGHT_MAGENTA,
111+
BRIGHT_CYAN,
112+
BRIGHT_WHITE,
105113
SAVEDCOLOR,
106114
RESET,
107115
};
@@ -114,6 +122,14 @@ class raw_ostream {
114122
static constexpr Colors MAGENTA = Colors::MAGENTA;
115123
static constexpr Colors CYAN = Colors::CYAN;
116124
static constexpr Colors WHITE = Colors::WHITE;
125+
static constexpr Colors BRIGHT_BLACK = Colors::BRIGHT_BLACK;
126+
static constexpr Colors BRIGHT_RED = Colors::BRIGHT_RED;
127+
static constexpr Colors BRIGHT_GREEN = Colors::BRIGHT_GREEN;
128+
static constexpr Colors BRIGHT_YELLOW = Colors::BRIGHT_YELLOW;
129+
static constexpr Colors BRIGHT_BLUE = Colors::BRIGHT_BLUE;
130+
static constexpr Colors BRIGHT_MAGENTA = Colors::BRIGHT_MAGENTA;
131+
static constexpr Colors BRIGHT_CYAN = Colors::BRIGHT_CYAN;
132+
static constexpr Colors BRIGHT_WHITE = Colors::BRIGHT_WHITE;
117133
static constexpr Colors SAVEDCOLOR = Colors::SAVEDCOLOR;
118134
static constexpr Colors RESET = Colors::RESET;
119135

llvm/lib/Support/Process.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -67,24 +67,40 @@ Process::FindInEnvPath(StringRef EnvName, StringRef FileName,
6767
return FoundPath;
6868
}
6969

70-
70+
// clang-format off
7171
#define COLOR(FGBG, CODE, BOLD) "\033[0;" BOLD FGBG CODE "m"
7272

73-
#define ALLCOLORS(FGBG,BOLD) {\
74-
COLOR(FGBG, "0", BOLD),\
75-
COLOR(FGBG, "1", BOLD),\
76-
COLOR(FGBG, "2", BOLD),\
77-
COLOR(FGBG, "3", BOLD),\
78-
COLOR(FGBG, "4", BOLD),\
79-
COLOR(FGBG, "5", BOLD),\
80-
COLOR(FGBG, "6", BOLD),\
81-
COLOR(FGBG, "7", BOLD)\
73+
#define ALLCOLORS(FGBG, BRIGHT, BOLD) \
74+
{ \
75+
COLOR(FGBG, "0", BOLD), \
76+
COLOR(FGBG, "1", BOLD), \
77+
COLOR(FGBG, "2", BOLD), \
78+
COLOR(FGBG, "3", BOLD), \
79+
COLOR(FGBG, "4", BOLD), \
80+
COLOR(FGBG, "5", BOLD), \
81+
COLOR(FGBG, "6", BOLD), \
82+
COLOR(FGBG, "7", BOLD), \
83+
COLOR(BRIGHT, "0", BOLD), \
84+
COLOR(BRIGHT, "1", BOLD), \
85+
COLOR(BRIGHT, "2", BOLD), \
86+
COLOR(BRIGHT, "3", BOLD), \
87+
COLOR(BRIGHT, "4", BOLD), \
88+
COLOR(BRIGHT, "5", BOLD), \
89+
COLOR(BRIGHT, "6", BOLD), \
90+
COLOR(BRIGHT, "7", BOLD), \
8291
}
8392

84-
static const char colorcodes[2][2][8][10] = {
85-
{ ALLCOLORS("3",""), ALLCOLORS("3","1;") },
86-
{ ALLCOLORS("4",""), ALLCOLORS("4","1;") }
93+
// bg
94+
// | bold
95+
// | |
96+
// | | codes
97+
// | | |
98+
// | | |
99+
static const char colorcodes[2][2][16][11] = {
100+
{ ALLCOLORS("3", "9", ""), ALLCOLORS("3", "9", "1;"),},
101+
{ ALLCOLORS("4", "10", ""), ALLCOLORS("4", "10", "1;")}
87102
};
103+
// clang-format on
88104

89105
// A CMake option controls wheter we emit core dumps by default. An application
90106
// may disable core dumps by calling Process::PreventCoreFiles().

llvm/lib/Support/Unix/Process.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ bool Process::ColorNeedsFlush() {
417417
}
418418

419419
const char *Process::OutputColor(char code, bool bold, bool bg) {
420-
return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7];
420+
return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
421421
}
422422

423423
const char *Process::OutputBold(bool bg) { return "\033[1m"; }

llvm/lib/Support/Windows/Process.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ const char *Process::OutputBold(bool bg) {
376376

377377
const char *Process::OutputColor(char code, bool bold, bool bg) {
378378
if (UseANSI)
379-
return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 7];
379+
return colorcodes[bg ? 1 : 0][bold ? 1 : 0][code & 15];
380380

381381
WORD current = DefaultColors::GetCurrentColor();
382382
WORD colors;

0 commit comments

Comments
 (0)