mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-14 01:04:38 +03:00
LibLine: Ignore interrupts unless actively editing
It does not make much sense to receive an interrupt and process it *much later*. Also patches Userland/js to only create exceptions while some code is actually running.
This commit is contained in:
parent
8b195d1211
commit
7ecf29f206
Notes:
sideshowbarker
2024-07-19 07:12:33 +09:00
Author: https://github.com/alimpfard Commit: https://github.com/SerenityOS/serenity/commit/7ecf29f206e Pull-request: https://github.com/SerenityOS/serenity/pull/2009 Issue: https://github.com/SerenityOS/serenity/issues/2008
@ -124,6 +124,8 @@ void Editor::stylize(const Span& span, const Style& style)
|
||||
|
||||
String Editor::get_line(const String& prompt)
|
||||
{
|
||||
m_is_editing = true;
|
||||
|
||||
set_prompt(prompt);
|
||||
reset();
|
||||
set_origin();
|
||||
@ -139,6 +141,7 @@ String Editor::get_line(const String& prompt)
|
||||
fflush(stdout);
|
||||
auto string = String::copy(m_buffer);
|
||||
m_buffer.clear();
|
||||
m_is_editing = false;
|
||||
return string;
|
||||
}
|
||||
char keybuf[16];
|
||||
|
@ -107,7 +107,11 @@ public:
|
||||
|
||||
// FIXME: we will have to kindly ask our instantiators to set our signal handlers
|
||||
// since we can not do this cleanly ourselves (signal() limitation: cannot give member functions)
|
||||
void interrupted() { m_was_interrupted = true; }
|
||||
void interrupted()
|
||||
{
|
||||
if (m_is_editing)
|
||||
m_was_interrupted = true;
|
||||
}
|
||||
void resized() { m_was_resized = true; }
|
||||
|
||||
size_t cursor() const { return m_cursor; }
|
||||
@ -148,6 +152,8 @@ public:
|
||||
m_finish = true;
|
||||
}
|
||||
|
||||
bool is_editing() const { return m_is_editing; }
|
||||
|
||||
private:
|
||||
void vt_save_cursor();
|
||||
void vt_restore_cursor();
|
||||
@ -291,6 +297,8 @@ private:
|
||||
|
||||
bool m_initialized { false };
|
||||
bool m_refresh_needed { false };
|
||||
|
||||
bool m_is_editing { false };
|
||||
};
|
||||
|
||||
}
|
||||
|
@ -421,7 +421,8 @@ int main(int argc, char** argv)
|
||||
s_editor = make<Line::Editor>();
|
||||
|
||||
signal(SIGINT, [](int) {
|
||||
sigint_handler();
|
||||
if (!s_editor->is_editing())
|
||||
sigint_handler();
|
||||
s_editor->interrupted();
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user