aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2016-03-12 16:54:18 +0100
committerMarc André Tanner <mat@brain-dump.org>2016-03-12 16:54:18 +0100
commit3ffd4e783c17bcd90820da297b9a2c3c7766df95 (patch)
treeb272cbfaca25087dfb6541ef0e7241408f409f79
parent20db7cee2dc1d61e0a9894373e30b1e7ae393a4c (diff)
downloadvis-3ffd4e783c17bcd90820da297b9a2c3c7766df95.tar.gz
vis-3ffd4e783c17bcd90820da297b9a2c3c7766df95.tar.xz
ui/view: general code cleanup
-rw-r--r--ui-curses.c15
-rw-r--r--view.c14
-rw-r--r--view.h4
3 files changed, 19 insertions, 14 deletions
diff --git a/ui-curses.c b/ui-curses.c
index e062ce8..6ab34a3 100644
--- a/ui-curses.c
+++ b/ui-curses.c
@@ -670,28 +670,33 @@ static void ui_window_draw(UiWin *w) {
UiCursesWin *win = (UiCursesWin*)w;
if (!ui_window_draw_sidebar(win))
return;
+
wbkgd(win->win, style_to_attr(&win->styles[UI_STYLE_DEFAULT]));
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;
bool multiple_cursors = view_cursors_multiple(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++) {
- unsigned int style_id = l->cells[x].attr;
+ enum UiStyles style_id = l->cells[x].style;
if (style_id == 0)
style_id = UI_STYLE_DEFAULT;
CellStyle *style = &win->styles[style_id];
+
if (l->cells[x].cursor && win->ui->selwin == win) {
if (multiple_cursors && l->cells[x].cursor_primary)
attr = style_to_attr(&win->styles[UI_STYLE_CURSOR_PRIMARY]);
@@ -725,6 +730,7 @@ static void ui_window_draw(UiWin *w) {
for (; 0 < x && x < width; x++)
waddstr(win->win, " ");
}
+
wclrtobot(win->win);
if (win->winstatus)
@@ -951,12 +957,11 @@ static UiWin *ui_window_new(Ui *ui, View *view, File *file, enum UiOption option
return NULL;
}
- CellStyle style = (CellStyle) {
- .fg = -1, .bg = -1, .attr = A_NORMAL,
- };
for (int i = 0; i < UI_STYLE_MAX; i++) {
- win->styles[i] = style;
+ win->styles[i] = (CellStyle) {
+ .fg = -1, .bg = -1, .attr = A_NORMAL,
+ };
}
win->styles[UI_STYLE_CURSOR].attr |= A_REVERSE;
diff --git a/view.c b/view.c
index e64d0b3..086fc6b 100644
--- a/view.c
+++ b/view.c
@@ -191,7 +191,7 @@ static void view_syntax_color(View *view) {
for (bool token_next = false; line; line = line->next, col = 0) {
for (; col < line->width; col++) {
if (pos < token_end) {
- line->cells[col].attr = token_style;
+ line->cells[col].style = token_style;
pos += line->cells[col].len;
} else {
token_next = true;
@@ -354,7 +354,7 @@ static bool view_addch(View *view, Cell *cell) {
cell->len = w == 0 ? 1 : 0;
int t = w == 0 ? SYNTAX_SYMBOL_TAB : SYNTAX_SYMBOL_TAB_FILL;
strncpy(cell->data, view->symbols[t]->symbol, sizeof(cell->data)-1);
- cell->attr = view->symbols[t]->style;
+ cell->style = view->symbols[t]->style;
view->line->cells[view->col] = *cell;
view->line->len += cell->len;
view->line->width += cell->width;
@@ -373,7 +373,7 @@ static bool view_addch(View *view, Cell *cell) {
}
strncpy(cell->data, view->symbols[SYNTAX_SYMBOL_EOL]->symbol, sizeof(cell->data)-1);
- cell->attr = view->symbols[SYNTAX_SYMBOL_EOL]->style;
+ cell->style = view->symbols[SYNTAX_SYMBOL_EOL]->style;
view->line->cells[view->col] = *cell;
view->line->len += cell->len;
@@ -393,13 +393,13 @@ static bool view_addch(View *view, Cell *cell) {
.data = { '^', ch == 127 ? '?' : ch + 64, '\0' },
.len = 1,
.width = 2,
- .attr = cell->attr,
+ .style = cell->style,
};
}
if (ch == ' ') {
strncpy(cell->data, view->symbols[SYNTAX_SYMBOL_SPACE]->symbol, sizeof(cell->data)-1);
- cell->attr = view->symbols[SYNTAX_SYMBOL_SPACE]->style;
+ cell->style = view->symbols[SYNTAX_SYMBOL_SPACE]->style;
}
@@ -650,7 +650,7 @@ void view_update(View *view) {
/* This screen line contains the cell we want to highlight */
if (line_cols >= view->colorcolumn) {
- l->cells[(view->colorcolumn - 1) % view->width].attr = UI_STYLE_COLOR_COLUMN;
+ l->cells[(view->colorcolumn - 1) % view->width].style = UI_STYLE_COLOR_COLUMN;
line_cc_set = true;
}
}
@@ -661,7 +661,7 @@ void view_update(View *view) {
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;
+ l->cells[0].style = view->symbols[SYNTAX_SYMBOL_EOF]->style;
for (int x = 1; x < view->width; x++)
l->cells[x] = cell_blank;
l->width = 1;
diff --git a/view.h b/view.h
index 81e82f5..621543e 100644
--- a/view.h
+++ b/view.h
@@ -25,10 +25,10 @@ typedef struct {
char data[16]; /* utf8 encoded character displayed in this cell (might be more than
one Unicode codepoint. might also not be the same as in the
underlying text, for example tabs get expanded */
- unsigned int attr;
+ enum UiStyles style;/* style id used to display this cell */
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;
+ bool cursor_primary;/* whether it is the primary cursor located on the cell */
} Cell;
typedef struct Line Line;