aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/llvm/Support/Process.h4
-rw-r--r--lib/Support/Unix/Process.inc14
-rw-r--r--lib/Support/Windows/Process.inc12
3 files changed, 20 insertions, 10 deletions
diff --git a/include/llvm/Support/Process.h b/include/llvm/Support/Process.h
index 91b92788f2..088897c903 100644
--- a/include/llvm/Support/Process.h
+++ b/include/llvm/Support/Process.h
@@ -97,6 +97,10 @@ namespace sys {
/// the user rather than being put on a pipe or stored in a file.
static bool FileDescriptorIsDisplayed(int fd);
+ /// This function determines if the given file descriptor is displayd and
+ /// supports colors.
+ static bool FileDescriptorHasColors(int fd);
+
/// This function determines the number of columns in the window
/// if standard output is connected to a "tty" or "console"
/// window. If standard output is not connected to a tty or
diff --git a/lib/Support/Unix/Process.inc b/lib/Support/Unix/Process.inc
index 4e1bd5db14..174112e8c2 100644
--- a/lib/Support/Unix/Process.inc
+++ b/lib/Support/Unix/Process.inc
@@ -249,16 +249,18 @@ static bool terminalHasColors() {
return false;
}
+bool Process::FileDescriptorHasColors(int fd) {
+ // A file descriptor has colors if it is displayed and the terminal has
+ // colors.
+ return FileDescriptorIsDisplayed(fd) && terminalHasColors();
+}
+
bool Process::StandardOutHasColors() {
- if (!StandardOutIsDisplayed())
- return false;
- return terminalHasColors();
+ return FileDescriptorHasColors(STDOUT_FILENO);
}
bool Process::StandardErrHasColors() {
- if (!StandardErrIsDisplayed())
- return false;
- return terminalHasColors();
+ return FileDescriptorHasColors(STDERR_FILENO);
}
bool Process::ColorNeedsFlush() {
diff --git a/lib/Support/Windows/Process.inc b/lib/Support/Windows/Process.inc
index 6a1270c2f3..43ba028a89 100644
--- a/lib/Support/Windows/Process.inc
+++ b/lib/Support/Windows/Process.inc
@@ -153,13 +153,17 @@ unsigned Process::StandardErrColumns() {
return Columns;
}
-// It always has colors.
-bool Process::StandardErrHasColors() {
- return StandardErrIsDisplayed();
+// The terminal always has colors.
+bool FileDescriptorHasColors(int fd) {
+ return FileDescriptorIsDisplayed(fd);
}
bool Process::StandardOutHasColors() {
- return StandardOutIsDisplayed();
+ return FileDescriptorHasColors(1);
+}
+
+bool Process::StandardErrHasColors() {
+ return FileDescriptorHasColors(2);
}
namespace {