#pragma once #include #include #include #include #include #include #include #include #include class TerminalWidget : public ui::Widget { public: TerminalWidget(ui::Window* window, ui::Widget* parent); Result init(char* const* args); Result handle_key_event(const ui::KeyEventRequest& request) override; Result draw(ui::Canvas& canvas) override; void show_tree(int indent) override { os::println("%*s- TerminalWidget (%d,%d,%d,%d)", indent, "", m_rect.pos.x, m_rect.pos.y, m_rect.width, m_rect.height); } private: ui::Canvas m_terminal_canvas; Vector m_line_buffer; int m_pty; pid_t m_child_pid; struct termios m_settings; SharedPtr m_font; SharedPtr m_bold_font; OwnedPtr m_cursor_timer; bool m_cursor_activated = false; bool m_cursor_enabled = true; long m_last_cursor_tick; int m_x_position { 0 }; int m_y_position { 0 }; bool m_bold { false }; ui::Color m_foreground_color { ui::WHITE }; ui::Color m_background_color { ui::BLACK }; void tick_cursor(); Utf8StateDecoder m_decoder; Option m_escape_parser; void draw_glyph(wchar_t c, int x, int y); void erase_current_line(); void scroll(); bool should_scroll(); void next_line(); void next_char(); void prev_char(); void erase_current_char(); void draw_cursor(); bool at_end_of_screen(); bool handle_escape_sequence(wchar_t c); Result putchar(char c); bool put_code_point(wchar_t c); Result process(); };