LibLine: Handle interrupts/window size changes internally

This commit is contained in:
AnotherTest 2020-08-20 20:09:48 +04:30 committed by Andreas Kling
parent 238e87de4e
commit 30554c969c
Notes: sideshowbarker 2024-07-19 03:21:24 +09:00
4 changed files with 9 additions and 10 deletions

View file

@ -35,6 +35,7 @@
#include <LibCore/EventLoop.h>
#include <LibCore/Notifier.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <sys/select.h>
@ -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;
}

View file

@ -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<Key, NonnullOwnPtr<KeyCallback>> m_key_callbacks;
// TODO: handle signals internally.
struct termios m_termios {
};
struct termios m_default_termios {

View file

@ -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);
});

View file

@ -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) {