[llvm] [LLVM] [Support] Assume ANSI escape support if $TERM is set. (PR #181512)

via llvm-commits llvm-commits at lists.llvm.org
Sat Feb 14 14:37:08 PST 2026


https://github.com/CrtlTom created https://github.com/llvm/llvm-project/pull/181512

The current method to decide on color output is to check `$TERM` against a list of known good values/patterns; this conservative behavior incorrectly assumes some terminals are incapable of interpreting ANSI color escape codes. Such as the foot terminal, which sets TERM=foot.

This aligns with GCC's current method, which assumes any value of $TERM means a tty will accept color, except for known exceptions, currently only the emacs M-x shell.

>From 4b15e71e7b6fb7f686443b17b7d0cbc7526cfa84 Mon Sep 17 00:00:00 2001
From: CrtlTom <tom.cortale-beck at etudiant.univ-perp.fr>
Date: Sat, 14 Feb 2026 22:55:56 +0100
Subject: [PATCH] [LLVM] [Support] Assume ANSI escape support if $TERM is set.

Aligns with GCC's current method for deciding on color output.
---
 llvm/lib/Support/Unix/Process.inc | 19 +++++--------------
 1 file changed, 5 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/Support/Unix/Process.inc b/llvm/lib/Support/Unix/Process.inc
index c6e79af44b9b4..0e4cc25da042a 100644
--- a/llvm/lib/Support/Unix/Process.inc
+++ b/llvm/lib/Support/Unix/Process.inc
@@ -344,20 +344,11 @@ unsigned Process::StandardErrColumns() {
 }
 
 static bool terminalHasColors() {
-  // 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);
-  }
+  // If TERM is defined in the environment, assume it supports ANSI color escape
+  // codes. This matches GCC.
+  if (const char *TermStr = std::getenv("TERM"))
+    // emacs M-x shell is a known exception and sets TERM="dumb".
+    return std::strcmp(TermStr, "dumb");
 
   return false;
 }



More information about the llvm-commits mailing list