[PATCH] D125914: [llvm/Support] Fallback to $TERM if terminfo has no "colors" capability
Med Ismail Bennani via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed May 18 18:23:08 PDT 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGb3718bc4672b: [llvm/Support] Fallback to $TERM if terminfo has no "colors" capability (authored by mib).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D125914/new/
https://reviews.llvm.org/D125914
Files:
llvm/lib/Support/Unix/Process.inc
Index: llvm/lib/Support/Unix/Process.inc
===================================================================
--- llvm/lib/Support/Unix/Process.inc
+++ llvm/lib/Support/Unix/Process.inc
@@ -331,6 +331,23 @@
static ManagedStatic<std::mutex> TermColorMutex;
#endif
+bool checkTerminalEnvironmentForColors() {
+ 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);
+ }
+
+ return false;
+}
+
static bool terminalHasColors(int fd) {
#ifdef LLVM_ENABLE_TERMINFO
// First, acquire a global lock because these C routines are thread hostile.
@@ -356,7 +373,8 @@
//
// The 'tigetnum' routine returns -2 or -1 on errors, and might return 0 if
// the terminfo says that no colors are supported.
- bool HasColors = tigetnum(const_cast<char *>("colors")) > 0;
+ int colors_ti = tigetnum(const_cast<char *>("colors"));
+ bool HasColors = colors_ti >= 0 ? colors_ti : checkTerminalEnvironmentForColors();
// Now extract the structure allocated by setupterm and free its memory
// through a really silly dance.
@@ -364,27 +382,12 @@
(void)del_curterm(termp); // Drop any errors here.
// Return true if we found a color capabilities for the current terminal.
- if (HasColors)
- return true;
+ return HasColors;
#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);
- }
+ return checkTerminalEnvironmentForColors();
#endif
-
- // Otherwise, be conservative.
- return false;
}
bool Process::FileDescriptorHasColors(int fd) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125914.430553.patch
Type: text/x-patch
Size: 2250 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220519/e461776d/attachment.bin>
More information about the llvm-commits
mailing list