aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-06-17 18:53:05 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-06-17 18:53:05 +0000
commit963b266cce1cbb81a88fba2175f2d70be86559e4 (patch)
tree43526162833f2d0413f46c8b732119ef400b9063
parentwip: vt parsing: break out grid operating functions (diff)
vt: handle cursor-at-right-edge
When printing to the right-most-cell, don't advance the cursor. Instead, set a flag that indicates that the *next* print should line-wrap.
-rw-r--r--grid.c1
-rw-r--r--terminal.h1
-rw-r--r--vt.c11
3 files changed, 11 insertions, 2 deletions
diff --git a/grid.c b/grid.c
index dc94ceae..3954b64f 100644
--- a/grid.c
+++ b/grid.c
@@ -25,6 +25,7 @@ grid_cursor_move(struct grid *grid, int cols)
grid->cells[new_cursor].dirty = true;
grid->cursor = new_cursor;
grid->dirty = true;
+ grid->print_needs_wrap = false;
}
void
diff --git a/terminal.h b/terminal.h
index bc0bca56..e6a2e1f2 100644
--- a/terminal.h
+++ b/terminal.h
@@ -29,6 +29,7 @@ struct grid {
int cell_height;
int cursor;
+ bool print_needs_wrap;
struct cell *cells;
uint32_t foreground;
diff --git a/vt.c b/vt.c
index 21630292..e1fe0f03 100644
--- a/vt.c
+++ b/vt.c
@@ -177,7 +177,10 @@ action(struct terminal *term, enum action action, uint8_t c)
memset(&term->vt.utf8, 0, sizeof(term->vt.utf8));
break;
- case ACTION_PRINT:{
+ case ACTION_PRINT: {
+ if (term->grid.print_needs_wrap)
+ grid_cursor_move(&term->grid, 1);
+
struct cell *cell = &term->grid.cells[term->grid.cursor];
cell->dirty = true;
@@ -194,7 +197,11 @@ action(struct terminal *term, enum action action, uint8_t c)
cell->attrs = term->vt.attrs;
- grid_cursor_move(&term->grid, 1);
+ if ((term->grid.cursor + 1) % term->grid.cols)
+ grid_cursor_move(&term->grid, 1);
+ else
+ term->grid.print_needs_wrap = true;
+
term->grid.dirty = true;
break;
}