diff options
| -rw-r--r-- | lexers/themes/solarized.lua | 1 | ||||
| -rw-r--r-- | ui-curses.c | 13 | ||||
| -rw-r--r-- | ui.h | 2 | ||||
| -rw-r--r-- | view.c | 3 | ||||
| -rw-r--r-- | vis-cmds.c | 11 |
5 files changed, 30 insertions, 0 deletions
diff --git a/lexers/themes/solarized.lua b/lexers/themes/solarized.lua index 0575056..060e6ee 100644 --- a/lexers/themes/solarized.lua +++ b/lexers/themes/solarized.lua @@ -50,5 +50,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_SELECTION = 'back:'..colors.base02 lexers.STYLE_SELECTION = 'back:white' diff --git a/ui-curses.c b/ui-curses.c index d00dbf3..fd55705 100644 --- a/ui-curses.c +++ b/ui-curses.c @@ -17,6 +17,7 @@ #include "ui.h" #include "ui-curses.h" #include "util.h" +#include "text-util.h" #ifdef NCURSES_VERSION # ifndef NCURSES_EXT_COLORS @@ -649,9 +650,18 @@ static void ui_window_draw(UiWin *w) { wmove(win->win, 0, 0); int width = view_width_get(win->view); CellStyle *prev_style = NULL; + size_t cursor_lineno = -1; + if (win->options & UI_OPTION_CURSOR_LINE && win->ui->selwin == win) { + Cursor *cursor = view_cursors(win->view); + Filerange selection = view_cursors_selection_get(cursor); + if (!view_cursors_next(cursor) && !text_range_valid(&selection)) + cursor_lineno = view_cursor_getpos(win->view).line; + } short selection_bg = win->styles[UI_STYLE_SELECTION].bg; + short cursor_line_bg = win->styles[UI_STYLE_CURSOR_LINE].bg; attr_t attr; for (const Line *l = view_lines_get(win->view); l; l = l->next) { + bool cursor_line = l->lineno == cursor_lineno; for (int x = 0; x < width; x++) { CellStyle *style = &win->styles[l->cells[x].attr]; if (l->cells[x].cursor && (win->ui->selwin == win || win->ui->prompt_win == win)) { @@ -660,6 +670,9 @@ static void ui_window_draw(UiWin *w) { } else if (l->cells[x].selected) { attr = style->attr | COLOR_PAIR(color_pair_get(style->fg, selection_bg)); prev_style = NULL; + } else if (cursor_line) { + attr = style->attr | COLOR_PAIR(color_pair_get(style->fg, cursor_line_bg)); + prev_style = NULL; } else if (style != prev_style) { attr = style_to_attr(style); prev_style = style; @@ -21,12 +21,14 @@ enum UiOption { UI_OPTION_SYMBOL_TAB_FILL = 1 << 4, UI_OPTION_SYMBOL_EOL = 1 << 5, UI_OPTION_SYMBOL_EOF = 1 << 6, + UI_OPTION_CURSOR_LINE = 1 << 7, }; enum UiStyles { UI_STYLE_LEXER_MAX = 64, UI_STYLE_DEFAULT, UI_STYLE_CURSOR, + UI_STYLE_CURSOR_LINE, UI_STYLE_SELECTION, UI_STYLE_LINENUMBER, UI_STYLE_MAX, @@ -889,6 +889,9 @@ bool view_syntax_set(View *view, const char *name) { lua_getfield(L, -1, "STYLE_CURSOR"); view->ui->syntax_style(view->ui, UI_STYLE_CURSOR, lua_tostring(L, -1)); lua_pop(L, 1); + lua_getfield(L, -1, "STYLE_CURSOR_LINE"); + view->ui->syntax_style(view->ui, UI_STYLE_CURSOR_LINE, lua_tostring(L, -1)); + lua_pop(L, 1); lua_getfield(L, -1, "STYLE_SELECTION"); view->ui->syntax_style(view->ui, UI_STYLE_SELECTION, lua_tostring(L, -1)); lua_pop(L, 1); @@ -158,6 +158,7 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * OPTION_SHOW, OPTION_NUMBER, OPTION_NUMBER_RELATIVE, + OPTION_CURSOR_LINE, }; /* definitions have to be in the same order as the enum above */ @@ -169,6 +170,7 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * [OPTION_SHOW] = { { "show" }, OPTION_TYPE_STRING }, [OPTION_NUMBER] = { { "numbers", "nu" }, OPTION_TYPE_BOOL }, [OPTION_NUMBER_RELATIVE] = { { "relativenumbers", "rnu" }, OPTION_TYPE_BOOL }, + [OPTION_CURSOR_LINE] = { { "cursorline", "cul" }, OPTION_TYPE_BOOL }, }; if (!vis->options) { @@ -313,6 +315,15 @@ static bool cmd_set(Vis *vis, Filerange *range, enum CmdOpt cmdopt, const char * view_options_set(vis->win->view, opt); break; } + case OPTION_CURSOR_LINE: { + enum UiOption opt = view_options_get(vis->win->view); + if (arg.b) + opt |= UI_OPTION_CURSOR_LINE; + else + opt &= ~UI_OPTION_CURSOR_LINE; + view_options_set(vis->win->view, opt); + break; + } } return true; |
