terminal: Draw directly onto the window canvas

This commit is contained in:
apio 2023-09-16 13:29:22 +02:00
parent ea3907d012
commit 18e3265d14
Signed by: apio
GPG Key ID: B8A7D06E42258954
3 changed files with 8 additions and 12 deletions

View File

@ -46,10 +46,8 @@ Result<void> TerminalWidget::init(char* const* args)
m_font = ui::Font::default_font();
m_bold_font = ui::Font::default_bold_font();
m_terminal_canvas = ui::Canvas { .width = m_rect.width,
.height = m_rect.height,
.stride = m_rect.width,
.ptr = (u8*)TRY(calloc_impl(m_rect.width, m_rect.height * sizeof(u32), false)) };
m_terminal_canvas = ui::App::the().main_window()->canvas();
m_terminal_canvas.fill(ui::BLACK);
signal(SIGCHLD, sigchld_handler);
@ -213,13 +211,12 @@ Result<ui::EventResult> TerminalWidget::handle_key_event(const ui::KeyEventReque
return ui::EventResult::DidHandle;
}
Result<void> TerminalWidget::draw(ui::Canvas& canvas)
Result<void> TerminalWidget::draw(ui::Canvas&)
{
canvas.fill((u32*)m_terminal_canvas.ptr, m_terminal_canvas.stride);
return {};
}
Result<void> TerminalWidget::process()
Result<bool> TerminalWidget::process()
{
char buffer[BUFSIZ];
ssize_t nread = read(m_pty, buffer, BUFSIZ);
@ -238,7 +235,7 @@ Result<void> TerminalWidget::process()
if (should_update_cursor || nread > 0) ui::App::the().main_window()->draw();
return {};
return nread == 0;
}
bool TerminalWidget::tick_cursor()

View File

@ -16,7 +16,7 @@ class TerminalWidget : public ui::Widget
Result<void> draw(ui::Canvas& canvas) override;
Result<void> process();
Result<bool> process();
void quit();

View File

@ -11,7 +11,6 @@ Result<int> luna_main(int argc, char** argv)
auto* window = TRY(ui::Window::create(ui::Rect { 150, 150, 640, 400 }));
app.set_main_window(window);
window->set_background(ui::BLACK);
window->set_title("Terminal");
TerminalWidget terminal;
@ -24,8 +23,8 @@ Result<int> luna_main(int argc, char** argv)
while (app.process_events())
{
TRY(terminal.process());
usleep(10000);
bool should_sleep = TRY(terminal.process());
if (should_sleep) usleep(10000);
}
terminal.quit();