Skip to content

Commit

Permalink
Fallback option for colorized output when terminfo isn't available
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petrhosek committed Jan 19, 2018
1 parent 4c8382e commit cc7a8f1
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions llvm/lib/Support/Unix/Process.inc
Expand Up @@ -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.
Expand Down

0 comments on commit cc7a8f1

Please sign in to comment.