mirror of
https://github.com/RGBCube/serenity
synced 2025-05-24 03:25:06 +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:
parent
42f06fc305
commit
e578b7884b
2 changed files with 15 additions and 10 deletions
|
@ -148,18 +148,18 @@ String Editor::get_line(const String& prompt)
|
||||||
exit(0);
|
exit(0);
|
||||||
if (nread < 0) {
|
if (nread < 0) {
|
||||||
if (errno == EINTR) {
|
if (errno == EINTR) {
|
||||||
if (m_was_interrupted) {
|
if (!m_was_interrupted) {
|
||||||
|
if (m_was_resized)
|
||||||
|
continue;
|
||||||
|
|
||||||
m_was_interrupted = false;
|
m_was_interrupted = false;
|
||||||
|
|
||||||
if (!m_buffer.is_empty())
|
if (!m_buffer.is_empty())
|
||||||
printf("^C");
|
printf("^C");
|
||||||
|
|
||||||
if (m_is_searching) {
|
m_buffer.clear();
|
||||||
end_search();
|
m_cursor = 0;
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (m_was_resized)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
finish();
|
finish();
|
||||||
continue;
|
continue;
|
||||||
|
@ -600,7 +600,9 @@ String Editor::get_line(const String& prompt)
|
||||||
} else {
|
} else {
|
||||||
m_is_searching = true;
|
m_is_searching = true;
|
||||||
m_search_offset = 0;
|
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_pre_search_cursor = m_cursor;
|
||||||
m_search_editor = make<Editor>(true); // Has anyone seen 'Inception'?
|
m_search_editor = make<Editor>(true); // Has anyone seen 'Inception'?
|
||||||
m_search_editor->initialize();
|
m_search_editor->initialize();
|
||||||
|
@ -640,6 +642,7 @@ String Editor::get_line(const String& prompt)
|
||||||
|
|
||||||
auto search_prompt = "\x1b[32msearch:\x1b[0m ";
|
auto search_prompt = "\x1b[32msearch:\x1b[0m ";
|
||||||
auto search_string = m_search_editor->get_line(search_prompt);
|
auto search_string = m_search_editor->get_line(search_prompt);
|
||||||
|
|
||||||
m_search_editor = nullptr;
|
m_search_editor = nullptr;
|
||||||
m_is_searching = false;
|
m_is_searching = false;
|
||||||
m_search_offset = 0;
|
m_search_offset = 0;
|
||||||
|
|
|
@ -167,10 +167,12 @@ private:
|
||||||
m_refresh_needed = true;
|
m_refresh_needed = true;
|
||||||
m_search_offset = 0;
|
m_search_offset = 0;
|
||||||
if (m_reset_buffer_on_search_end) {
|
if (m_reset_buffer_on_search_end) {
|
||||||
m_buffer = m_pre_search_buffer;
|
m_buffer.clear();
|
||||||
|
for (auto ch : m_pre_search_buffer)
|
||||||
|
m_buffer.append(ch);
|
||||||
m_cursor = m_pre_search_cursor;
|
m_cursor = m_pre_search_cursor;
|
||||||
}
|
}
|
||||||
m_reset_buffer_on_search_end = false;
|
m_reset_buffer_on_search_end = true;
|
||||||
m_search_editor = nullptr;
|
m_search_editor = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue