mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 13:05:12 +00:00
Terminal: Move the notifier into the Terminal class.
This commit is contained in:
parent
3351f1ccc1
commit
c75ecaae32
Notes:
sideshowbarker
2024-07-19 15:47:04 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/c75ecaae322
3 changed files with 29 additions and 26 deletions
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Reference in a new issue