diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-08-23 01:56:46 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2025-08-23 01:56:46 +0200 |
commit | 4b5873002e8a31dc686c69db4fce41bf3686fd6d (patch) | |
tree | cbff3e841ddcce8fcbbe234f5a09cbd9e7a0fd99 /src/tui-internals.h | |
parent | 6c4d699eeb7fb385b775041ba59487666e550612 (diff) |
tui: Start to lay out the data structures
Diffstat (limited to 'src/tui-internals.h')
-rw-r--r-- | src/tui-internals.h | 83 |
1 files changed, 64 insertions, 19 deletions
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 <termios.h> -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); |