summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Unix/Process.inc
diff options
context:
space:
mode:
authorPetr Hosek <phosek@chromium.org>2018-01-19 17:10:55 +0000
committerPetr Hosek <phosek@chromium.org>2018-01-19 17:10:55 +0000
commitcc7a8f14bd00dad20505a087d0ae93a06e7746fe (patch)
treea58ebd110829ee1c779a1761567207f72f6ce049 /llvm/lib/Support/Unix/Process.inc
parent4c8382eec60d75825cda1041832a3278e9443d3f (diff)
downloadbcm5719-llvm-cc7a8f14bd00dad20505a087d0ae93a06e7746fe.tar.gz
bcm5719-llvm-cc7a8f14bd00dad20505a087d0ae93a06e7746fe.zip
Fallback option for colorized output when terminfo isn't available
Try to detect the terminal color support by checking the value of the TERM environment variable. This is not great, but it's better than nothing when terminfo library isn't available, which may still be the case on some Linux distributions. Differential Revision: https://reviews.llvm.org/D42055 llvm-svn: 322962
Diffstat (limited to 'llvm/lib/Support/Unix/Process.inc')
-rw-r--r--llvm/lib/Support/Unix/Process.inc15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index e43650d707e..7a4e3861400 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -369,6 +369,21 @@ static bool terminalHasColors(int fd) {
// 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.
OpenPOWER on IntegriCloud