1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-06-30 10:32:17 +00:00

LibLine: Use Core::EventLoop for outer read loop

This commit changes LibLine's internal structure to work in an event
loop, and as a result, also switches it to being a Core::Object.
This commit is contained in:
AnotherTest 2020-05-26 15:04:39 +04:30 committed by Andreas Kling
parent 8e6df3949d
commit 70a213a6ec
7 changed files with 583 additions and 517 deletions

View file

@ -35,7 +35,7 @@
#include <string.h>
#include <sys/wait.h>
Line::Editor editor { Line::Configuration { Line::Configuration::UnescapedSpaces } };
RefPtr<Line::Editor> editor;
Shell* s_shell;
void FileDescriptionCollector::collect()
@ -58,13 +58,13 @@ void FileDescriptionCollector::add(int fd)
int main(int argc, char** argv)
{
Core::EventLoop loop;
signal(SIGINT, [](int) {
editor.interrupted();
editor->interrupted();
});
signal(SIGWINCH, [](int) {
editor.resized();
editor->resized();
});
signal(SIGHUP, [](int) {
@ -92,18 +92,20 @@ int main(int argc, char** argv)
return 1;
}
editor = Line::Editor::construct(Line::Configuration { Line::Configuration::UnescapedSpaces });
auto shell = Shell::construct();
s_shell = shell.ptr();
editor.initialize();
shell->termios = editor.termios();
shell->default_termios = editor.default_termios();
editor->initialize();
shell->termios = editor->termios();
shell->default_termios = editor->default_termios();
editor.on_display_refresh = [&](auto& editor) {
editor->on_display_refresh = [&](auto& editor) {
editor.strip_styles();
shell->highlight(editor);
};
editor.on_tab_complete = [&](const Line::Editor& editor) {
editor->on_tab_complete = [&](const Line::Editor& editor) {
return shell->complete(editor);
};
@ -128,13 +130,15 @@ int main(int argc, char** argv)
return 0;
}
editor.on_interrupt_handled = [&] {
editor->on_interrupt_handled = [&] {
if (!shell->should_read_more()) {
shell->finish_command();
editor.finish();
editor->finish();
}
};
shell->add_child(*editor);
Core::EventLoop::current().post_event(*shell, make<Core::CustomEvent>(Shell::ShellEventType::ReadLine));
return loop.exec();