Skip to content

Commit

Permalink
ui: make primary cursor blink
Browse files Browse the repository at this point in the history
  • Loading branch information
martanne committed Mar 10, 2016
1 parent 650ef03 commit 0e322d5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions lexers/themes/solarized.lua
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ lexers.STYLE_IDENTIFIER = fg

lexers.STYLE_LINENUMBER = fg
lexers.STYLE_CURSOR = 'fore:'..colors.base03..',back:'..colors.base0
lexers.STYLE_CURSOR_PRIMARY = lexers.STYLE_CURSOR..',blink'
lexers.STYLE_CURSOR_LINE = 'back:'..colors.base02
lexers.STYLE_COLOR_COLUMN = 'back:'..colors.base02
-- lexers.STYLE_SELECTION = 'back:'..colors.base02
Expand Down
6 changes: 5 additions & 1 deletion ui-curses.c
Original file line number Diff line number Diff line change
Expand Up @@ -683,13 +683,17 @@ static void ui_window_draw(UiWin *w) {
}
short selection_bg = win->styles[UI_STYLE_SELECTION].bg;
short cursor_line_bg = win->styles[UI_STYLE_CURSOR_LINE].bg;
bool multiple_cursors = view_cursors_next(view_cursors(win->view));
attr_t attr = A_NORMAL;
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) {
attr = style_to_attr(&win->styles[UI_STYLE_CURSOR]);
if (multiple_cursors && l->cells[x].cursor_primary)
attr = style_to_attr(&win->styles[UI_STYLE_CURSOR_PRIMARY]);
else
attr = style_to_attr(&win->styles[UI_STYLE_CURSOR]);
prev_style = NULL;
} else if (l->cells[x].selected) {
if (style->fg == selection_bg)
Expand Down
1 change: 1 addition & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum UiStyles {
UI_STYLE_LEXER_MAX = 64,
UI_STYLE_DEFAULT,
UI_STYLE_CURSOR,
UI_STYLE_CURSOR_PRIMARY,
UI_STYLE_CURSOR_LINE,
UI_STYLE_SELECTION,
UI_STYLE_LINENUMBER,
Expand Down
4 changes: 4 additions & 0 deletions view.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,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_PRIMARY");
view->ui->syntax_style(view->ui, UI_STYLE_CURSOR_PRIMARY, 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);
Expand Down Expand Up @@ -610,6 +613,7 @@ void view_draw(View *view) {
size_t pos = view_cursors_pos(c);
if (view_coord_get(view, pos, &c->line, &c->row, &c->col)) {
c->line->cells[c->col].cursor = true;
c->line->cells[c->col].cursor_primary = (c == view->cursor);
if (view->ui && !c->sel) {
Line *line_match; int col_match;
size_t pos_match = text_bracket_match_symbol(view->text, pos, "(){}[]\"'`");
Expand Down
1 change: 1 addition & 0 deletions view.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
unsigned int attr;
bool selected; /* whether this cell is part of a selected region */
bool cursor; /* whether a cursor is currently located on the cell */
bool cursor_primary;
} Cell;

typedef struct Line Line;
Expand Down

0 comments on commit 0e322d5

Please sign in to comment.