#pragma once #include #include #include #include #include #include #include class TerminalWidget : public ui::Widget { public: Result init(char* const* args); Result handle_key_event(const ui::KeyEventRequest& request) override; Result draw(ui::Canvas& canvas) override; Result process(); void quit(); 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; static constexpr int CURSOR_TIMEOUT = 500; int m_current_cursor_timeout = CURSOR_TIMEOUT; 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 query_termios(); bool 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); void put_code_point(wchar_t c); };