diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/dged/buffer_view.c | 14 | ||||
| -rw-r--r-- | src/dged/display.c | 23 | ||||
| -rw-r--r-- | src/dged/display.h | 3 | ||||
| -rw-r--r-- | src/dged/window.c | 14 |
4 files changed, 37 insertions, 17 deletions
diff --git a/src/dged/buffer_view.c b/src/dged/buffer_view.c index 0c587a6..29ce307 100644 --- a/src/dged/buffer_view.c +++ b/src/dged/buffer_view.c @@ -3,6 +3,7 @@ #include "buffer.h" #include "buffer_view.h" #include "display.h" +#include "settings.h" #include "timers.h" #include "utf8.h" @@ -458,9 +459,20 @@ void buffer_view_update(struct buffer_view *view, // render buffer struct timer *render_buffer_timer = timer_start("update-windows.buffer-render"); + + struct setting *tw = lang_setting(&view->buffer->lang, "tab-width"); + if (tw == NULL) { + tw = settings_get("editor.tab-width"); + } + + uint32_t tab_width = 4; + if (tw != NULL && tw->value.type == Setting_Number) { + tab_width = tw->value.data.number_value; + } + struct command_list *buf_cmds = command_list_create( width * height, params->frame_alloc, params->window_x + linum_width, - params->window_y, view->buffer->name); + params->window_y, tab_width, view->buffer->name); struct buffer_render_params render_params = { .commands = buf_cmds, .origin = view->scroll, diff --git a/src/dged/display.c b/src/dged/display.c index 0c3c47c..e39391b 100644 --- a/src/dged/display.c +++ b/src/dged/display.c @@ -80,6 +80,8 @@ struct command_list { uint32_t xoffset; uint32_t yoffset; + uint32_t tab_width; + void *(*allocator)(size_t); char name[16]; @@ -149,10 +151,10 @@ static void apply_fmt(uint8_t *fmt_stack, uint32_t fmt_stack_len) { } void putch_ws(uint8_t c, bool show_whitespace, uint8_t *fmt_stack, - uint32_t fmt_stack_len) { - // TODO: tab width needs to be sent here + uint32_t fmt_stack_len, uint32_t tab_width) { if (show_whitespace && c == '\t') { - fputs("\x1b[90m → \x1b[39m", stdout); + fprintf(stdout, "\x1b[90m→%*s\x1b[39m", tab_width > 0 ? tab_width - 1 : 0, + ""); apply_fmt(fmt_stack, fmt_stack_len); } else if (show_whitespace && c == ' ') { fputs("\x1b[90m·\x1b[39m", stdout); @@ -163,9 +165,10 @@ void putch_ws(uint8_t c, bool show_whitespace, uint8_t *fmt_stack, } void putbytes(uint8_t *line_bytes, uint32_t line_length, bool show_whitespace, - uint8_t *fmt_stack, uint32_t fmt_stack_len) { + uint8_t *fmt_stack, uint32_t fmt_stack_len, uint32_t tab_width) { for (uint32_t bytei = 0; bytei < line_length; ++bytei) { - putch_ws(line_bytes[bytei], show_whitespace, fmt_stack, fmt_stack_len); + putch_ws(line_bytes[bytei], show_whitespace, fmt_stack, fmt_stack_len, + tab_width); } } @@ -202,7 +205,7 @@ void display_clear(struct display *display) { struct command_list *command_list_create(uint32_t initial_capacity, void *(*allocator)(size_t), uint32_t xoffset, uint32_t yoffset, - const char *name) { + uint32_t tab_width, const char *name) { struct command_list *command_list = allocator(sizeof(struct command_list)); command_list->capacity = initial_capacity; @@ -210,6 +213,7 @@ struct command_list *command_list_create(uint32_t initial_capacity, command_list->xoffset = xoffset; command_list->yoffset = yoffset; command_list->next_list = NULL; + command_list->tab_width = tab_width; strncpy(command_list->name, name, 15); command_list->cmds = @@ -232,7 +236,7 @@ struct render_command *add_command(struct command_list *list, if (l->ncmds == l->capacity && n == NULL) { l->next_list = command_list_create(l->capacity, l->allocator, l->xoffset, - l->yoffset, l->name); + l->yoffset, l->tab_width, l->name); l = l->next_list; } @@ -380,7 +384,7 @@ void display_render(struct display *display, txt_cmd->col + cl->xoffset); apply_fmt(fmt_stack, fmt_stack_len); putbytes(txt_cmd->data, txt_cmd->len, show_whitespace_state, fmt_stack, - fmt_stack_len); + fmt_stack_len, cl->tab_width); break; } @@ -395,7 +399,8 @@ void display_render(struct display *display, if (codepoint != NULL) { for (uint32_t i = 0; i < repeat_cmd->nrepeat; ++i) { putbytes((uint8_t *)&repeat_cmd->c, codepoint->nbytes, - show_whitespace_state, fmt_stack, fmt_stack_len); + show_whitespace_state, fmt_stack, fmt_stack_len, + cl->tab_width); } } break; diff --git a/src/dged/display.h b/src/dged/display.h index 950ab3c..cfa2eca 100644 --- a/src/dged/display.h +++ b/src/dged/display.h @@ -103,12 +103,13 @@ void display_end_render(struct display *display); * @param xoffset Column offset to apply to all operations in the list. * @param yoffset Row offset to apply to all operations in the list. * @param name Name for the command list. Useful for debugging. + * @param tab_width Number of characters to use for displaying tabs. * @returns A pointer to the created command list. */ struct command_list *command_list_create(uint32_t capacity, void *(*allocator)(size_t), uint32_t xoffset, uint32_t yoffset, - const char *name); + uint32_t tab_width, const char *name); /** * Enable/disable rendering of whitespace characters. diff --git a/src/dged/window.c b/src/dged/window.c index 93a5c48..cad3c7e 100644 --- a/src/dged/window.c +++ b/src/dged/window.c @@ -200,7 +200,8 @@ void windows_update(void *(*frame_alloc)(size_t), float frame_time) { struct window *w = &g_minibuffer_window; w->x = 0; - w->commands = command_list_create(10, frame_alloc, w->x, w->y, "mb-prompt"); + w->commands = + command_list_create(10, frame_alloc, w->x, w->y, 4, "mb-prompt"); // draw the prompt here to make it off-limits for the buffer/buffer view uint32_t prompt_len = minibuffer_draw_prompt(w->commands); @@ -208,7 +209,7 @@ void windows_update(void *(*frame_alloc)(size_t), float frame_time) { uint32_t width = prompt_len < w->width ? w->width - prompt_len : 1; struct command_list *inner_commands = command_list_create( - w->height * width, frame_alloc, w->x, w->y, "bufview-mb"); + w->height * width, frame_alloc, w->x, w->y, 4, "bufview-mb"); struct buffer_view_update_params p = { .commands = inner_commands, @@ -260,7 +261,7 @@ void windows_update(void *(*frame_alloc)(size_t), float frame_time) { width += border_width * 2; } - w->commands = command_list_create(height * width, frame_alloc, w_x, w_y, + w->commands = command_list_create(height * width, frame_alloc, w_x, w_y, 4, "popup-decor"); uint32_t x = 0, y = 0; if (draw_borders) { @@ -299,8 +300,9 @@ void windows_update(void *(*frame_alloc)(size_t), float frame_time) { x += border_width; } - struct command_list *inner = command_list_create( - w->height * w->width, frame_alloc, w_x + x, w_y + y, "bufview-popup"); + struct command_list *inner = + command_list_create(w->height * w->width, frame_alloc, w_x + x, w_y + y, + 4, "bufview-popup"); struct buffer_view_update_params p = { .commands = inner, @@ -326,7 +328,7 @@ void windows_update(void *(*frame_alloc)(size_t), float frame_time) { char name[16] = {0}; snprintf(name, 15, "bufview-%s", w->buffer_view.buffer->name); w->commands = command_list_create(w->height * w->width, frame_alloc, w->x, - w->y, name); + w->y, 4, name); struct buffer_view_update_params p = { .commands = w->commands, |
