Skip to content

Commit 5678492

Browse files
committed
Redraw the statusline when editline has taken control of the screen
1 parent b467289 commit 5678492

File tree

6 files changed

+30
-7
lines changed

6 files changed

+30
-7
lines changed

lldb/include/lldb/Core/Debugger.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,9 @@ class Debugger : public std::enable_shared_from_this<Debugger>,
417417
/// Decrement the "interrupt requested" counter.
418418
void CancelInterruptRequest();
419419

420+
/// Redraw the statusline if enabled.
421+
void RedrawStatusline(bool update = true);
422+
420423
/// This is the correct way to query the state of Interruption.
421424
/// If you are on the RunCommandInterpreter thread, it will check the
422425
/// command interpreter state, and if it is on another thread it will

lldb/include/lldb/Core/IOHandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,8 @@ class IOHandlerEditline : public IOHandler {
406406
std::optional<std::string> SuggestionCallback(llvm::StringRef line);
407407

408408
void AutoCompleteCallback(CompletionRequest &request);
409+
410+
void RedrawCallback();
409411
#endif
410412

411413
protected:

lldb/include/lldb/Host/Editline.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ using SuggestionCallbackType =
102102

103103
using CompleteCallbackType = llvm::unique_function<void(CompletionRequest &)>;
104104

105+
using RedrawCallbackType = llvm::unique_function<void()>;
106+
105107
/// Status used to decide when and how to start editing another line in
106108
/// multi-line sessions.
107109
enum class EditorStatus {
@@ -194,6 +196,11 @@ class Editline {
194196
m_suggestion_callback = std::move(callback);
195197
}
196198

199+
/// Register a callback for redrawing the statusline.
200+
void SetRedrawCallback(RedrawCallbackType callback) {
201+
m_redraw_callback = std::move(callback);
202+
}
203+
197204
/// Register a callback for the tab key
198205
void SetAutoCompleteCallback(CompleteCallbackType callback) {
199206
m_completion_callback = std::move(callback);
@@ -409,6 +416,7 @@ class Editline {
409416

410417
CompleteCallbackType m_completion_callback;
411418
SuggestionCallbackType m_suggestion_callback;
419+
RedrawCallbackType m_redraw_callback;
412420

413421
bool m_color;
414422
std::string m_prompt_ansi_prefix;

lldb/source/Core/Debugger.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,7 @@ Status Debugger::SetPropertyValue(const ExecutionContext *exe_ctx,
258258
} else if (property_path ==
259259
g_debugger_properties[ePropertyStatuslineFormat].name) {
260260
// Statusline format changed. Redraw the statusline.
261-
if (m_statusline)
262-
m_statusline->Redraw();
261+
RedrawStatusline();
263262
} else if (property_path ==
264263
g_debugger_properties[ePropertyUseSourceCache].name) {
265264
// use-source-cache changed. Wipe out the cache contents if it was
@@ -1155,6 +1154,11 @@ void Debugger::RestoreInputTerminalState() {
11551154
m_statusline->Enable();
11561155
}
11571156

1157+
void Debugger::RedrawStatusline(bool update) {
1158+
if (m_statusline)
1159+
m_statusline->Redraw(update);
1160+
}
1161+
11581162
ExecutionContext Debugger::GetSelectedExecutionContext() {
11591163
bool adopt_selected = true;
11601164
ExecutionContextRef exe_ctx_ref(GetSelectedTarget().get(), adopt_selected);
@@ -2084,8 +2088,7 @@ lldb::thread_result_t Debugger::DefaultEventHandler() {
20842088
if (m_forward_listener_sp)
20852089
m_forward_listener_sp->AddEvent(event_sp);
20862090
}
2087-
if (m_statusline)
2088-
m_statusline->Redraw();
2091+
RedrawStatusline();
20892092
}
20902093
}
20912094

@@ -2176,9 +2179,7 @@ void Debugger::HandleProgressEvent(const lldb::EventSP &event_sp) {
21762179
}
21772180
}
21782181

2179-
// Redraw the statusline if enabled.
2180-
if (m_statusline)
2181-
m_statusline->Redraw();
2182+
RedrawStatusline();
21822183
}
21832184

21842185
std::optional<Debugger::ProgressReport>

lldb/source/Core/IOHandler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ IOHandlerEditline::IOHandlerEditline(
258258
m_editline_up->SetAutoCompleteCallback([this](CompletionRequest &request) {
259259
this->AutoCompleteCallback(request);
260260
});
261+
m_editline_up->SetRedrawCallback([this]() { this->RedrawCallback(); });
261262

262263
if (debugger.GetUseAutosuggestion()) {
263264
m_editline_up->SetSuggestionCallback([this](llvm::StringRef line) {
@@ -439,6 +440,11 @@ IOHandlerEditline::SuggestionCallback(llvm::StringRef line) {
439440
void IOHandlerEditline::AutoCompleteCallback(CompletionRequest &request) {
440441
m_delegate.IOHandlerComplete(*this, request);
441442
}
443+
444+
void IOHandlerEditline::RedrawCallback() {
445+
m_debugger.RedrawStatusline(/*update=*/false);
446+
}
447+
442448
#endif
443449

444450
const char *IOHandlerEditline::GetPrompt() {

lldb/source/Host/common/Editline.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,9 @@ int Editline::GetCharacter(EditLineGetCharType *c) {
567567
m_needs_prompt_repaint = false;
568568
}
569569

570+
if (m_redraw_callback)
571+
m_redraw_callback();
572+
570573
if (m_multiline_enabled) {
571574
// Detect when the number of rows used for this input line changes due to
572575
// an edit

0 commit comments

Comments
 (0)