From f90d5e1f07fdc9dea7c24b11107049b613a5be7a Mon Sep 17 00:00:00 2001 From: Albert Cervin Date: Sun, 29 Jan 2023 22:22:54 +0100 Subject: More tests and documentation Also improve find file and switch buffer a bit. Implement word backward/forward. --- src/display.c | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) (limited to 'src/display.c') diff --git a/src/display.c b/src/display.c index de99e36..2f147d5 100644 --- a/src/display.c +++ b/src/display.c @@ -8,10 +8,18 @@ #include #include #include +#include #include #define ESC 0x1b +struct display { + struct termios term; + struct termios orig_term; + uint32_t width; + uint32_t height; +}; + enum render_cmd_type { RenderCommand_DrawText = 0, RenderCommand_PushFormat = 1, @@ -62,7 +70,7 @@ struct command_list { uint32_t xoffset; uint32_t yoffset; - alloc_fn allocator; + void *(*allocator)(size_t); char name[16]; }; @@ -73,7 +81,7 @@ struct winsize getsize() { return ws; } -struct display display_create() { +struct display *display_create() { struct winsize ws = getsize(); @@ -87,12 +95,12 @@ struct display display_create() { tcsetattr(0, TCSADRAIN, &term); - return (struct display){ - .orig_term = orig_term, - .term = term, - .height = ws.ws_row, - .width = ws.ws_col, - }; + struct display *d = calloc(1, sizeof(struct display)); + d->orig_term = orig_term; + d->term = term; + d->height = ws.ws_row; + d->width = ws.ws_col; + return d; } void display_resize(struct display *display) { @@ -104,8 +112,13 @@ void display_resize(struct display *display) { void display_destroy(struct display *display) { // reset old terminal mode tcsetattr(0, TCSADRAIN, &display->orig_term); + + free(display); } +uint32_t display_width(struct display *display) { return display->width; } +uint32_t display_height(struct display *display) { return display->height; } + void putbyte(uint8_t c) { if (c != '\r') { putc(c, stdout); @@ -156,7 +169,8 @@ void display_clear(struct display *display) { putbytes(bytes, 3, false); } -struct command_list *command_list_create(uint32_t capacity, alloc_fn allocator, +struct command_list *command_list_create(uint32_t capacity, + void *(*allocator)(size_t), uint32_t xoffset, uint32_t yoffset, const char *name) { struct command_list *command_list = allocator(sizeof(struct command_list)); @@ -176,7 +190,10 @@ struct command_list *command_list_create(uint32_t capacity, alloc_fn allocator, struct render_command *add_command(struct command_list *list, enum render_cmd_type tp) { if (list->ncmds == list->capacity) { - // TODO: better + /* TODO: better. Currently a bit tricky to provide dynamic scaling of this + * since it is initially allocated with the frame allocator that does not + * support realloc. + */ return NULL; } -- cgit v1.2.3