7814
Ta
tiny-c-agent / files
tiny-c-agent / src / tui / editor.h
1.2 KB
1// tiny TUI line editor: multi-line, wrapped, with word motion and completion. 2 3#ifndef TINY_TUI_EDITOR_H 4#define TINY_TUI_EDITOR_H 5 6#include <stdbool.h> 7#include <stddef.h> 8 9#include "term.h" 10 11typedef struct tiny_editor tiny_editor; 12 13tiny_editor *tiny_editor_new(void); 14void tiny_editor_free(tiny_editor *e); 15 16// The draft as one string, lines joined by newline. Owned by the editor. 17const char *tiny_editor_text(tiny_editor *e); 18 19void tiny_editor_clear(tiny_editor *e); 20void tiny_editor_set_text(tiny_editor *e, const char *text); 21 22typedef enum { 23 TINY_EDIT_NONE, 24 TINY_EDIT_CHANGED, 25 TINY_EDIT_SUBMIT, 26} tiny_edit_result; 27 28tiny_edit_result tiny_editor_handle(tiny_editor *e, const tiny_key *key); 29 30// Applies `step` to the word ending at the caret, replacing it; false when 31// there is no word before the caret. 32bool tiny_editor_complete_word(tiny_editor *e, char *(*step)(const char *word, void *user), void *user); 33 34typedef struct { 35 char **rows; 36 size_t nrows; 37 int cursor_row; 38 int cursor_col; 39} tiny_editor_view; 40 41// Clipped to `max_rows`, scrolled only as far as the caret requires. 42tiny_editor_view tiny_editor_render(tiny_editor *e, int width, int max_rows); 43 44#endif