aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc André Tanner <mat@brain-dump.org>2015-07-25 12:38:13 +0200
committerMarc André Tanner <mat@brain-dump.org>2015-07-26 12:20:55 +0200
commitd58a37a179474d42bae6ec718ea0cf4578eb9f2a (patch)
tree1d6d6b5a13a5e4c63f2470fbc652b0c5e96572b2
parentd7a7a3efde175e944cc6943170c9f60467850060 (diff)
downloadvis-d58a37a179474d42bae6ec718ea0cf4578eb9f2a.tar.gz
vis-d58a37a179474d42bae6ec718ea0cf4578eb9f2a.tar.xz
view: always fill out complete cell matrix
-rw-r--r--ui-curses.c30
-rw-r--r--view.c29
-rw-r--r--view.h1
3 files changed, 26 insertions, 34 deletions
diff --git a/ui-curses.c b/ui-curses.c
index 5f72a2e..9ab394b 100644
--- a/ui-curses.c
+++ b/ui-curses.c
@@ -358,31 +358,17 @@ static void ui_window_free(UiWin *w) {
static void ui_window_draw_text(UiWin *w, const Line *line) {
UiCursesWin *win = (UiCursesWin*)w;
wmove(win->win, 0, 0);
+ int width = view_width_get(win->view);
for (const Line *l = line; l; l = l->next) {
- /* add a single space in an otherwise empty line to make
- * the selection cohorent */
- if (l->width == 1 && l->cells[0].data[0] == '\n') {
- int attr = l->cells[0].attr;
- if (l->cells[0].cursor)
+ for (int x = 0; x < width; x++) {
+ int attr = l->cells[x].attr;
+ if (l->cells[x].cursor && (win->ui->selwin == win || win->ui->prompt_win == win))
attr = A_NORMAL | A_REVERSE;
- if (l->cells[0].selected)
+ if (l->cells[x].selected)
attr |= A_REVERSE;
wattrset(win->win, attr);
- waddstr(win->win, " \n");
- } else {
- for (int x = 0; x < l->width; x++) {
- int attr = l->cells[x].attr;
- if (l->cells[x].cursor)
- attr = A_NORMAL | A_REVERSE;
- if (l->cells[x].selected)
- attr |= A_REVERSE;
- wattrset(win->win, attr);
- waddstr(win->win, l->cells[x].data);
- }
- if (l->width != win->width - win->sidebar_width)
- waddstr(win->win, "\n");
+ waddstr(win->win, l->cells[x].data);
}
- wclrtoeol(win->win);
}
wclrtobot(win->win);
@@ -394,8 +380,8 @@ static void ui_window_focus(UiWin *w) {
UiCursesWin *oldsel = win->ui->selwin;
win->ui->selwin = win;
if (oldsel)
- ui_window_draw_status((UiWin*)oldsel);
- ui_window_draw_status(w);
+ ui_window_draw((UiWin*)oldsel);
+ ui_window_draw(w);
}
static void ui_window_options(UiWin *w, enum UiOption options) {
diff --git a/view.c b/view.c
index 157b2c9..700ea40 100644
--- a/view.c
+++ b/view.c
@@ -72,7 +72,7 @@ static SyntaxSymbol symbols_none[] = {
{ " " }, /* spaces */
{ " " }, /* tab first cell */
{ " " }, /* tab remaining cells */
- { "" }, /* eol */
+ { " " }, /* eol */
{ "~" }, /* eof */
};
@@ -84,6 +84,9 @@ static SyntaxSymbol symbols_default[] = {
{ "~" }, /* eof */
};
+static Cell cell_unused;
+static Cell cell_blank = { .data = " " };
+
static void view_clear(View *view);
static bool view_addch(View *view, Cell *cell);
static bool view_coord_get(View *view, size_t pos, Line **retline, int *retrow, int *retcol);
@@ -132,7 +135,6 @@ static bool view_addch(View *view, Cell *cell) {
return false;
int width;
- static Cell empty;
size_t lineno = view->line->lineno;
switch (cell->data[0]) {
@@ -179,7 +181,7 @@ static bool view_addch(View *view, Cell *cell) {
view->line->len += cell->len;
view->line->width += cell->width;
for (int i = view->col + 1; i < view->width; i++)
- view->line->cells[i] = empty;
+ view->line->cells[i] = cell_blank;
view->line = view->line->next;
if (view->line)
@@ -207,7 +209,7 @@ static bool view_addch(View *view, Cell *cell) {
if (view->col + cell->width > view->width) {
for (int i = view->col; i < view->width; i++)
- view->line->cells[i] = empty;
+ view->line->cells[i] = cell_blank;
view->line = view->line->next;
view->col = 0;
}
@@ -220,7 +222,7 @@ static bool view_addch(View *view, Cell *cell) {
view->col++;
/* set cells of a character which uses multiple columns */
for (int i = 1; i < cell->width; i++)
- view->line->cells[view->col++] = empty;
+ view->line->cells[view->col++] = cell_unused;
return true;
}
return false;
@@ -444,11 +446,17 @@ void view_draw(View *view) {
/* set end of vieviewg region */
view->end = pos;
view->lastline = view->line ? view->line : view->bottomline;
+ if (view->line) {
+ for (int x = view->col; x < view->width; x++)
+ view->line->cells[x] = cell_blank;
+ }
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));
if (view->symbols[SYNTAX_SYMBOL_EOF]->color)
l->cells[0].attr =view->symbols[SYNTAX_SYMBOL_EOF]->color->attr;
+ for (int x = 1; x < view->width; x++)
+ l->cells[x] = cell_blank;
l->width = 1;
l->len = 0;
}
@@ -487,13 +495,6 @@ 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;
- /* if the cursor is at the end of the document where nothing
- * is currently displayed, add an empty cell */
- if (pos == text_size(view->text)) {
- c->line->width++;
- c->line->cells[c->col].data[0] = ' ';
- }
-
if (view->ui && view->syntax) {
Line *line_match; int col_match;
size_t pos_match = text_bracket_match_except(view->text, pos, "<>");
@@ -534,6 +535,10 @@ int view_height_get(View *view) {
return view->height;
}
+int view_width_get(View *view) {
+ return view->width;
+}
+
void view_free(View *view) {
if (!view)
return;
diff --git a/view.h b/view.h
index d993fbd..ce2dc93 100644
--- a/view.h
+++ b/view.h
@@ -52,6 +52,7 @@ void view_free(View*);
bool view_resize(View*, int width, int height);
int view_height_get(View*);
+int view_width_get(View*);
void view_draw(View*);
/* changes how many spaces are used for one tab (must be >0), redraws the window */
void view_tabwidth_set(View*, int tabwidth);