@@ -2066,19 +2066,23 @@ void Debugger::CancelForwardEvents(const ListenerSP &listener_sp) {
20662066 m_forward_listener_sp.reset ();
20672067}
20682068
2069+ bool Debugger::IsInteractiveColorTTY () {
2070+ if (lldb::LockableStreamFileSP stream_sp = GetOutputStreamSP ()) {
2071+ File &file = stream_sp->GetUnlockedFile ();
2072+ return file.GetIsInteractive () && file.GetIsRealTerminal () &&
2073+ file.GetIsTerminalWithColors ();
2074+ }
2075+ return false ;
2076+ }
2077+
20692078bool Debugger::StatuslineSupported () {
20702079// We have trouble with the contol codes on Windows, see
20712080// https://github.com/llvm/llvm-project/issues/134846.
20722081#ifndef _WIN32
2073- if (GetShowStatusline ()) {
2074- if (lldb::LockableStreamFileSP stream_sp = GetOutputStreamSP ()) {
2075- File &file = stream_sp->GetUnlockedFile ();
2076- return file.GetIsInteractive () && file.GetIsRealTerminal () &&
2077- file.GetIsTerminalWithColors ();
2078- }
2079- }
2080- #endif
2082+ return GetShowStatusline () && IsInteractiveColorTTY ();
2083+ #else
20812084 return false ;
2085+ #endif
20822086}
20832087
20842088static bool RequiresFollowChildWorkaround (const Process &process) {
@@ -2271,10 +2275,11 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
22712275 ProgressReport progress_report{data->GetID (), data->GetCompleted (),
22722276 data->GetTotal (), data->GetMessage ()};
22732277
2274- // Do some bookkeeping regardless of whether we're going to display
2275- // progress reports.
22762278 {
22772279 std::lock_guard<std::mutex> guard (m_progress_reports_mutex);
2280+
2281+ // Do some bookkeeping regardless of whether we're going to display
2282+ // progress reports.
22782283 auto it = llvm::find_if (m_progress_reports, [&](const auto &report) {
22792284 return report.id == progress_report.id ;
22802285 });
@@ -2287,6 +2292,30 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
22872292 } else {
22882293 m_progress_reports.push_back (progress_report);
22892294 }
2295+
2296+ // Show progress using Operating System Command (OSC) sequences.
2297+ if (GetShowProgress () && IsInteractiveColorTTY ()) {
2298+ if (lldb::LockableStreamFileSP stream_sp = GetOutputStreamSP ()) {
2299+
2300+ // Clear progress if this was the last progress event.
2301+ if (m_progress_reports.empty ()) {
2302+ stream_sp->Lock () << OSC_PROGRESS_REMOVE;
2303+ return ;
2304+ }
2305+
2306+ const ProgressReport &report = m_progress_reports.back ();
2307+
2308+ // Show indeterminate progress.
2309+ if (report.total == UINT64_MAX) {
2310+ stream_sp->Lock () << OSC_PROGRESS_INDETERMINATE;
2311+ return ;
2312+ }
2313+
2314+ // Compute and show the progress value (0-100).
2315+ const unsigned value = (report.completed / report.total ) * 100 ;
2316+ stream_sp->Lock ().Printf (OSC_PROGRESS_SHOW, value);
2317+ }
2318+ }
22902319 }
22912320}
22922321
0 commit comments