1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 20:07:35 +00:00

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.
This commit is contained in:
AnotherTest 2020-03-30 21:55:09 +04:30 committed by Andreas Kling
parent 21c4c67119
commit 5062a7d4cd
3 changed files with 12 additions and 12 deletions

View file

@ -42,14 +42,8 @@ LineEditor::LineEditor(struct termios termios)
} }
LineEditor::LineEditor() LineEditor::LineEditor()
: m_termios({}) : LineEditor(termios {})
, m_initialized(false)
{ {
struct winsize ws;
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
m_num_columns = 80;
else
m_num_columns = ws.ws_col;
} }
LineEditor::~LineEditor() LineEditor::~LineEditor()

View file

@ -70,7 +70,11 @@ public:
Function<Vector<String>(const String&)> on_tab_complete_first_token = nullptr; Function<Vector<String>(const String&)> on_tab_complete_first_token = nullptr;
Function<Vector<String>(const String&)> on_tab_complete_other_token = nullptr; Function<Vector<String>(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; } size_t cursor() const { return m_cursor; }
const Vector<char, 1024>& buffer() const { return m_buffer; } const Vector<char, 1024>& buffer() const { return m_buffer; }

View file

@ -1154,14 +1154,16 @@ int main(int argc, char** argv)
signal(SIGINT, [](int) { signal(SIGINT, [](int) {
g.was_interrupted = true; g.was_interrupted = true;
}); editor.interrupted();
signal(SIGHUP, [](int) {
save_history();
}); });
signal(SIGWINCH, [](int) { signal(SIGWINCH, [](int) {
g.was_resized = true; g.was_resized = true;
editor.resized();
});
signal(SIGHUP, [](int) {
save_history();
}); });
int rc = gethostname(g.hostname, sizeof(g.hostname)); int rc = gethostname(g.hostname, sizeof(g.hostname));