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

>From 65126c7ebb94bcee69ac513ec97e0227f4f2e1aa Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Tue, 18 Nov 2025 22:41:43 +0100
Subject: [PATCH 1/4] [lldb] improve the heuristics for checking if a terminal
 supports Unicode

---
 lldb/include/lldb/Host/Terminal.h                | 11 +++++++++++
 lldb/source/Host/common/DiagnosticsRendering.cpp |  8 +++-----
 lldb/source/Host/common/Terminal.cpp             | 15 +++++++++++++++
 3 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/lldb/include/lldb/Host/Terminal.h 
b/lldb/include/lldb/Host/Terminal.h
index da0d05e8bd265..6da5d45644b28 100644
--- a/lldb/include/lldb/Host/Terminal.h
+++ b/lldb/include/lldb/Host/Terminal.h
@@ -169,6 +169,17 @@ class TerminalState {
   lldb::pid_t m_process_group = -1;       ///< Cached process group 
information.
 };
 
+/// 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();
+
 } // namespace lldb_private
 
 #endif // LLDB_HOST_TERMINAL_H
diff --git a/lldb/source/Host/common/DiagnosticsRendering.cpp 
b/lldb/source/Host/common/DiagnosticsRendering.cpp
index f2cd3968967fb..c7e083573c631 100644
--- a/lldb/source/Host/common/DiagnosticsRendering.cpp
+++ b/lldb/source/Host/common/DiagnosticsRendering.cpp
@@ -7,6 +7,8 @@
 
//===----------------------------------------------------------------------===//
 
 #include "lldb/Host/common/DiagnosticsRendering.h"
+#include "lldb/Host/Terminal.h"
+
 #include <cstdint>
 
 using namespace lldb_private;
@@ -97,12 +99,8 @@ void RenderDiagnosticDetails(Stream &stream,
     return;
   }
 
-  // Since there is no other way to find this out, use the color
-  // attribute as a proxy for whether the terminal supports Unicode
-  // 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 = "│";
diff --git a/lldb/source/Host/common/Terminal.cpp 
b/lldb/source/Host/common/Terminal.cpp
index 436dfd8130d9b..825e9e0aee78e 100644
--- a/lldb/source/Host/common/Terminal.cpp
+++ b/lldb/source/Host/common/Terminal.cpp
@@ -472,3 +472,18 @@ bool TerminalState::TTYStateIsValid() const { return 
bool(m_data); }
 bool TerminalState::ProcessGroupIsValid() const {
   return static_cast<int32_t>(m_process_group) != -1;
 }
+
+bool lldb_private::TerminalSupportsUnicode() {
+  static std::optional<bool> result;
+  if (result)
+    return result.value();
+#ifdef _WIN32
+  return true;
+#else
+  const char *lang_var = std::getenv("LANG");
+  if (!lang_var)
+    return false;
+  result = llvm::StringRef(lang_var).lower().find("utf-8") != 
std::string::npos;
+#endif
+  return result.value();
+}

>From 6fc6b567ba158d9867561b45ac68a3601c28c67e Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Wed, 19 Nov 2025 15:01:23 +0100
Subject: [PATCH 2/4] fixup! [lldb] improve the heuristics for checking if a
 terminal supports Unicode

---
 lldb/include/lldb/Host/Terminal.h | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/lldb/include/lldb/Host/Terminal.h 
b/lldb/include/lldb/Host/Terminal.h
index 6da5d45644b28..bfcd66b13ded8 100644
--- a/lldb/include/lldb/Host/Terminal.h
+++ b/lldb/include/lldb/Host/Terminal.h
@@ -174,10 +174,11 @@ class TerminalState {
 /// The value is cached after the first computation.
 ///
 /// On POSIX systems, we check if the LANG environment variable contains the
-/// substring "UTF-8";
+/// substring "UTF-8", case insensitive.
 ///
-/// On Windows, we check that we are running from the Windows Terminal
-/// application.
+/// On Windows, we always return true since we use the `WriteConsoleW` API
+/// internally. Note that the default Windows codepage (437) does not support
+/// all Unicode characters. This function does not check the codepage.
 bool TerminalSupportsUnicode();
 
 } // namespace lldb_private

>From 19cad716e620256a06be2ac03351b0a5116380ee Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Mon, 24 Nov 2025 18:02:45 +0000
Subject: [PATCH 3/4] fixup! fixup! [lldb] improve the heuristics for checking
 if a terminal supports Unicode

