summaryrefslogtreecommitdiffstats
path: root/llvm/include
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/include
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/include')
-rw-r--r--llvm/include/llvm/Support/raw_ostream.h31
-rw-r--r--llvm/include/llvm/System/Process.h29
2 files changed, 60 insertions, 0 deletions
diff --git a/llvm/include/llvm/Support/raw_ostream.h b/llvm/include/llvm/Support/raw_ostream.h
index b67d12675fe..8242f04e23c 100644
--- a/llvm/include/llvm/Support/raw_ostream.h
+++ b/llvm/include/llvm/Support/raw_ostream.h
@@ -45,6 +45,19 @@ private:
bool Unbuffered;
public:
+ // color order matches ANSI escape sequence, don't change
+ enum Colors {
+ BLACK=0,
+ RED,
+ GREEN,
+ YELLOW,
+ BLUE,
+ MAGENTA,
+ CYAN,
+ WHITE,
+ SAVEDCOLOR
+ };
+
explicit raw_ostream(bool unbuffered=false) : Unbuffered(unbuffered) {
// Start out ready to flush.
OutBufStart = OutBufEnd = OutBufCur = 0;
@@ -167,6 +180,20 @@ public:
// Formatted output, see the format() function in Support/Format.h.
raw_ostream &operator<<(const format_object_base &Fmt);
+ /// Changes the foreground color of text that will be output from this point
+ /// forward.
+ /// @param colors ANSI color to use, the special SAVEDCOLOR can be used to
+ /// change only the bold attribute, and keep colors untouched
+ /// @param bold bold/brighter text, default false
+ /// @param bg if true change the background, default: change foreground
+ /// @returns itself so it can be used within << invocations
+ virtual raw_ostream &changeColor(enum Colors colors, bool bold=false,
+ bool bg=false) { return *this; }
+
+ /// Resets the colors to terminal defaults. Call this when you are done
+ /// outputting colored text, or before program exit.
+ virtual raw_ostream &resetColor() { return *this; }
+
//===--------------------------------------------------------------------===//
// Subclass Interface
//===--------------------------------------------------------------------===//
@@ -243,6 +270,10 @@ public:
/// seek - Flushes the stream and repositions the underlying file descriptor
/// positition to the offset specified from the beginning of the file.
uint64_t seek(uint64_t off);
+
+ virtual raw_ostream &changeColor(enum Colors colors, bool bold=false,
+ bool bg=false);
+ virtual raw_ostream &resetColor();
};
/// raw_stdout_ostream - This is a stream that always prints to stdout.
diff --git a/llvm/include/llvm/System/Process.h b/llvm/include/llvm/System/Process.h
index ce19eb29819..adc1f03deb4 100644
--- a/llvm/include/llvm/System/Process.h
+++ b/llvm/include/llvm/System/Process.h
@@ -107,6 +107,35 @@ namespace sys {
/// console, or if the number of columns cannot be determined,
/// this routine returns zero.
static unsigned StandardErrColumns();
+
+ /// This function determines whether the terminal connected to standard
+ /// output supports colors. If standard output is not connected to a
+ /// terminal, this function returns false.
+ static bool StandardOutHasColors();
+
+ /// This function determines whether the terminal connected to standard
+ /// error supports colors. If standard error is not connected to a
+ /// terminal, this function returns false.
+ static bool StandardErrHasColors();
+
+ /// Whether changing colors requires the output to be flushed.
+ /// This is needed on systems that don't support escape sequences for
+ /// changing colors.
+ static bool ColorNeedsFlush();
+
+ /// This function returns the colorcode escape sequences, and sets Len to
+ /// the length of the escape sequence.
+ /// If ColorNeedsFlush() is true then this function will change the colors
+ /// and return an empty escape sequence. In that case it is the
+ /// responsibility of the client to flush the output stream prior to
+ /// calling this function.
+ static const char *OutputColor(char c, bool bold, bool bg);
+
+ /// Same as OutputColor, but only enables the bold attribute.
+ static const char *OutputBold(bool bg);
+
+ /// Resets the terminals colors, or returns an escape sequence to do so.
+ static const char *ResetColor();
/// @}
};
}
OpenPOWER on IntegriCloud