Skip to content

Commit

Permalink
LibLine: Handle interrupts/window size changes internally
Browse files Browse the repository at this point in the history
  • Loading branch information
alimpfard authored and awesomekling committed Aug 21, 2020
1 parent 238e87d commit 30554c9
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
9 changes: 9 additions & 0 deletions Libraries/LibLine/Editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 0 additions & 3 deletions Libraries/LibLine/Editor.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,6 @@ class Editor : public Core::Object {

#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()
{
Expand Down Expand Up @@ -451,7 +449,6 @@ class Editor : public Core::Object {

HashMap<Key, NonnullOwnPtr<KeyCallback>> m_key_callbacks;

// TODO: handle signals internally.
struct termios m_termios {
};
struct termios m_default_termios {
Expand Down
2 changes: 0 additions & 2 deletions Shell/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down
5 changes: 0 additions & 5 deletions Userland/js.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 30554c9

Please sign in to comment.