Process: Add sys::Process::FileDescriptorHasColors().
authorDaniel Dunbar <daniel@zuster.org>
Fri, 20 Jul 2012 18:29:38 +0000 (18:29 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 20 Jul 2012 18:29:38 +0000 (18:29 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@160557 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/Process.h
lib/Support/Unix/Process.inc
lib/Support/Windows/Process.inc

index 91b92788f2ce6140c1fca616f8f0ffb6565e4bd3..088897c903d09d587b9d4689ac142047c1c8c545 100644 (file)
@@ -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
index 4e1bd5db142cdc6c2856ddec5d9e14896c971f05..174112e8c2ab81abf8f48b1c6d83b7a948e04c51 100644 (file)
@@ -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() {
index 6a1270c2f3085848553b5018c4bd8d316770684b..43ba028a8983355033c6de52912b533aa760b8a3 100644 (file)
@@ -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 {