From 5062a7d4cd6293b497db88b685648c52da471221 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Mon, 30 Mar 2020 21:55:09 +0430 Subject: [PATCH] LibLinEdit + Shell: handle signals This allows the LineEditor to get notified about signals, since we cannot set signal handlers in a clean way within the LineEditor instance. --- Libraries/LibLineEdit/LineEditor.cpp | 8 +------- Libraries/LibLineEdit/LineEditor.h | 6 +++++- Shell/main.cpp | 10 ++++++---- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Libraries/LibLineEdit/LineEditor.cpp b/Libraries/LibLineEdit/LineEditor.cpp index 131216a008..e632168b21 100644 --- a/Libraries/LibLineEdit/LineEditor.cpp +++ b/Libraries/LibLineEdit/LineEditor.cpp @@ -42,14 +42,8 @@ LineEditor::LineEditor(struct termios termios) } LineEditor::LineEditor() - : m_termios({}) - , m_initialized(false) + : LineEditor(termios {}) { - struct winsize ws; - if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) - m_num_columns = 80; - else - m_num_columns = ws.ws_col; } LineEditor::~LineEditor() diff --git a/Libraries/LibLineEdit/LineEditor.h b/Libraries/LibLineEdit/LineEditor.h index 75e0e54a89..437d024e43 100644 --- a/Libraries/LibLineEdit/LineEditor.h +++ b/Libraries/LibLineEdit/LineEditor.h @@ -70,7 +70,11 @@ public: Function(const String&)> on_tab_complete_first_token = nullptr; Function(const String&)> on_tab_complete_other_token = nullptr; - // FIXME: figure out signals + + // 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 resized() { m_was_resized = true; } size_t cursor() const { return m_cursor; } const Vector& buffer() const { return m_buffer; } diff --git a/Shell/main.cpp b/Shell/main.cpp index 147cae889c..acdf9df612 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -1154,14 +1154,16 @@ int main(int argc, char** argv) signal(SIGINT, [](int) { g.was_interrupted = true; - }); - - signal(SIGHUP, [](int) { - save_history(); + editor.interrupted(); }); signal(SIGWINCH, [](int) { g.was_resized = true; + editor.resized(); + }); + + signal(SIGHUP, [](int) { + save_history(); }); int rc = gethostname(g.hostname, sizeof(g.hostname));