diff options
| -rw-r--r-- | ui-terminal.c | 145 | ||||
| -rw-r--r-- | ui.h | 39 | ||||
| -rw-r--r-- | view.c | 34 | ||||
| -rw-r--r-- | view.h | 7 | ||||
| -rw-r--r-- | vis-cmds.c | 24 | ||||
| -rw-r--r-- | vis-core.h | 10 | ||||
| -rw-r--r-- | vis-lua.c | 48 | ||||
| -rw-r--r-- | vis-prompt.c | 2 | ||||
| -rw-r--r-- | vis.c | 35 |
9 files changed, 152 insertions, 192 deletions
diff --git a/ui-terminal.c b/ui-terminal.c index d540308..6e78d32 100644 --- a/ui-terminal.c +++ b/ui-terminal.c @@ -53,16 +53,16 @@ static void ui_die_msg(Ui *ui, const char *msg, ...) { va_end(ap); } -static void ui_window_resize(UiWin *win, int width, int height) { - debug("ui-win-resize[%s]: %dx%d\n", win->win->file->name ? win->win->file->name : "noname", width, height); +static void ui_window_resize(Win *win, int width, int height) { + debug("ui-win-resize[%s]: %dx%d\n", win->file->name ? win->file->name : "noname", width, height); bool status = win->options & UI_OPTION_STATUSBAR; - win->width = width; + win->width = width; win->height = height; - view_resize(&win->win->view, width - win->sidebar_width, status ? height - 1 : height); + view_resize(&win->view, width - win->sidebar_width, status ? height - 1 : height); } -static void ui_window_move(UiWin *win, int x, int y) { - debug("ui-win-move[%s]: (%d, %d)\n", win->win->file->name ? win->win->file->name : "noname", x, y); +static void ui_window_move(Win *win, int x, int y) { + debug("ui-win-move[%s]: (%d, %d)\n", win->file->name ? win->file->name : "noname", x, y); win->x = x; win->y = y; } @@ -115,8 +115,8 @@ static bool color_fromstring(Ui *ui, CellColor *color, const char *s) return false; } -bool ui_style_define(UiWin *win, int id, const char *style) { - Ui *tui = win->ui; +bool ui_style_define(Win *win, int id, const char *style) { + Ui *tui = &win->vis->ui; if (id >= UI_STYLE_MAX) return false; if (!style) @@ -157,9 +157,9 @@ bool ui_style_define(UiWin *win, int id, const char *style) { } else if (!strcasecmp(option, "notblink")) { cell_style.attr &= ~CELL_ATTR_BLINK; } else if (!strcasecmp(option, "fore")) { - color_fromstring(win->ui, &cell_style.fg, value); + color_fromstring(&win->vis->ui, &cell_style.fg, value); } else if (!strcasecmp(option, "back")) { - color_fromstring(win->ui, &cell_style.bg, value); + color_fromstring(&win->vis->ui, &cell_style.bg, value); } option = next; } @@ -181,7 +181,7 @@ static void ui_draw_line(Ui *tui, int x, int y, char c, enum UiStyle style_id) { } } -static void ui_draw_string(Ui *tui, int x, int y, const char *str, UiWin *win, enum UiStyle style_id) { +static void ui_draw_string(Ui *tui, int x, int y, const char *str, Win *win, enum UiStyle style_id) { debug("draw-string: [%d][%d]\n", y, x); if (x < 0 || x >= tui->width || y < 0 || y >= tui->height) return; @@ -202,25 +202,26 @@ static void ui_draw_string(Ui *tui, int x, int y, const char *str, UiWin *win, e } } -static void ui_window_draw(UiWin *win) { - Ui *ui = win->ui; - View *view = &win->win->view; - int width = win->width, height = win->height; - const Line *line = view->topline; - bool status = win->options & UI_OPTION_STATUSBAR; - bool nu = win->options & UI_OPTION_LINE_NUMBERS_ABSOLUTE; - bool rnu = win->options & UI_OPTION_LINE_NUMBERS_RELATIVE; +static void ui_window_draw(Win *win) { + Ui *ui = &win->vis->ui; + View *view = &win->view; + const Line *line = win->view.topline; + + bool status = win->options & UI_OPTION_STATUSBAR; + bool nu = win->options & UI_OPTION_LINE_NUMBERS_ABSOLUTE; + bool rnu = win->options & UI_OPTION_LINE_NUMBERS_RELATIVE; bool sidebar = nu || rnu; + + int width = win->width, height = win->height; int sidebar_width = sidebar ? snprintf(NULL, 0, "%zd ", line->lineno + height - 2) : 0; if (sidebar_width != win->sidebar_width) { view_resize(view, width - sidebar_width, status ? height - 1 : height); win->sidebar_width = sidebar_width; } - vis_window_draw(win->win); - line = view->topline; - size_t prev_lineno = 0; + vis_window_draw(win); + Selection *sel = view_selections_primary_get(view); - size_t cursor_lineno = sel->line->lineno; + size_t prev_lineno = 0, cursor_lineno = sel->line->lineno; char buf[(sizeof(size_t) * CHAR_BIT + 2) / 3 + 1 + 1]; int x = win->x, y = win->y; int view_width = view->width; @@ -253,8 +254,8 @@ static void ui_window_draw(UiWin *win) { } } -void ui_window_style_set(UiWin *win, Cell *cell, enum UiStyle id) { - Ui *tui = win->ui; +void ui_window_style_set(Win *win, Cell *cell, enum UiStyle id) { + Ui *tui = &win->vis->ui; CellStyle set, style = tui->styles[win->id * UI_STYLE_MAX + id]; if (id == UI_STYLE_DEFAULT) { @@ -269,8 +270,8 @@ void ui_window_style_set(UiWin *win, Cell *cell, enum UiStyle id) { memcpy(&cell->style, &set, sizeof(CellStyle)); } -bool ui_window_style_set_pos(UiWin *win, int x, int y, enum UiStyle id) { - Ui *tui = win->ui; +bool ui_window_style_set_pos(Win *win, int x, int y, enum UiStyle id) { + Ui *tui = &win->vis->ui; if (x < 0 || y < 0 || y >= win->height || x >= win->width) { return false; } @@ -279,10 +280,10 @@ bool ui_window_style_set_pos(UiWin *win, int x, int y, enum UiStyle id) { return true; } -void ui_window_status(UiWin *win, const char *status) { +void ui_window_status(Win *win, const char *status) { if (!(win->options & UI_OPTION_STATUSBAR)) return; - Ui *ui = win->ui; + Ui *ui = &win->vis->ui; enum UiStyle style = ui->selwin == win ? UI_STYLE_STATUS_FOCUSED : UI_STYLE_STATUS; ui_draw_string(ui, win->x, win->y + win->height - 1, status, win, style); } @@ -291,7 +292,7 @@ void ui_arrange(Ui *tui, enum UiLayout layout) { debug("ui-arrange\n"); tui->layout = layout; int n = 0, m = !!tui->info[0], x = 0, y = 0; - for (UiWin *win = tui->windows; win; win = win->next) { + for (Win *win = tui->windows; win; win = win->next) { if (win->options & UI_OPTION_ONELINE) m++; else @@ -300,7 +301,7 @@ void ui_arrange(Ui *tui, enum UiLayout layout) { int max_height = tui->height - m; int width = (tui->width / MAX(1, n)) - 1; int height = max_height / MAX(1, n); - for (UiWin *win = tui->windows; win; win = win->next) { + for (Win *win = tui->windows; win; win = win->next) { if (win->options & UI_OPTION_ONELINE) continue; n--; @@ -329,7 +330,7 @@ void ui_arrange(Ui *tui, enum UiLayout layout) { if (layout == UI_LAYOUT_VERTICAL) y = max_height; - for (UiWin *win = tui->windows; win; win = win->next) { + for (Win *win = tui->windows; win; win = win->next) { if (!(win->options & UI_OPTION_ONELINE)) continue; ui_window_resize(win, tui->width, 1); @@ -340,7 +341,7 @@ void ui_arrange(Ui *tui, enum UiLayout layout) { void ui_draw(Ui *tui) { debug("ui-draw\n"); ui_arrange(tui, tui->layout); - for (UiWin *win = tui->windows; win; win = win->next) + for (Win *win = tui->windows; win; win = win->next) ui_window_draw(win); if (tui->info[0]) ui_draw_string(tui, 0, tui->height-1, tui->info, NULL, UI_STYLE_INFO); @@ -350,8 +351,8 @@ void ui_draw(Ui *tui) { void ui_redraw(Ui *tui) { ui_term_backend_clear(tui); - for (UiWin *win = tui->windows; win; win = win->next) - win->win->view.need_update = true; + for (Win *win = tui->windows; win; win = win->next) + win->view.need_update = true; } void ui_resize(Ui *tui) { @@ -383,73 +384,46 @@ void ui_resize(Ui *tui) { tui->height = height; } -void ui_window_free(UiWin *win) { +void ui_window_release(Ui *tui, Win *win) { if (!win) return; - Ui *tui = win->ui; - if (win->prev) - win->prev->next = win->next; - if (win->next) - win->next->prev = win->prev; if (tui->windows == win) tui->windows = win->next; if (tui->selwin == win) tui->selwin = NULL; - win->next = win->prev = NULL; tui->ids &= ~(1UL << win->id); - free(win); } -void ui_window_focus(UiWin *new) { - UiWin *old = new->ui->selwin; +void ui_window_focus(Win *new) { + Win *old = new->vis->ui.selwin; if (new->options & UI_OPTION_STATUSBAR) - new->ui->selwin = new; + new->vis->ui.selwin = new; if (old) - old->win->view.need_update = true; - new->win->view.need_update = true; + old->view.need_update = true; + new->view.need_update = true; } -void ui_window_options_set(UiWin *win, enum UiOption options) { +void ui_window_options_set(Win *win, enum UiOption options) { win->options = options; if (options & UI_OPTION_ONELINE) { /* move the new window to the end of the list */ - Ui *tui = win->ui; - UiWin *last = tui->windows; + Ui *tui = &win->vis->ui; + Win *last = tui->windows; while (last->next) last = last->next; if (last != win) { - if (win->prev) - win->prev->next = win->next; - if (win->next) - win->next->prev = win->prev; if (tui->windows == win) tui->windows = win->next; last->next = win; - win->prev = last; - win->next = NULL; } } - ui_draw(win->ui); + ui_draw(&win->vis->ui); } -void ui_window_swap(UiWin *a, UiWin *b) { +void ui_window_swap(Win *a, Win *b) { if (a == b || !a || !b) return; - Ui *tui = a->ui; - UiWin *tmp = a->next; - a->next = b->next; - b->next = tmp; - if (a->next) - a->next->prev = a; - if (b->next) - b->next->prev = b; - tmp = a->prev; - a->prev = b->prev; - b->prev = tmp; - if (a->prev) - a->prev->next = a; - if (b->prev) - b->prev->next = b; + Ui *tui = &a->vis->ui; if (tui->windows == a) tui->windows = b; else if (tui->windows == b) @@ -460,7 +434,7 @@ void ui_window_swap(UiWin *a, UiWin *b) { ui_window_focus(a); } -UiWin *ui_window_new(Ui *tui, Win *w, enum UiOption options) { +bool ui_window_init(Ui *tui, Win *w, enum UiOption options) { /* get rightmost zero bit, i.e. highest available id */ size_t bit = ~tui->ids & (tui->ids + 1); size_t id = 0; @@ -475,16 +449,11 @@ UiWin *ui_window_new(Ui *tui, Win *w, enum UiOption options) { tui->styles = styles; tui->styles_size = styles_size; } - UiWin *win = calloc(1, sizeof(UiWin)); - if (!win) - return NULL; tui->ids |= bit; - win->id = id; - win->ui = tui; - win->win = w; + w->id = id; - CellStyle *styles = &tui->styles[win->id * UI_STYLE_MAX]; + CellStyle *styles = &tui->styles[w->id * UI_STYLE_MAX]; for (int i = 0; i < UI_STYLE_MAX; i++) { styles[i] = (CellStyle) { .fg = CELL_COLOR_DEFAULT, @@ -500,21 +469,19 @@ UiWin *ui_window_new(Ui *tui, Win *w, enum UiOption options) { styles[UI_STYLE_STATUS].attr |= CELL_ATTR_REVERSE; styles[UI_STYLE_STATUS_FOCUSED].attr |= CELL_ATTR_REVERSE|CELL_ATTR_BOLD; styles[UI_STYLE_INFO].attr |= CELL_ATTR_BOLD; - w->view.ui = win; if (tui->windows) - tui->windows->prev = win; - win->next = tui->windows; - tui->windows = win; + tui->windows->prev = w->prev; + tui->windows = w; if (text_size(w->file->text) > UI_LARGE_FILE_SIZE) { options |= UI_OPTION_LARGE_FILE; options &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; } - ui_window_options_set(win, options); + win_options_set(w, options); - return win; + return true; } void ui_info_show(Ui *tui, const char *msg, va_list ap) { @@ -634,7 +601,7 @@ void ui_terminal_free(Ui *tui) { if (!tui) return; while (tui->windows) - ui_window_free(tui->windows); + ui_window_release(tui, tui->windows); ui_term_backend_free(tui); if (tui->termkey) termkey_destroy(tui->termkey); @@ -79,24 +79,12 @@ typedef struct { CellStyle style; /* colors and attributes used to display this cell */ } Cell; -struct Ui; struct Win; -typedef struct UiWin { - struct Ui *ui; /* ui which manages this window */ - struct Win *win; /* editor window being displayed */ - int id; /* unique identifier for this window */ - int width, height; /* window dimension including status bar */ - int x, y; /* window position */ - int sidebar_width; /* width of the sidebar showing line numbers etc. */ - struct UiWin *next, *prev; /* pointers to neighbouring windows */ - enum UiOption options; /* display settings for this window */ -} UiWin; - struct Vis; -typedef struct Ui { +typedef struct { struct Vis *vis; /* editor instance to which this ui belongs */ - UiWin *windows; /* all windows managed by this ui */ - UiWin *selwin; /* the currently selected layout */ + struct Win *windows; /* all windows managed by this ui */ + struct Win *selwin; /* the currently selected layout */ char info[UI_MAX_WIDTH]; /* info message displayed at the bottom of the screen */ int width, height; /* terminal dimensions available for all windows */ enum UiLayout layout; /* whether windows are displayed horizontally or vertically */ @@ -114,8 +102,6 @@ typedef struct Ui { #include "vis.h" #include "text.h" -#define UI_OPTIONS_GET(ui) ((ui) ? (ui)->options : 0) - bool ui_terminal_init(Ui*); int ui_terminal_colors(void); void ui_terminal_free(Ui*); @@ -133,18 +119,19 @@ void ui_info_show(Ui *, const char *, va_list); void ui_redraw(Ui*); void ui_resize(Ui*); -UiWin *ui_window_new(Ui *, Win *, enum UiOption); -void ui_window_focus(UiWin *); -void ui_window_free(UiWin *); -void ui_window_swap(UiWin *, UiWin *); +bool ui_window_init(Ui *, Win *, enum UiOption); +void ui_window_focus(Win *); +/* removes a window from the list of open windows */ +void ui_window_release(Ui *, Win *); +void ui_window_swap(Win *, Win *); bool ui_getkey(Ui *, TermKeyKey *); -bool ui_style_define(UiWin *win, int id, const char *style); -bool ui_window_style_set_pos(UiWin *win, int x, int y, enum UiStyle id); -void ui_window_style_set(UiWin *win, Cell *cell, enum UiStyle id); +bool ui_style_define(Win *win, int id, const char *style); +bool ui_window_style_set_pos(Win *win, int x, int y, enum UiStyle id); +void ui_window_style_set(Win *win, Cell *cell, enum UiStyle id); -void ui_window_options_set(UiWin *win, enum UiOption options); -void ui_window_status(UiWin *win, const char *status); +void ui_window_options_set(Win *win, enum UiOption options); +void ui_window_status(Win *win, const char *status); #endif @@ -73,8 +73,8 @@ void window_status_update(Vis *vis, Win *win) { View *view = &win->view; File *file = win->file; Text *txt = file->text; - int width = win->ui->width; - enum UiOption options = UI_OPTIONS_GET(view->ui); + int width = win->width; + enum UiOption options = win->options; bool focused = vis->win == win; const char *filename = file_name_get(file); const char *mode = vis->mode->status; @@ -118,7 +118,7 @@ void window_status_update(Vis *vis, Win *win) { size_t col = view_cursors_col(sel); if (col > UI_LARGE_FILE_LINE_SIZE) { options |= UI_OPTION_LARGE_FILE; - view_options_set(&win->view, options); + win_options_set(win, options); } snprintf(right_parts[right_count++], sizeof(right_parts[0]), "%zu, %zu", line, col); @@ -152,7 +152,7 @@ void window_status_update(Vis *vis, Win *win) { spaces = 1; snprintf(status, sizeof(status), "%s%*s%s", left, spaces, " ", right); - ui_window_status(win->ui, status); + ui_window_status(win, status); } void view_tabwidth_set(View *view, int tabwidth) { @@ -201,8 +201,11 @@ static void view_clear(View *view) { view->col = 0; view->wrapcol = 0; view->prevch_breakat = false; - if (view->ui) - ui_window_style_set(view->ui, &cell_blank, UI_STYLE_DEFAULT); + + /* FIXME: awful garbage that only exists because every + * struct in this program is an interdependent hellscape */ + Win *win = (Win *)((char *)view - offsetof(Win, view)); + ui_window_style_set(win, &cell_blank, UI_STYLE_DEFAULT); } static int view_max_text_width(const View *view) { @@ -558,7 +561,8 @@ void view_reload(View *view, Text *text) { view_cursors_to(view->selection, 0); } -bool view_init(View *view, Text *text) { +bool view_init(Win *win, Text *text) { + View *view = &win->view; if (!text) return false; @@ -566,7 +570,7 @@ bool view_init(View *view, Text *text) { view->tabwidth = 8; view->breakat = strdup(""); view->wrapcolumn = 0; - view_options_set(view, 0); + win_options_set(win, 0); if (!view->breakat || !view_selections_new(view, 0) || @@ -859,7 +863,7 @@ void view_scroll_to(View *view, size_t pos) { view_cursors_scroll_to(view->selection, pos); } -void view_options_set(View *view, enum UiOption options) { +void win_options_set(Win *win, enum UiOption options) { const int mapping[] = { [SYNTAX_SYMBOL_SPACE] = UI_OPTION_SYMBOL_SPACE, [SYNTAX_SYMBOL_TAB] = UI_OPTION_SYMBOL_TAB, @@ -869,17 +873,16 @@ void view_options_set(View *view, enum UiOption options) { }; for (int i = 0; i < LENGTH(mapping); i++) { - view->symbols[i] = (options & mapping[i]) ? symbols_default[i] : + win->view.symbols[i] = (options & mapping[i]) ? symbols_default[i] : symbols_none[i]; } if (options & UI_OPTION_LINE_NUMBERS_ABSOLUTE) options &= ~UI_OPTION_LARGE_FILE; - view->large_file = (options & UI_OPTION_LARGE_FILE); + win->view.large_file = (options & UI_OPTION_LARGE_FILE); - if (view->ui) - ui_window_options_set(view->ui, options); + ui_window_options_set(win, options); } bool view_breakat_set(View *view, const char *breakat) { @@ -1332,7 +1335,8 @@ void view_selections_normalize(View *view) { view_selections_set(prev, &range_prev); } -void view_style(View *view, enum UiStyle style, size_t start, size_t end) { +void win_style(Win *win, enum UiStyle style, size_t start, size_t end) { + View *view = &win->view; if (end < view->start || start > view->end) return; @@ -1361,7 +1365,7 @@ void view_style(View *view, enum UiStyle style, size_t start, size_t end) { do { while (pos <= end && col < width) { pos += line->cells[col].len; - ui_window_style_set(view->ui, &line->cells[col++], style); + ui_window_style_set(win, &line->cells[col++], style); } col = 0; } while (pos <= end && (line = line->next)); @@ -49,7 +49,6 @@ typedef struct Selection { typedef struct View { Text *text; /* underlying text management */ char *textbuf; /* scratch buffer used for drawing */ - UiWin *ui; /* corresponding ui window */ int width, height; /* size of display area */ size_t start, end; /* currently displayed area [start, end] in bytes from the start of the file */ size_t start_last; /* previously used start of visible area, used to update the mark */ @@ -82,7 +81,7 @@ typedef struct View { * @defgroup view_life * @{ */ -bool view_init(View*, Text*); +bool view_init(struct Win*, Text*); void view_free(View*); void view_reload(View*, Text*); /** @@ -339,13 +338,13 @@ bool view_regions_save(View*, Filerange*, SelectionRegion*); * @defgroup view_style * @{ */ -void view_options_set(View*, enum UiOption options); +void win_options_set(struct Win *, enum UiOption); bool view_breakat_set(View*, const char *breakat); /** Set how many spaces are used to display a tab `\t` character. */ void view_tabwidth_set(View*, int tabwidth); /** Apply a style to a text range. */ -void view_style(View*, enum UiStyle, size_t start, size_t end); +void win_style(struct Win*, enum UiStyle, size_t start, size_t end); /** @} */ @@ -271,43 +271,43 @@ static bool cmd_set(Vis *vis, Win *win, Command *cmd, const char *argv[], Select [OPTION_SHOW_EOF] = UI_OPTION_SYMBOL_EOF, [OPTION_STATUSBAR] = UI_OPTION_STATUSBAR, }; - int flags = UI_OPTIONS_GET(win->view.ui); + int flags = win->options; if (arg.b || (toggle && !(flags & values[opt_index]))) flags |= values[opt_index]; else flags &= ~values[opt_index]; - view_options_set(&win->view, flags); + win_options_set(win, flags); break; } case OPTION_NUMBER: { - enum UiOption opt = UI_OPTIONS_GET(win->view.ui); + enum UiOption opt = win->options; if (arg.b || (toggle && !(opt & UI_OPTION_LINE_NUMBERS_ABSOLUTE))) { opt &= ~UI_OPTION_LINE_NUMBERS_RELATIVE; opt |= UI_OPTION_LINE_NUMBERS_ABSOLUTE; } else { opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; } - view_options_set(&win->view, opt); + win_options_set(win, opt); break; } case OPTION_NUMBER_RELATIVE: { - enum UiOption opt = UI_OPTIONS_GET(win->view.ui); + enum UiOption opt = win->options; if (arg.b || (toggle && !(opt & UI_OPTION_LINE_NUMBERS_RELATIVE))) { opt &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; opt |= UI_OPTION_LINE_NUMBERS_RELATIVE; } else { opt &= ~UI_OPTION_LINE_NUMBERS_RELATIVE; } - view_options_set(&win->view, opt); + win_options_set(win, opt); break; } case OPTION_CURSOR_LINE: { - enum UiOption opt = UI_OPTIONS_GET(win->view.ui); + enum UiOption opt = win->options; if (arg.b || (toggle && !(opt & UI_OPTION_CURSOR_LINE))) opt |= UI_OPTION_CURSOR_LINE; else opt &= ~UI_OPTION_CURSOR_LINE; - view_options_set(&win->view, opt); + win_options_set(win, opt); break; } case OPTION_COLOR_COLUMN: @@ -540,26 +540,26 @@ static bool cmd_qall(Vis *vis, Win *win, Command *cmd, const char *argv[], Selec static bool cmd_split(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) { if (!win) return false; - enum UiOption options = UI_OPTIONS_GET(win->view.ui); + enum UiOption options = win->options; ui_arrange(&vis->ui, UI_LAYOUT_HORIZONTAL); if (!argv[1]) return vis_window_split(win); bool ret = openfiles(vis, &argv[1]); if (ret) - view_options_set(&vis->win->view, options); + win_options_set(vis->win, options); return ret; } static bool cmd_vsplit(Vis *vis, Win *win, Command *cmd, const char *argv[], Selection *sel, Filerange *range) { if (!win) return false; - enum UiOption options = UI_OPTIONS_GET(win->view.ui); + enum UiOption options = win->options; ui_arrange(&vis->ui, UI_LAYOUT_VERTICAL); if (!argv[1]) return vis_window_split(win); bool ret = openfiles(vis, &argv[1]); if (ret) - view_options_set(&vis->win->view, options); + win_options_set(vis->win, options); return ret; } @@ -154,11 +154,15 @@ struct File { /* shared state among windows displaying the same file */ }; struct Win { - Vis *vis; /* editor instance to which this window belongs */ - UiWin *ui; /* ui object handling visual appearance of this window */ - File *file; /* file being displayed in this window */ + int id; /* unique identifier for this window */ + int width, height; /* window dimension including status bar */ + int x, y; /* window position */ + int sidebar_width; /* width of the sidebar showing line numbers etc. */ + enum UiOption options; /* display settings for this window */ View view; /* currently displayed part of underlying text */ bool expandtab; /* whether typed tabs should be converted to spaces in this window*/ + Vis *vis; /* editor instance to which this window belongs */ + File *file; /* file being displayed in this window */ MarkList jumplist; /* LRU jump management */ Array saved_selections; /* register used to store selections */ Mode modes[VIS_MODE_INVALID]; /* overlay mods used for per window key bindings */ @@ -1786,12 +1786,12 @@ static int window_index(lua_State *L) { } if (strcmp(key, "width") == 0) { - lua_pushunsigned(L, win->ui->width); + lua_pushunsigned(L, win->width); return 1; } if (strcmp(key, "height") == 0) { - lua_pushunsigned(L, win->ui->height); + lua_pushunsigned(L, win->height); return 1; } @@ -1825,7 +1825,7 @@ static int window_index(lua_State *L) { } static int window_options_assign(Win *win, lua_State *L, const char *key, int next) { - enum UiOption flags = UI_OPTIONS_GET(win->view.ui); + enum UiOption flags = win->options; if (strcmp(key, "breakat") == 0 || strcmp(key, "brk") == 0) { if (lua_isstring(L, next)) view_breakat_set(&win->view, lua_tostring(L, next)); @@ -1836,49 +1836,49 @@ static int window_options_assign(Win *win, lua_State *L, const char *key, int ne flags |= UI_OPTION_CURSOR_LINE; else flags &= ~UI_OPTION_CURSOR_LINE; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "numbers") == 0 || strcmp(key, "nu") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_LINE_NUMBERS_ABSOLUTE; else flags &= ~UI_OPTION_LINE_NUMBERS_ABSOLUTE; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "relativenumbers") == 0 || strcmp(key, "rnu") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_LINE_NUMBERS_RELATIVE; else flags &= ~UI_OPTION_LINE_NUMBERS_RELATIVE; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "showeof") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_SYMBOL_EOF; else flags &= ~UI_OPTION_SYMBOL_EOF; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "shownewlines") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_SYMBOL_EOL; else flags &= ~UI_OPTION_SYMBOL_EOL; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "showspaces") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_SYMBOL_SPACE; else flags &= ~UI_OPTION_SYMBOL_SPACE; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "showtabs") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_SYMBOL_TAB; else flags &= ~UI_OPTION_SYMBOL_TAB; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "statusbar") == 0) { if (lua_toboolean(L, next)) flags |= UI_OPTION_STATUSBAR; else flags &= ~UI_OPTION_STATUSBAR; - view_options_set(&win->view, flags); + win_options_set(win, flags); } else if (strcmp(key, "wrapcolumn") == 0 || strcmp(key, "wc") == 0) { win->view.wrapcolumn = luaL_checkunsigned(L, next); } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) { @@ -1986,7 +1986,7 @@ static int window_style_define(lua_State *L) { Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW); enum UiStyle id = luaL_checkunsigned(L, 2); const char *style = luaL_checkstring(L, 3); - bool ret = ui_style_define(win->view.ui, id, style); + bool ret = ui_style_define(win, id, style); lua_pushboolean(L, ret); return 1; } @@ -2008,7 +2008,7 @@ static int window_style(lua_State *L) { enum UiStyle style = luaL_checkunsigned(L, 2); size_t start = checkpos(L, 3); size_t end = checkpos(L, 4); - view_style(&win->view, style, start, end); + win_style(win, style, start, end); return 0; } @@ -2033,7 +2033,7 @@ static int window_style_pos(lua_State *L) { enum UiStyle style = luaL_checkunsigned(L, 2); size_t x = checkpos(L, 3); size_t y = checkpos(L, 4); - bool ret = ui_window_style_set_pos(win->ui, (int)x, (int)y, style); + bool ret = ui_window_style_set_pos(win, (int)x, (int)y, style); lua_pushboolean(L, ret); return 1; } @@ -2048,7 +2048,7 @@ static int window_style_pos(lua_State *L) { static int window_status(lua_State *L) { Win *win = obj_ref_check(L, 1, VIS_LUA_TYPE_WINDOW); char status[1024] = ""; - int width = win->ui->width; + int width = win->width; const char *left = luaL_checkstring(L, 2); const char *right = luaL_optstring(L, 3, ""); int left_width = text_string_width(left, strlen(left)); @@ -2057,7 +2057,7 @@ static int window_status(lua_State *L) { if (spaces < 1) spaces = 1; snprintf(status, sizeof(status)-1, "%s%*s%s", left, spaces, " ", right); - ui_window_status(win->ui, status); + ui_window_status(win, status); return 0; } @@ -2146,31 +2146,31 @@ static int window_options_index(lua_State *L) { lua_pushunsigned(L, win->view.colorcolumn); return 1; } else if (strcmp(key, "cursorline") == 0 || strcmp(key, "cul") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_CURSOR_LINE); + lua_pushboolean(L, win->options & UI_OPTION_CURSOR_LINE); return 1; } else if (strcmp(key, "expandtab") == 0 || strcmp(key, "et") == 0) { lua_pushboolean(L, win->expandtab); return 1; } else if (strcmp(key, "numbers") == 0 || strcmp(key, "nu") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_LINE_NUMBERS_ABSOLUTE); + lua_pushboolean(L, win->options & UI_OPTION_LINE_NUMBERS_ABSOLUTE); return 1; } else if (strcmp(key, "relativenumbers") == 0 || strcmp(key, "rnu") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_LINE_NUMBERS_RELATIVE); + lua_pushboolean(L, win->options & UI_OPTION_LINE_NUMBERS_RELATIVE); return 1; } else if (strcmp(key, "showeof") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_EOF); + lua_pushboolean(L, win->options & UI_OPTION_SYMBOL_EOF); return 1; } else if (strcmp(key, "shownewlines") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_EOL); + lua_pushboolean(L, win->options & UI_OPTION_SYMBOL_EOL); return 1; } else if (strcmp(key, "showspaces") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_SPACE); + lua_pushboolean(L, win->options & UI_OPTION_SYMBOL_SPACE); return 1; } else if (strcmp(key, "showtabs") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_SYMBOL_TAB); + lua_pushboolean(L, win->options & UI_OPTION_SYMBOL_TAB); return 1; } else if (strcmp(key, "statusbar") == 0) { - lua_pushboolean(L, UI_OPTIONS_GET(win->view.ui) & UI_OPTION_STATUSBAR); + lua_pushboolean(L, win->options & UI_OPTION_STATUSBAR); return 1; } else if (strcmp(key, "tabwidth") == 0 || strcmp(key, "tw") == 0) { lua_pushinteger(L, win->view.tabwidth); diff --git a/vis-prompt.c b/vis-prompt.c index 86699f2..bf1aeb2 100644 --- a/vis-prompt.c +++ b/vis-prompt.c @@ -126,7 +126,7 @@ static const char *prompt_esc(Vis *vis, const char *keys, const Arg *arg) { static const char *prompt_up(Vis *vis, const char *keys, const Arg *arg) { vis_motion(vis, VIS_MOVE_LINE_UP); vis_window_mode_unmap(vis->win, VIS_MODE_INSERT, "<Up>"); - view_options_set(&vis->win->view, UI_OPTION_SYMBOL_EOF); + win_options_set(vis->win, UI_OPTION_SYMBOL_EOF); return keys; } @@ -201,7 +201,7 @@ static void window_free(Win *win) { if (other->parent == win) other->parent = NULL; } - ui_window_free(win->ui); + ui_window_release(&vis->ui, win); view_free(&win->view); for (size_t i = 0; i < LENGTH(win->modes); i++) map_free(win->modes[i].bindings); @@ -231,7 +231,7 @@ static void window_draw_colorcolumn(Win *win) { /* This screen line contains the cell we want to highlight */ if (cc <= line_cols + width) { - ui_window_style_set(win->ui, &l->cells[cc - 1 - line_cols], UI_STYLE_COLOR_COLUMN); + ui_window_style_set(win, &l->cells[cc - 1 - line_cols], UI_STYLE_COLOR_COLUMN); line_cc_set = true; } else { line_cols += width; @@ -241,7 +241,7 @@ static void window_draw_colorcolumn(Win *win) { static void window_draw_cursorline(Win *win) { Vis *vis = win->vis; - enum UiOption options = UI_OPTIONS_GET(win->view.ui); + enum UiOption options = win->options; if (!(options & UI_OPTION_CURSOR_LINE)) return; if (vis->mode->visual || vis->win != win) @@ -255,7 +255,7 @@ static void window_draw_cursorline(Win *win) { for (Line *l = win->view.topline; l; l = l->next) { if (l->lineno == lineno) { for (int x = 0; x < width; x++) - ui_window_style_set(win->ui, &l->cells[x], UI_STYLE_CURSOR_LINE); + ui_window_style_set(win, &l->cells[x], UI_STYLE_CURSOR_LINE); } else if (l->lineno > lineno) { break; } @@ -285,7 +285,7 @@ static void window_draw_selection(Win *win, Selection *cur) { int col = (l == start_line) ? start_col : 0; int end = (l == end_line) ? end_col : l->width; while (col < end) - ui_window_style_set(win->ui, &l->cells[col++], UI_STYLE_SELECTION); + ui_window_style_set(win, &l->cells[col++], UI_STYLE_SELECTION); } } @@ -300,7 +300,7 @@ static void window_draw_cursor_matching(Win *win, Selection *cur) { return; if (!view_coord_get(&win->view, pos_match, &line_match, NULL, &col_match)) return; - ui_window_style_set(win->ui, &line_match->cells[col_match], UI_STYLE_SELECTION); + ui_window_style_set(win, &line_match->cells[col_match], UI_STYLE_SELECTION); } static void window_draw_cursor(Win *win, Selection *cur) { @@ -310,7 +310,7 @@ static void window_draw_cursor(Win *win, Selection *cur) { if (!line) return; Selection *primary = view_selections_primary_get(&win->view); - ui_window_style_set(win->ui, &line->cells[cur->col], primary == cur ? UI_STYLE_CURSOR_PRIMARY : UI_STYLE_CURSOR); + ui_window_style_set(win, &line->cells[cur->col], primary == cur ? UI_STYLE_CURSOR_PRIMARY : UI_STYLE_CURSOR); window_draw_cursor_matching(win, cur); return; } @@ -342,12 +342,12 @@ static void window_draw_eof(Win *win) { return; for (Line *l = view->lastline->next; l; l = l->next) { strncpy(l->cells[0].data, view->symbols[SYNTAX_SYMBOL_EOF], sizeof(l->cells[0].data)-1); - ui_window_style_set(win->ui, &l->cells[0], UI_STYLE_EOF); + ui_window_style_set(win, &l->cells[0], UI_STYLE_EOF); } } void vis_window_draw(Win *win) { - if (!win->ui || !view_update(&win->view)) + if (!view_update(&win->view)) return; Vis *vis = win->vis; vis_event_emit(vis, VIS_EVENT_WIN_HIGHLIGHT, win); @@ -375,27 +375,26 @@ Win *window_new_file(Vis *vis, File *file, enum UiOption options) { return NULL; win->vis = vis; win->file = file; - if (!view_init(&win->view, file->text)) { + if (!view_init(win, file->text)) { free(win); return NULL; } win->expandtab = false; - win->ui = ui_window_new(&vis->ui, win, options); - if (!win->ui) { + if (!ui_window_init(&vis->ui, win, options)) { window_free(win); return NULL; } marklist_init(&win->jumplist, 32); mark_init(&win->saved_selections); file->refcount++; - view_options_set(&win->view, UI_OPTIONS_GET(win->view.ui)); + win_options_set(win, win->options); if (vis->windows) vis->windows->prev = win; win->next = vis->windows; vis->windows = win; vis->win = win; - ui_window_focus(win->ui); + ui_window_focus(win); for (size_t i = 0; i < LENGTH(win->modes); i++) win->modes[i].parent = &vis_modes[i]; vis_event_emit(vis, VIS_EVENT_WIN_OPEN, win); @@ -443,7 +442,7 @@ bool vis_window_split(Win *original) { map_copy(win->modes[i].bindings, original->modes[i].bindings); } win->file = original->file; - view_options_set(&win->view, UI_OPTIONS_GET(original->view.ui)); + win_options_set(win, original->options); view_cursors_to(win->view.selection, view_cursor_get(&original->view)); win->vis->ui.doupdate = true; return true; @@ -454,7 +453,7 @@ void vis_window_focus(Win *win) { return; Vis *vis = win->vis; vis->win = win; - ui_window_focus(win->ui); + ui_window_focus(win); } void vis_window_next(Vis *vis) { @@ -536,7 +535,7 @@ void vis_window_swap(Win *a, Win *b) { vis->windows = b; else if (vis->windows == b) vis->windows = a; - ui_window_swap(a->ui, b->ui); + ui_window_swap(a, b); if (vis->win == a) vis_window_focus(b); else if (vis->win == b) @@ -561,7 +560,7 @@ void vis_window_close(Win *win) { vis->message_window = NULL; window_free(win); if (vis->win) - ui_window_focus(vis->win->ui); + ui_window_focus(vis->win); vis_draw(vis); } |
