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
Notes: sideshowbarker 2024-07-19 08:02:12 +09:00
3 changed files with 12 additions and 12 deletions

View file

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

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_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<char, 1024>& buffer() const { return m_buffer; }

View file

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