[lldb] Turn on OSC 9;4 graphical progress in supported terminals#185541
[lldb] Turn on OSC 9;4 graphical progress in supported terminals#185541JDevlieghere merged 2 commits intollvm:mainfrom
Conversation
In llvm#162162, I added support for OSC 9;4 graphical progress. I put it behind the `show-progress` setting because I didn't have a reliable way to detect whether the escape code was supported by the terminal. Since then, more tools have added support for it, most notably Claude Code and Homebrew. While I still don't have a good way to detect this, there are a handful of known terminals that are easy enough to identify. This PR toggles the default of `show-progress` to on again and puts showing the progress behind a check for those known terminals (Windows Terminal, ConEmu & Ghostty). This means that if you're running in one of those, you'll get the visual progress by default unless you set `show-progress` to off. The downside is that if you're on an unrecognized terminal, you can't force it on any longer by setting `show-progress` to on. I think that's a fair trade-off as the setting wasn't really advertised and I doubt many people are using that. As a workaround, they can set `OSC_PROGRESS` to spoof an OSC-supporting terminal.
|
@llvm/pr-subscribers-lldb Author: Jonas Devlieghere (JDevlieghere) ChangesIn #162162, I added support for OSC 9;4 graphical progress. I put it behind the Since then, more tools have added support for it, most notably Claude Code and Homebrew. While I still don't have a good way to detect this, there are a handful of known terminals that are easy enough to identify. This PR toggles the default of This means that if you're running in one of those, you'll get the visual progress by default unless you set Full diff: https://github.com/llvm/llvm-project/pull/185541.diff 2 Files Affected:
diff --git a/lldb/source/Core/CoreProperties.td b/lldb/source/Core/CoreProperties.td
index c9141959a50f2..03326b130e067 100644
--- a/lldb/source/Core/CoreProperties.td
+++ b/lldb/source/Core/CoreProperties.td
@@ -184,7 +184,7 @@ let Definition = "debugger", Path = "" in {
def ShowProgress
: Property<"show-progress", "Boolean">,
Global,
- DefaultFalse,
+ DefaultTrue,
Desc<"Whether to show progress using Operating System Command (OSC) "
"Sequences in supporting terminal emulators.">;
def ShowProgressAnsiPrefix: Property<"show-progress-ansi-prefix", "String">,
diff --git a/lldb/source/Core/Debugger.cpp b/lldb/source/Core/Debugger.cpp
index 05c2ed13374ae..a993e17162f73 100644
--- a/lldb/source/Core/Debugger.cpp
+++ b/lldb/source/Core/Debugger.cpp
@@ -2077,6 +2077,30 @@ void Debugger::CancelForwardEvents(const ListenerSP &listener_sp) {
m_forward_listener_sp.reset();
}
+/// Conservative heuristic to detect whether OSC 9;4 progress is supported by
+/// the current terminal.
+static bool TerminalSupportsOSCProgress() {
+ static std::once_flag g_once_flag;
+ static bool g_supports_osc_progress = false;
+
+ std::call_once(g_once_flag, []() {
+ std::array<const char *, 4> g_known_env_vars = {
+ "WT_SESSION", // Windows Terminal
+ "ConEmuPID", // ConEmu
+ "GHOSTTY_RESOURCES_DIR", // Ghostty
+ "OSC_PROGRESS", // Override
+ };
+ for (const char *env_var : g_known_env_vars) {
+ if (std::getenv(env_var)) {
+ g_supports_osc_progress = true;
+ return;
+ }
+ }
+ });
+
+ return g_supports_osc_progress;
+}
+
bool Debugger::IsEscapeCodeCapableTTY() {
if (lldb::LockableStreamFileSP stream_sp = GetOutputStreamSP()) {
File &file = stream_sp->GetUnlockedFile();
@@ -2305,7 +2329,8 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
}
// Show progress using Operating System Command (OSC) sequences.
- if (GetShowProgress() && IsEscapeCodeCapableTTY()) {
+ if (GetShowProgress() && IsEscapeCodeCapableTTY() &&
+ TerminalSupportsOSCProgress()) {
if (lldb::LockableStreamFileSP stream_sp = GetOutputStreamSP()) {
// Clear progress if this was the last progress event.
|
In #162162, I added support for OSC 9;4 graphical progress. I put it behind the
show-progresssetting because I didn't have a reliable way to detect whether the escape code was supported by the terminal.Since then, more tools have added support for it, most notably Claude Code and Homebrew. While I still don't have a good way to detect this, there are a handful of known terminals that are easy enough to identify.
This PR toggles the default of
show-progressto on again and puts showing the progress behind a check for those known terminals (Windows Terminal, ConEmu & Ghostty).This means that if you're running in one of those, you'll get the visual progress by default unless you set
show-progressto off. The downside is that if you're on an unrecognized terminal, you can't force it on any longer by settingshow-progressto on. I think that's a fair trade-off as the setting wasn't really advertised and I doubt many people are using that. As a workaround, they can setOSC_PROGRESSto spoof an OSC-supporting terminal.