From 30554c969c3f42fdb95b2b2c55cd00aaf314c4b3 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Thu, 20 Aug 2020 20:09:48 +0430 Subject: [PATCH] LibLine: Handle interrupts/window size changes internally --- Libraries/LibLine/Editor.cpp | 9 +++++++++ Libraries/LibLine/Editor.h | 3 --- Shell/main.cpp | 2 -- Userland/js.cpp | 5 ----- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Libraries/LibLine/Editor.cpp b/Libraries/LibLine/Editor.cpp index 61508f6fe08..458f08d30d9 100644 --- a/Libraries/LibLine/Editor.cpp +++ b/Libraries/LibLine/Editor.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -404,6 +405,14 @@ void Editor::initialize() for (auto& keybind : m_configuration.keybindings) register_key_input_callback(keybind); + Core::EventLoop::register_signal(SIGINT, [this](int) { + interrupted(); + }); + + Core::EventLoop::register_signal(SIGWINCH, [this](int) { + resized(); + }); + m_initialized = true; } diff --git a/Libraries/LibLine/Editor.h b/Libraries/LibLine/Editor.h index 01640777ddf..2774ab39012 100644 --- a/Libraries/LibLine/Editor.h +++ b/Libraries/LibLine/Editor.h @@ -194,8 +194,6 @@ public: #undef __ENUMERATE_EDITOR_INTERNAL_FUNCTION - // 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(); void resized() { @@ -451,7 +449,6 @@ private: HashMap> m_key_callbacks; - // TODO: handle signals internally. struct termios m_termios { }; struct termios m_default_termios { diff --git a/Shell/main.cpp b/Shell/main.cpp index a3fdf5e6a27..4786c088bd9 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -93,12 +93,10 @@ int main(int argc, char** argv) Core::EventLoop loop; Core::EventLoop::register_signal(SIGINT, [](int) { - editor->interrupted(); s_shell->kill_job(s_shell->current_job(), SIGINT); }); Core::EventLoop::register_signal(SIGWINCH, [](int) { - editor->resized(); s_shell->kill_job(s_shell->current_job(), SIGWINCH); }); diff --git a/Userland/js.cpp b/Userland/js.cpp index 66298b07da2..f08b336184e 100644 --- a/Userland/js.cpp +++ b/Userland/js.cpp @@ -572,11 +572,6 @@ int main(int argc, char** argv) signal(SIGINT, [](int) { if (!s_editor->is_editing()) sigint_handler(); - s_editor->interrupted(); - }); - - signal(SIGWINCH, [](int) { - s_editor->resized(); }); s_editor->on_display_refresh = [syntax_highlight](Line::Editor& editor) {