Skip to content

Fix a bug in handling ^C at the "y/n/a" completion prompt. #7530

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lldb/include/lldb/Host/Editline.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,10 @@ class Editline {
/// of Editline.
static Editline *InstanceFor(::EditLine *editline);

static void
DisplayCompletions(Editline &editline,
llvm::ArrayRef<CompletionResult::Completion> results);

/// Sets a string to be used as a prompt, or combined with a line number to
/// form a prompt.
void SetPrompt(const char *prompt);
Expand Down
28 changes: 18 additions & 10 deletions lldb/source/Host/common/Editline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -939,12 +939,12 @@ PrintCompletion(FILE *output_file,
}
}

static void
DisplayCompletions(::EditLine *editline, FILE *output_file,
llvm::ArrayRef<CompletionResult::Completion> results) {
void Editline::DisplayCompletions(
Editline &editline, llvm::ArrayRef<CompletionResult::Completion> results) {
assert(!results.empty());

fprintf(output_file, "\n" ANSI_CLEAR_BELOW "Available completions:\n");
fprintf(editline.m_output_file,
"\n" ANSI_CLEAR_BELOW "Available completions:\n");
const size_t page_size = 40;
bool all = false;

Expand All @@ -956,7 +956,7 @@ DisplayCompletions(::EditLine *editline, FILE *output_file,
const size_t max_len = longest->GetCompletion().size();

if (results.size() < page_size) {
PrintCompletion(output_file, results, max_len);
PrintCompletion(editline.m_output_file, results, max_len);
return;
}

Expand All @@ -965,17 +965,25 @@ DisplayCompletions(::EditLine *editline, FILE *output_file,
size_t remaining = results.size() - cur_pos;
size_t next_size = all ? remaining : std::min(page_size, remaining);

PrintCompletion(output_file, results.slice(cur_pos, next_size), max_len);
PrintCompletion(editline.m_output_file, results.slice(cur_pos, next_size),
max_len);

cur_pos += next_size;

if (cur_pos >= results.size())
break;

fprintf(output_file, "More (Y/n/a): ");
fprintf(editline.m_output_file, "More (Y/n/a): ");
char reply = 'n';
int got_char = el_getc(editline, &reply);
fprintf(output_file, "\n");
int got_char = el_getc(editline.m_editline, &reply);
// Check for a ^C or other interruption.
if (editline.m_editor_status == EditorStatus::Interrupted) {
editline.m_editor_status = EditorStatus::Editing;
fprintf(editline.m_output_file, "^C\n");
break;
}

fprintf(editline.m_output_file, "\n");
if (got_char == -1 || reply == 'n')
break;
if (reply == 'a')
Expand Down Expand Up @@ -1046,7 +1054,7 @@ unsigned char Editline::TabCommand(int ch) {
return CC_REDISPLAY;
}

DisplayCompletions(m_editline, m_output_file, results);
DisplayCompletions(*this, results);

DisplayInput();
MoveCursor(CursorLocation::BlockEnd, CursorLocation::EditingCursor);
Expand Down
6 changes: 6 additions & 0 deletions lldb/test/API/iohandler/completion/TestIOHandlerCompletion.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def test_completion(self):
self.child.send("n")
self.expect_prompt()

# Start tab completion and abort showing more commands with '^C'.
self.child.send("\t")
self.child.expect_exact("More (Y/n/a)")
self.child.sendcontrol("c")
self.expect_prompt()

# Shouldn't crash or anything like that.
self.child.send("regoinvalid\t")
self.expect_prompt()
Expand Down