Skip to content

Commit 19cad71

Browse files
fixup! fixup! [lldb] improve the heuristics for checking if a terminal supports Unicode
1 parent 6fc6b56 commit 19cad71

File tree

2 files changed

+27
-27
lines changed

2 files changed

+27
-27
lines changed

lldb/include/lldb/Host/Terminal.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ class Terminal {
6868

6969
llvm::Error SetHardwareFlowControl(bool enabled);
7070

71+
/// Returns whether or not the current terminal supports Unicode rendering.
72+
///
73+
/// The value is cached after the first computation.
74+
///
75+
/// On POSIX systems, we check if the LANG environment variable contains the
76+
/// substring "UTF-8", case insensitive.
77+
///
78+
/// On Windows, we always return true since we use the `WriteConsoleW` API
79+
/// internally. Note that the default Windows codepage (437) does not support
80+
/// all Unicode characters. This function does not check the codepage.
81+
static bool SupportsUnicode();
82+
7183
protected:
7284
struct Data;
7385

@@ -169,18 +181,6 @@ class TerminalState {
169181
lldb::pid_t m_process_group = -1; ///< Cached process group information.
170182
};
171183

172-
/// Returns whether or not the current terminal supports Unicode rendering.
173-
///
174-
/// The value is cached after the first computation.
175-
///
176-
/// On POSIX systems, we check if the LANG environment variable contains the
177-
/// substring "UTF-8", case insensitive.
178-
///
179-
/// On Windows, we always return true since we use the `WriteConsoleW` API
180-
/// internally. Note that the default Windows codepage (437) does not support
181-
/// all Unicode characters. This function does not check the codepage.
182-
bool TerminalSupportsUnicode();
183-
184184
} // namespace lldb_private
185185

186186
#endif // LLDB_HOST_TERMINAL_H

lldb/source/Host/common/Terminal.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,21 @@ llvm::Error Terminal::SetHardwareFlowControl(bool enabled) {
400400
#endif // LLDB_ENABLE_TERMIOS
401401
}
402402

403+
bool Terminal::SupportsUnicode() {
404+
static std::optional<bool> result;
405+
if (result)
406+
return result.value();
407+
#ifdef _WIN32
408+
return true;
409+
#else
410+
const char *lang_var = std::getenv("LANG");
411+
if (!lang_var)
412+
return false;
413+
result = llvm::StringRef(lang_var).lower().find("utf-8") != std::string::npos;
414+
#endif
415+
return result.value();
416+
}
417+
403418
TerminalState::TerminalState(Terminal term, bool save_process_group)
404419
: m_tty(term) {
405420
Save(term, save_process_group);
@@ -472,18 +487,3 @@ bool TerminalState::TTYStateIsValid() const { return bool(m_data); }
472487
bool TerminalState::ProcessGroupIsValid() const {
473488
return static_cast<int32_t>(m_process_group) != -1;
474489
}
475-
476-
bool lldb_private::TerminalSupportsUnicode() {
477-
static std::optional<bool> result;
478-
if (result)
479-
return result.value();
480-
#ifdef _WIN32
481-
return true;
482-
#else
483-
const char *lang_var = std::getenv("LANG");
484-
if (!lang_var)
485-
return false;
486-
result = llvm::StringRef(lang_var).lower().find("utf-8") != std::string::npos;
487-
#endif
488-
return result.value();
489-
}

0 commit comments

Comments
 (0)