1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:35:07 +00:00

LibLine: Properly handle ^C and do not return after being interrupted

this commit fixes a...surprisingly long-standing ^C bug, where it would
return the buffer instead of voiding it and starting over :^)
This commit is contained in:
AnotherTest 2020-04-20 17:53:24 +04:30 committed by Andreas Kling
parent 42f06fc305
commit e578b7884b
2 changed files with 15 additions and 10 deletions

View file

@ -148,18 +148,18 @@ String Editor::get_line(const String& prompt)
exit(0);
if (nread < 0) {
if (errno == EINTR) {
if (m_was_interrupted) {
if (!m_was_interrupted) {
if (m_was_resized)
continue;
m_was_interrupted = false;
if (!m_buffer.is_empty())
printf("^C");
if (m_is_searching) {
end_search();
continue;
}
m_buffer.clear();
m_cursor = 0;
}
if (m_was_resized)
continue;
finish();
continue;
@ -600,7 +600,9 @@ String Editor::get_line(const String& prompt)
} else {
m_is_searching = true;
m_search_offset = 0;
m_pre_search_buffer = m_buffer;
m_pre_search_buffer.clear();
for (auto ch : m_buffer)
m_pre_search_buffer.append(ch);
m_pre_search_cursor = m_cursor;
m_search_editor = make<Editor>(true); // Has anyone seen 'Inception'?
m_search_editor->initialize();
@ -640,6 +642,7 @@ String Editor::get_line(const String& prompt)
auto search_prompt = "\x1b[32msearch:\x1b[0m ";
auto search_string = m_search_editor->get_line(search_prompt);
m_search_editor = nullptr;
m_is_searching = false;
m_search_offset = 0;