[Lldb-commits] [lldb] [lldb] improve the heuristics for checking if a terminal supports Unicode (PR #168603)

Charles Zablit via lldb-commits lldb-commits at lists.llvm.org
Tue Nov 18 11:46:42 PST 2025


https://github.com/charles-zablit updated https://github.com/llvm/llvm-project/pull/168603

>From 70a77fc934a37ec4bf19ffec823a55660b9dfac4 Mon Sep 17 00:00:00 2001
From: Charles Zablit <c_zablit at apple.com>
Date: Tue, 18 Nov 2025 20:43:12 +0100
Subject: [PATCH] [lldb] improve the heuristics for checking if a terminal
 supports Unicode

---
 .../include/lldb/Utility/DiagnosticsRendering.h | 11 +++++++++++
 lldb/source/Utility/DiagnosticsRendering.cpp    | 17 ++++++++++++++++-
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/lldb/include/lldb/Utility/DiagnosticsRendering.h b/lldb/include/lldb/Utility/DiagnosticsRendering.h
index dd33d671c24a5..3dfa9b0880f70 100644
--- a/lldb/include/lldb/Utility/DiagnosticsRendering.h
+++ b/lldb/include/lldb/Utility/DiagnosticsRendering.h
@@ -64,6 +64,17 @@ void RenderDiagnosticDetails(Stream &stream,
                              bool show_inline,
                              llvm::ArrayRef<DiagnosticDetail> details);
 
+/// Returns whether or not the current terminal supports Unicode rendering.
+///
+/// The value is cached after the first computation.
+///
+/// On POSIX systems, we check if the LANG environment variable contains the
+/// substring "UTF-8";
+///
+/// On Windows, we check that we are running from the Windows Terminal
+/// application.
+bool TerminalSupportsUnicode();
+
 class DiagnosticError
     : public llvm::ErrorInfo<DiagnosticError, CloneableECError> {
 public:
diff --git a/lldb/source/Utility/DiagnosticsRendering.cpp b/lldb/source/Utility/DiagnosticsRendering.cpp
index 8c21e661ce764..6ee0e1b3e04f5 100644
--- a/lldb/source/Utility/DiagnosticsRendering.cpp
+++ b/lldb/source/Utility/DiagnosticsRendering.cpp
@@ -102,7 +102,7 @@ void RenderDiagnosticDetails(Stream &stream,
   // characters.  In the future it might make sense to move this into
   // Host so it can be customized for a specific platform.
   llvm::StringRef cursor, underline, vbar, joint, hbar, spacer;
-  if (stream.AsRawOstream().colors_enabled()) {
+  if (TerminalSupportsUnicode()) {
     cursor = "˄";
     underline = "˜";
     vbar = "│";
@@ -232,4 +232,19 @@ void RenderDiagnosticDetails(Stream &stream,
     }
 }
 
+bool TerminalSupportsUnicode() {
+  static std::optional<bool> result;
+  if (result)
+    return result.value();
+#ifndef _WIN32
+  if (const char *lang_var = std::getenv("LANG"))
+    result = std::string(lang_var).find("UTF-8");
+  else
+    result = false;
+#else
+  result = std::getenv("WT_SESSION") != nullptr;
+#endif
+  return result.value();
+}
+
 } // namespace lldb_private



More information about the lldb-commits mailing list