summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System/Win32/Process.inc
diff options
context:
space:
mode:
authorTorok Edwin <edwintorok@gmail.com>2009-06-04 07:09:50 +0000
committerTorok Edwin <edwintorok@gmail.com>2009-06-04 07:09:50 +0000
commit9b5a47fc3c5acad4f1637e1825787834d8357b70 (patch)
tree42872f1f633198ea769de9ee8d3bddb4d4e514bc /llvm/lib/System/Win32/Process.inc
parent75ac061fdb28f3b0135fbf45c3fd283c1463edb0 (diff)
downloadbcm5719-llvm-9b5a47fc3c5acad4f1637e1825787834d8357b70.tar.gz
bcm5719-llvm-9b5a47fc3c5acad4f1637e1825787834d8357b70.zip
Add support for outputting ANSI colors to raw_fd_ostream.
llvm-svn: 72854
Diffstat (limited to 'llvm/lib/System/Win32/Process.inc')
-rw-r--r--llvm/lib/System/Win32/Process.inc66
1 files changed, 66 insertions, 0 deletions
diff --git a/llvm/lib/System/Win32/Process.inc b/llvm/lib/System/Win32/Process.inc
index e1d7a9222f7..97eba5808df 100644
--- a/llvm/lib/System/Win32/Process.inc
+++ b/llvm/lib/System/Win32/Process.inc
@@ -147,4 +147,70 @@ unsigned Process::StandardErrColumns() {
return Columns;
}
+// it always has colors
+bool Process::StandardErrHasColors() {
+ return StandardErrIsDisplayed();
+}
+
+bool Process::StandardOutHasColors() {
+ return StandardOutIsDisplayed();
+}
+namespace {
+class DefaultColors
+{
+ private:
+ WORD defaultColor;
+ public:
+ DefaultColors()
+ :defaultColor(GetCurrentColor()) {}
+ static unsigned GetCurrentColor() {
+ CONSOLE_SCREEN_BUFFER_INFO csbi;
+ if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi))
+ return csbi.wAttributes;
+ return 0;
+ }
+ WORD operator()() const { return defaultColor; }
+};
+
+DefaultColors defaultColors;
+}
+
+bool Process::ColorNeedsFlush() {
+ return true;
+}
+
+const char *Process::OutputBold(bool bg) {
+ WORD colors = DefaultColors::GetCurrentColor();
+ if (bg)
+ colors |= BACKGROUND_INTENSITY;
+ else
+ colors |= FOREGROUND_INTENSITY;
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
+ return 0;
+}
+
+const char *Process::OutputColor(char code, bool bold, bool bg) {
+ WORD colors;
+ if (bg) {
+ colors = ((code&1) ? BACKGROUND_RED : 0) |
+ ((code&2) ? BACKGROUND_GREEN : 0 ) |
+ ((code&4) ? BACKGROUND_BLUE : 0);
+ if (bold)
+ colors |= BACKGROUND_INTENSITY;
+ } else {
+ colors = ((code&1) ? FOREGROUND_RED : 0) |
+ ((code&2) ? FOREGROUND_GREEN : 0 ) |
+ ((code&4) ? FOREGROUND_BLUE : 0);
+ if (bold)
+ colors |= FOREGROUND_INTENSITY;
+ }
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), colors);
+ return 0;
+}
+
+const char *Process::ResetColor() {
+ SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), defaultColors());
+ return 0;
+}
+
}
OpenPOWER on IntegriCloud