diff options
| author | Albert Cervin <albert@acervin.com> | 2022-11-02 22:20:04 +0100 |
|---|---|---|
| committer | Albert Cervin <albert@acervin.com> | 2022-11-16 23:33:49 +0100 |
| commit | 2f4cb88d5c60f725323739300bb49dfa8923e7d5 (patch) | |
| tree | 6ec22c2be92eff05f18e5919e747faab56e555ad /src/text.h | |
| download | dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.gz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.tar.xz dged-2f4cb88d5c60f725323739300bb49dfa8923e7d5.zip | |
🎉 And so it begins
Diffstat (limited to 'src/text.h')
| -rw-r--r-- | src/text.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/text.h b/src/text.h new file mode 100644 index 0000000..21de899 --- /dev/null +++ b/src/text.h @@ -0,0 +1,39 @@ +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> + +// opaque so it is easier to change representation to gap, rope etc. +struct text; + +struct render_cmd; + +struct text *text_create(uint32_t initial_capacity); +void text_destroy(struct text *text); + +void text_append(struct text *text, uint32_t line, uint32_t col, uint8_t *bytes, + uint32_t nbytes, uint32_t *lines_added, uint32_t *cols_added); + +void text_delete(struct text *text, uint32_t line, uint32_t col, + uint32_t nchars); +void text_delete_line(struct text *text, uint32_t line); + +uint32_t text_render(struct text *text, uint32_t line, uint32_t nlines, + struct render_cmd *cmds, uint32_t max_ncmds); + +uint32_t text_num_lines(struct text *text); +uint32_t text_line_length(struct text *text, uint32_t lineidx); +uint32_t text_line_size(struct text *text, uint32_t lineidx); + +struct txt_line { + uint8_t *text; + uint32_t nbytes; + uint32_t nchars; +}; + +typedef void (*line_cb)(struct txt_line *line); +void text_for_each_line(struct text *text, uint32_t line, uint32_t nlines, + line_cb callback); + +struct txt_line text_get_line(struct text *text, uint32_t line); + +bool text_line_contains_unicode(struct text *text, uint32_t line); |
