mib created this revision. mib added a reviewer: JDevlieghere. mib added a project: LLDB. Herald added a project: All. mib requested review of this revision. Herald added a subscriber: lldb-commits.
When the terminal window is too small, lldb would wrap progress messages accross multiple lines which would break the progress event handling code that is supposed to clear the message once the progress is completed. This causes the progress message to stay, sometimes partially which can be confusing for the user. To fix this issue, this patch trims the progress message to the terminal width taking into account the progress counter leading the message for finite progress events and also the trailing `...`. rdar://91993836 Signed-off-by: Med Ismail Bennani <medismail.benn...@gmail.com> Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D124785 Files: lldb/include/lldb/Core/DebuggerEvents.h lldb/source/Core/Debugger.cpp Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -1857,11 +1857,26 @@ output->Printf( "%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str()); - // Print the progress message. + // Trim the progress message if it exceeds the window's width and print it. std::string message = data->GetMessage(); - if (data->GetTotal() != UINT64_MAX) { + uint64_t progress_total = data->GetTotal(); + uint32_t term_width = GetTerminalWidth(); + + size_t prefix_width = 0; + if (data->IsFinite()) { + prefix_width += 4; // '[%PRIu64/%PRIu64] %s' + prefix_width += std::to_string(progress_total).size() * 2; + } + + const size_t suffix_width = 3; // %s... + + if (message.size() + prefix_width + suffix_width >= term_width) + message.erase(message.begin() + term_width - prefix_width - suffix_width, + message.end()); + + if (data->IsFinite()) { output->Printf("[%" PRIu64 "/%" PRIu64 "] %s...", data->GetCompleted(), - data->GetTotal(), message.c_str()); + progress_total, message.c_str()); } else { output->Printf("%s...", message.c_str()); } Index: lldb/include/lldb/Core/DebuggerEvents.h =================================================================== --- lldb/include/lldb/Core/DebuggerEvents.h +++ lldb/include/lldb/Core/DebuggerEvents.h @@ -32,6 +32,7 @@ static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr); uint64_t GetID() const { return m_id; } + bool IsFinite() const { return m_total != UINT64_MAX; } uint64_t GetCompleted() const { return m_completed; } uint64_t GetTotal() const { return m_total; } const std::string &GetMessage() const { return m_message; }
Index: lldb/source/Core/Debugger.cpp =================================================================== --- lldb/source/Core/Debugger.cpp +++ lldb/source/Core/Debugger.cpp @@ -1857,11 +1857,26 @@ output->Printf( "%s", ansi::FormatAnsiTerminalCodes(ansi_prefix, use_color).c_str()); - // Print the progress message. + // Trim the progress message if it exceeds the window's width and print it. std::string message = data->GetMessage(); - if (data->GetTotal() != UINT64_MAX) { + uint64_t progress_total = data->GetTotal(); + uint32_t term_width = GetTerminalWidth(); + + size_t prefix_width = 0; + if (data->IsFinite()) { + prefix_width += 4; // '[%PRIu64/%PRIu64] %s' + prefix_width += std::to_string(progress_total).size() * 2; + } + + const size_t suffix_width = 3; // %s... + + if (message.size() + prefix_width + suffix_width >= term_width) + message.erase(message.begin() + term_width - prefix_width - suffix_width, + message.end()); + + if (data->IsFinite()) { output->Printf("[%" PRIu64 "/%" PRIu64 "] %s...", data->GetCompleted(), - data->GetTotal(), message.c_str()); + progress_total, message.c_str()); } else { output->Printf("%s...", message.c_str()); } Index: lldb/include/lldb/Core/DebuggerEvents.h =================================================================== --- lldb/include/lldb/Core/DebuggerEvents.h +++ lldb/include/lldb/Core/DebuggerEvents.h @@ -32,6 +32,7 @@ static const ProgressEventData *GetEventDataFromEvent(const Event *event_ptr); uint64_t GetID() const { return m_id; } + bool IsFinite() const { return m_total != UINT64_MAX; } uint64_t GetCompleted() const { return m_completed; } uint64_t GetTotal() const { return m_total; } const std::string &GetMessage() const { return m_message; }
_______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits