mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 04:28:13 +00:00
LibLine: Handle interrupts again
This commit makes LibLine handle interrupts (as reported via interrupted() and resized()) again. There is a little catch with the shell: ``` $ ls | pipe> <C-c> (prompt stays here until a key is pressed) ```
This commit is contained in:
parent
29029568ee
commit
889a8e7d0f
3 changed files with 31 additions and 15 deletions
|
@ -292,6 +292,9 @@ auto Editor::get_line(const String& prompt) -> Result<String, Editor::Error>
|
||||||
add_child(*m_notifier);
|
add_child(*m_notifier);
|
||||||
|
|
||||||
m_notifier->on_ready_to_read = [&] {
|
m_notifier->on_ready_to_read = [&] {
|
||||||
|
if (m_was_interrupted)
|
||||||
|
handle_interrupt_event();
|
||||||
|
|
||||||
handle_read_event();
|
handle_read_event();
|
||||||
|
|
||||||
if (m_always_refresh)
|
if (m_always_refresh)
|
||||||
|
@ -342,6 +345,23 @@ void Editor::save_to(JsonObject& object)
|
||||||
object.set("used_display_area", move(display_area));
|
object.set("used_display_area", move(display_area));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Editor::handle_interrupt_event()
|
||||||
|
{
|
||||||
|
m_was_interrupted = false;
|
||||||
|
|
||||||
|
if (!m_buffer.is_empty())
|
||||||
|
printf("^C");
|
||||||
|
|
||||||
|
m_buffer.clear();
|
||||||
|
m_cursor = 0;
|
||||||
|
|
||||||
|
if (on_interrupt_handled)
|
||||||
|
on_interrupt_handled();
|
||||||
|
|
||||||
|
m_refresh_needed = true;
|
||||||
|
refresh_display();
|
||||||
|
}
|
||||||
|
|
||||||
void Editor::handle_read_event()
|
void Editor::handle_read_event()
|
||||||
{
|
{
|
||||||
char keybuf[16];
|
char keybuf[16];
|
||||||
|
@ -360,18 +380,7 @@ void Editor::handle_read_event()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_was_interrupted = false;
|
handle_interrupt_event();
|
||||||
|
|
||||||
if (!m_buffer.is_empty())
|
|
||||||
printf("^C");
|
|
||||||
|
|
||||||
m_buffer.clear();
|
|
||||||
m_cursor = 0;
|
|
||||||
|
|
||||||
if (on_interrupt_handled)
|
|
||||||
on_interrupt_handled();
|
|
||||||
|
|
||||||
m_refresh_needed = true;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,10 +114,16 @@ public:
|
||||||
// since we can not do this cleanly ourselves. (signal() limitation: cannot give member functions)
|
// since we can not do this cleanly ourselves. (signal() limitation: cannot give member functions)
|
||||||
void interrupted()
|
void interrupted()
|
||||||
{
|
{
|
||||||
if (m_is_editing)
|
if (m_is_editing) {
|
||||||
m_was_interrupted = true;
|
m_was_interrupted = true;
|
||||||
|
handle_interrupt_event();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void resized()
|
||||||
|
{
|
||||||
|
m_was_resized = true;
|
||||||
|
refresh_display();
|
||||||
}
|
}
|
||||||
void resized() { m_was_resized = true; }
|
|
||||||
|
|
||||||
size_t cursor() const { return m_cursor; }
|
size_t cursor() const { return m_cursor; }
|
||||||
const Vector<u32, 1024>& buffer() const { return m_buffer; }
|
const Vector<u32, 1024>& buffer() const { return m_buffer; }
|
||||||
|
@ -176,6 +182,7 @@ private:
|
||||||
Function<bool(Editor&)> callback;
|
Function<bool(Editor&)> callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void handle_interrupt_event();
|
||||||
void handle_read_event();
|
void handle_read_event();
|
||||||
|
|
||||||
Vector<size_t, 2> vt_dsr();
|
Vector<size_t, 2> vt_dsr();
|
||||||
|
|
|
@ -133,7 +133,7 @@ int main(int argc, char** argv)
|
||||||
}
|
}
|
||||||
|
|
||||||
editor->on_interrupt_handled = [&] {
|
editor->on_interrupt_handled = [&] {
|
||||||
if (!shell->should_read_more()) {
|
if (shell->should_read_more()) {
|
||||||
shell->finish_command();
|
shell->finish_command();
|
||||||
editor->finish();
|
editor->finish();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue