mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 04:17:34 +00:00
Terminal: Move the notifier into the Terminal class.
This commit is contained in:
parent
3351f1ccc1
commit
c75ecaae32
3 changed files with 29 additions and 26 deletions
|
@ -1,13 +1,16 @@
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
#include "XtermColors.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/AKString.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <SharedGraphics/Font.h>
|
#include <SharedGraphics/Font.h>
|
||||||
#include <SharedGraphics/Painter.h>
|
#include <SharedGraphics/Painter.h>
|
||||||
#include <AK/StdLibExtras.h>
|
#include <AK/StdLibExtras.h>
|
||||||
#include <LibC/stdlib.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibC/unistd.h>
|
|
||||||
#include <LibC/stdio.h>
|
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
|
|
||||||
|
@ -16,7 +19,27 @@
|
||||||
Terminal::Terminal(int ptm_fd)
|
Terminal::Terminal(int ptm_fd)
|
||||||
: m_ptm_fd(ptm_fd)
|
: m_ptm_fd(ptm_fd)
|
||||||
, m_font(Font::default_font())
|
, 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);
|
set_fill_with_background_color(false);
|
||||||
|
|
||||||
m_line_height = font().glyph_height() + m_line_spacing;
|
m_line_height = font().glyph_height() + m_line_spacing;
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
#include <SharedGraphics/GraphicsBitmap.h>
|
#include <SharedGraphics/GraphicsBitmap.h>
|
||||||
#include <SharedGraphics/Rect.h>
|
#include <SharedGraphics/Rect.h>
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
|
#include <LibGUI/GNotifier.h>
|
||||||
|
|
||||||
class Font;
|
class Font;
|
||||||
|
|
||||||
|
@ -140,4 +141,6 @@ private:
|
||||||
bool m_need_full_flush { false };
|
bool m_need_full_flush { false };
|
||||||
|
|
||||||
RetainPtr<Font> m_font;
|
RetainPtr<Font> m_font;
|
||||||
|
|
||||||
|
GNotifier m_notifier;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,7 +11,6 @@
|
||||||
#include "Terminal.h"
|
#include "Terminal.h"
|
||||||
#include <Kernel/KeyCode.h>
|
#include <Kernel/KeyCode.h>
|
||||||
#include <LibGUI/GApplication.h>
|
#include <LibGUI/GApplication.h>
|
||||||
#include <LibGUI/GNotifier.h>
|
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
#include <LibGUI/GWindow.h>
|
#include <LibGUI/GWindow.h>
|
||||||
|
|
||||||
|
@ -70,29 +69,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
Terminal terminal(ptm_fd);
|
Terminal terminal(ptm_fd);
|
||||||
window->set_main_widget(&terminal);
|
window->set_main_widget(&terminal);
|
||||||
|
|
||||||
window->move_to(300, 300);
|
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();
|
window->show();
|
||||||
|
|
||||||
return app.exec();
|
return app.exec();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue