[PATCH] D42055: Fallback option for colorized output when terminfo isn't available

Petr Hosek via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jan 18 19:20:40 PST 2018


phosek updated this revision to Diff 130548.
phosek edited the summary of this revision.
phosek added a comment.

I've implemented what @joerg suggested, is this acceptable?


Repository:
  rL LLVM

https://reviews.llvm.org/D42055

Files:
  lib/Support/Unix/Process.inc


Index: lib/Support/Unix/Process.inc
===================================================================
--- lib/Support/Unix/Process.inc
+++ lib/Support/Unix/Process.inc
@@ -369,6 +369,21 @@
   // Return true if we found a color capabilities for the current terminal.
   if (HasColors)
     return true;
+#else
+  // When the terminfo database is not available, check if the current terminal
+  // is one of terminals that are known to support ANSI color escape codes.
+  if (const char *TermStr = std::getenv("TERM")) {
+    return StringSwitch<bool>(TermStr)
+      .Case("ansi", true)
+      .Case("cygwin", true)
+      .Case("linux", true)
+      .StartsWith("screen", true)
+      .StartsWith("xterm", true)
+      .StartsWith("vt100", true)
+      .StartsWith("rxvt", true)
+      .EndsWith("color", true)
+      .Default(false);
+  }
 #endif
 
   // Otherwise, be conservative.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42055.130548.patch
Type: text/x-patch
Size: 886 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180119/89351755/attachment.bin>


More information about the llvm-commits mailing list