diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-02-11 15:07:05 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-02-11 15:07:05 +0100 |
commit | c75ecaae322910e0100cce90a26a47538710219d (patch) | |
tree | e5c44ef672a43d760b4ce52761438eaafa7c530f /Applications/Terminal | |
parent | 3351f1ccc1bcc169b680ff2f4e335a1296a47d67 (diff) | |
download | serenity-c75ecaae322910e0100cce90a26a47538710219d.zip |
Terminal: Move the notifier into the Terminal class.
Diffstat (limited to 'Applications/Terminal')
-rw-r--r-- | Applications/Terminal/Terminal.cpp | 31 | ||||
-rw-r--r-- | Applications/Terminal/Terminal.h | 3 | ||||
-rw-r--r-- | Applications/Terminal/main.cpp | 23 |
3 files changed, 30 insertions, 27 deletions
diff --git a/Applications/Terminal/Terminal.cpp b/Applications/Terminal/Terminal.cpp index d62d258741..3f68b193b8 100644 --- a/Applications/Terminal/Terminal.cpp +++ b/Applications/Terminal/Terminal.cpp @@ -1,13 +1,16 @@ #include "Terminal.h" #include "XtermColors.h" +#include <string.h> +#include <errno.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdio.h> #include <AK/AKString.h> #include <AK/StringBuilder.h> #include <SharedGraphics/Font.h> #include <SharedGraphics/Painter.h> #include <AK/StdLibExtras.h> -#include <LibC/stdlib.h> -#include <LibC/unistd.h> -#include <LibC/stdio.h> +#include <LibGUI/GApplication.h> #include <LibGUI/GWindow.h> #include <Kernel/KeyCode.h> @@ -16,7 +19,27 @@ Terminal::Terminal(int ptm_fd) : m_ptm_fd(ptm_fd) , m_font(Font::default_font()) -{ + , m_notifier(ptm_fd, GNotifier::Read) +{ + m_notifier.on_ready_to_read = [this] (GNotifier& notifier) { + byte buffer[BUFSIZ]; + ssize_t nread = read(notifier.fd(), buffer, sizeof(buffer)); + if (nread < 0) { + dbgprintf("Terminal read error: %s\n", strerror(errno)); + perror("read(ptm)"); + GApplication::the().exit(1); + return; + } + if (nread == 0) { + dbgprintf("Terminal: EOF on master pty, closing.\n"); + GApplication::the().exit(0); + return; + } + for (ssize_t i = 0; i < nread; ++i) + on_char(buffer[i]); + flush_dirty_lines(); + }; + set_fill_with_background_color(false); m_line_height = font().glyph_height() + m_line_spacing; diff --git a/Applications/Terminal/Terminal.h b/Applications/Terminal/Terminal.h index 64642104a4..a3a4ac018e 100644 --- a/Applications/Terminal/Terminal.h +++ b/Applications/Terminal/Terminal.h @@ -6,6 +6,7 @@ #include <SharedGraphics/GraphicsBitmap.h> #include <SharedGraphics/Rect.h> #include <LibGUI/GWidget.h> +#include <LibGUI/GNotifier.h> class Font; @@ -140,4 +141,6 @@ private: bool m_need_full_flush { false }; RetainPtr<Font> m_font; + + GNotifier m_notifier; }; diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp index 215295efae..3faa510d15 100644 --- a/Applications/Terminal/main.cpp +++ b/Applications/Terminal/main.cpp @@ -11,7 +11,6 @@ #include "Terminal.h" #include <Kernel/KeyCode.h> #include <LibGUI/GApplication.h> -#include <LibGUI/GNotifier.h> #include <LibGUI/GWidget.h> #include <LibGUI/GWindow.h> @@ -70,29 +69,7 @@ int main(int argc, char** argv) Terminal terminal(ptm_fd); window->set_main_widget(&terminal); - window->move_to(300, 300); - - GNotifier ptm_notifier(ptm_fd, GNotifier::Read); - ptm_notifier.on_ready_to_read = [&terminal] (GNotifier& notifier) { - byte buffer[BUFSIZ]; - ssize_t nread = read(notifier.fd(), buffer, sizeof(buffer)); - if (nread < 0) { - dbgprintf("Terminal read error: %s\n", strerror(errno)); - perror("read(ptm)"); - GApplication::the().exit(1); - return; - } - if (nread == 0) { - dbgprintf("Terminal: EOF on master pty, closing.\n"); - GApplication::the().exit(0); - return; - } - for (ssize_t i = 0; i < nread; ++i) - terminal.on_char(buffer[i]); - terminal.flush_dirty_lines(); - }; - window->show(); return app.exec(); |