diff options
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | lexers/themes/solarized.lua | 1 | ||||
| -rw-r--r-- | ui-curses.c | 1 | ||||
| -rw-r--r-- | ui.h | 1 | ||||
| -rw-r--r-- | view.c | 22 | ||||
| -rw-r--r-- | view.h | 2 | ||||
| -rw-r--r-- | vis-cmds.c | 5 |
7 files changed, 36 insertions, 0 deletions
@@ -472,6 +472,10 @@ Operators can be forced to work line wise by specifying `V`. highlight the line on which the cursor currently resides + colorcolumn number + + highlight the given column + theme name use the given theme / color scheme for syntax highlighting diff --git a/lexers/themes/solarized.lua b/lexers/themes/solarized.lua index 060e6ee..6d1120c 100644 --- a/lexers/themes/solarized.lua +++ b/lexers/themes/solarized.lua @@ -51,5 +51,6 @@ lexers.STYLE_IDENTIFIER = fg lexers.STYLE_LINENUMBER = fg lexers.STYLE_CURSOR = 'fore:'..colors.base03..',back:'..colors.base0 lexers.STYLE_CURSOR_LINE = 'back:'..colors.base02 +lexers.STYLE_COLOR_COLUMN = 'back:'..colors.base02 -- lexers.STYLE_SELECTION = 'back:'..colors.base02 lexers.STYLE_SELECTION = 'back:white' diff --git a/ui-curses.c b/ui-curses.c index af5057e..79e75e5 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -892,6 +892,7 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file) { style.attr |= A_REVERSE; win->styles[UI_STYLE_CURSOR] = style; win->styles[UI_STYLE_SELECTION] = style; + win->styles[UI_STYLE_COLOR_COLUMN] = style; win->ui = uic; win->view = view; @@ -31,6 +31,7 @@ enum UiStyles { UI_STYLE_CURSOR_LINE, UI_STYLE_SELECTION, UI_STYLE_LINENUMBER, + UI_STYLE_COLOR_COLUMN, UI_STYLE_MAX, }; @@ -74,6 +74,7 @@ struct View { lua_State *lua; /* lua state used for syntax highlighting */ char *lexer_name; bool need_update; /* whether view has been redrawn */ + int colorcolumn; }; static const SyntaxSymbol symbols_none[] = { @@ -516,6 +517,15 @@ void view_update(View *view) { lua_pop(L, 3); /* _TOKENSTYLES, language specific lexer, lexers global */ } + if (view->colorcolumn > 0 && view->colorcolumn <= view->width) { + size_t lineno = 0; + for (Line *l = view->topline; l; l = l->next) { + if (l->lineno != lineno) + l->cells[view->colorcolumn-1].attr = UI_STYLE_COLOR_COLUMN; + lineno = l->lineno; + } + } + for (Line *l = view->lastline->next; l; l = l->next) { strncpy(l->cells[0].data, view->symbols[SYNTAX_SYMBOL_EOF]->symbol, sizeof(l->cells[0].data)); l->cells[0].attr = view->symbols[SYNTAX_SYMBOL_EOF]->style; @@ -909,6 +919,9 @@ bool view_syntax_set(View *view, const char *name) { lua_getfield(L, -1, "STYLE_LINENUMBER"); view->ui->syntax_style(view->ui, UI_STYLE_LINENUMBER, lua_tostring(L, -1)); lua_pop(L, 1); + lua_getfield(L, -1, "STYLE_COLOR_COLUMN"); + view->ui->syntax_style(view->ui, UI_STYLE_COLOR_COLUMN, lua_tostring(L, -1)); + lua_pop(L, 1); lua_getfield(L, -1, "load"); @@ -975,6 +988,15 @@ enum UiOption view_options_get(View *view) { return view->ui ? view->ui->options_get(view->ui) : 0; } +void view_colorcolumn_set(View *view, int col) { + if (col >= 0) + view->colorcolumn = col; +} + +int view_colorcolumn_get(View *view) { + return view->colorcolumn; +} + size_t view_screenline_goto(View *view, int n) { size_t pos = view->start; for (Line *line = view->topline; --n > 0 && line != view->lastline; line = line->next) @@ -99,6 +99,8 @@ const char *view_syntax_get(View*); void view_options_set(View*, enum UiOption options); enum UiOption view_options_get(View*); +void view_colorcolumn_set(View*, int col); +int view_colorcolumn_get(View*); /* A view can manage multiple cursors, one of which (the main cursor) is always * placed within the visible viewport. All functions named view_cursor_* operate @@ -160,6 +160,7 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * OPTION_NUMBER_RELATIVE, OPTION_CURSOR_LINE, OPTION_THEME, + OPTION_COLOR_COLUMN, }; /* definitions have to be in the same order as the enum above */ @@ -173,6 +174,7 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * [OPTION_NUMBER_RELATIVE] = { { "relativenumbers", "rnu" }, OPTION_TYPE_BOOL }, [OPTION_CURSOR_LINE] = { { "cursorline", "cul" }, OPTION_TYPE_BOOL }, [OPTION_THEME] = { { "theme" }, OPTION_TYPE_STRING }, + [OPTION_COLOR_COLUMN] = { { "colorcolumn", "cc" }, OPTION_TYPE_NUMBER }, }; if (!vis->options) { @@ -333,6 +335,9 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * return false; } break; + case OPTION_COLOR_COLUMN: + view_colorcolumn_set(vis->win->view, arg.i); + break; } return true; |
