From 4b5873002e8a31dc686c69db4fce41bf3686fd6d Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 23 Aug 2025 01:56:46 +0200 Subject: tui: Start to lay out the data structures --- src/tui-internals.h | 83 +++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 64 insertions(+), 19 deletions(-) (limited to 'src/tui-internals.h') diff --git a/src/tui-internals.h b/src/tui-internals.h index c64964e..9469b47 100644 --- a/src/tui-internals.h +++ b/src/tui-internals.h @@ -20,25 +20,69 @@ #include -typedef struct _tui { - struct termios term_old_config; - struct termios term_config; -} tui; - -typedef struct _mouse_event { - int x; - int y; -} mouse_event; - -typedef struct _scroll_event { - int x; - int y; -} scroll_event; - -typedef struct _key_event { - int key; - int modifiers; -} key_event; +typedef struct _vec2 + { + int x; + int y; + } +vec2; + +#define INPUT_BUFF_SIZE 100 + +typedef struct _tui + { + struct termios term_old_config; + struct termios term_config; + char input_buff[INPUT_BUFF_SIZE]; /* For input events */ + + /* Double buffering of the display: + * We allocate a huge array, double the size we need and realloc it when + * needed. Then the top half is for the old display status and the bottom + * half is for the incoming. Then we flip. + */ + int *display_A; + int *display_B; + vec2 display_size; + } +tui; + +typedef struct _event_mouse + { + int key; + vec2 pos; + } +event_mouse; + +typedef struct _event_scroll + { + int amount; + } +event_scroll; + +typedef struct _event_key + { + int key; + int modifiers; + } +event_key; + +typedef enum + { + EVENT_KEY, + EVENT_MOUSE, + EVENT_SCROLL + } +event_type; + +typedef struct _event { + event_type type; + union + { + event_key key; + event_mouse mouse; + event_scroll scroll; + } data; +} event; void tui_cursor_save (void); void tui_cursor_restore (void); @@ -51,6 +95,7 @@ void tui_screen_erase (void); void tui_alternate_buffer_enable (void); void tui_alternate_buffer_disable (void); void tui_input_sequence_consume (void); + tui *tui_init (void); void tui_deinit (tui *ui); void tui_loop (tui *ui); -- cgit v1.2.3