---
 lldb/include/lldb/Host/Terminal.h    | 24 +++++++++++-----------
 lldb/source/Host/common/Terminal.cpp | 30 ++++++++++++++--------------
 2 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/lldb/include/lldb/Host/Terminal.h 
b/lldb/include/lldb/Host/Terminal.h
index bfcd66b13ded8..3d66515c18812 100644
--- a/lldb/include/lldb/Host/Terminal.h
+++ b/lldb/include/lldb/Host/Terminal.h
@@ -68,6 +68,18 @@ class Terminal {
 
   llvm::Error SetHardwareFlowControl(bool enabled);
 
+  /// 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", case insensitive.
+  ///
+  /// On Windows, we always return true since we use the `WriteConsoleW` API
+  /// internally. Note that the default Windows codepage (437) does not support
+  /// all Unicode characters. This function does not check the codepage.
+  static bool SupportsUnicode();
+
 protected:
   struct Data;
 
@@ -169,18 +181,6 @@ class TerminalState {
   lldb::pid_t m_process_group = -1;       ///< Cached process group 
information.
 };
 
-/// 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", case insensitive.
-///
-/// On Windows, we always return true since we use the `WriteConsoleW` API
-/// internally. Note that the default Windows codepage (437) does not support
-/// all Unicode characters. This function does not check the codepage.
-bool TerminalSupportsUnicode();
-
 } // namespace lldb_private
 
 #endif // LLDB_HOST_TERMINAL_H
diff --git a/lldb/source/Host/common/Terminal.cpp 
b/lldb/source/Host/common/Terminal.cpp
index 825e9e0aee78e..dd1dc75133f45 100644
--- a/lldb/source/Host/common/Terminal.cpp
+++ b/lldb/source/Host/common/Terminal.cpp
@@ -400,6 +400,21 @@ llvm::Error Terminal::SetHardwareFlowControl(bool enabled) 
{
 #endif // LLDB_ENABLE_TERMIOS
 }
 
+bool Terminal::SupportsUnicode() {
+  static std::optional<bool> result;
+  if (result)
+    return result.value();
+#ifdef _WIN32
+  return true;
+#else
+  const char *lang_var = std::getenv("LANG");
+  if (!lang_var)
+    return false;
+  result = llvm::StringRef(lang_var).lower().find("utf-8") != 
std::string::npos;
+#endif
+  return result.value();
+}
+
 TerminalState::TerminalState(Terminal term, bool save_process_group)
     : m_tty(term) {
   Save(term, save_process_group);
@@ -472,18 +487,3 @@ bool TerminalState::TTYStateIsValid() const { return 
bool(m_data); }
 bool TerminalState::ProcessGroupIsValid() const {
   return static_cast<int32_t>(m_process_group) != -1;
 }
-
-bool lldb_private::TerminalSupportsUnicode() {
-  static std::optional<bool> result;
-  if (result)
-    return result.value();
-#ifdef _WIN32
-  return true;
-#else
-  const char *lang_var = std::getenv("LANG");
-  if (!lang_var)
-    return false;
-  result = llvm::StringRef(lang_var).lower().find("utf-8") != 
std::string::npos;
-#endif
-  return result.value();
-}

>From 55818e20ccf36382f6e7e52f6c5140bc18a14c51 Mon Sep 17 00:00:00 2001
From: Charles Zablit <[email protected]>
Date: Wed, 26 Nov 2025 16:34:46 +0000
Subject: [PATCH 4/4] fix call to removed method

---
 lldb/source/Host/common/DiagnosticsRendering.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lldb/source/Host/common/DiagnosticsRendering.cpp 
b/lldb/source/Host/common/DiagnosticsRendering.cpp
index c7e083573c631..375d1caa99f52 100644
--- a/lldb/source/Host/common/DiagnosticsRendering.cpp
+++ b/lldb/source/Host/common/DiagnosticsRendering.cpp
@@ -100,7 +100,7 @@ void RenderDiagnosticDetails(Stream &stream,
   }
 
   llvm::StringRef cursor, underline, vbar, joint, hbar, spacer;
-  if (TerminalSupportsUnicode()) {
+  if (Terminal::SupportsUnicode()) {
     cursor = "˄";
     underline = "˜";
     vbar = "│";

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to