From d70956da08c987af639fd8e03e669ca59c4c542b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 1 Jul 2019 12:23:38 +0200 Subject: wip: use a sliding window instead of memmove() to scroll Instead of memmoving a large amount of data on every scroll, use a sliding window. That is, each time we scroll, we offset origin. --- terminal.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'terminal.h') diff --git a/terminal.h b/terminal.h index cceaa6b6..4efaab9f 100644 --- a/terminal.h +++ b/terminal.h @@ -62,8 +62,8 @@ struct damage { }; struct grid { - size_t size; - size_t offset; + int size; + int offset; struct cell *cells; @@ -73,7 +73,7 @@ struct grid { struct vt_subparams { unsigned value[16]; - size_t idx; + int idx; }; struct vt_param { @@ -85,20 +85,20 @@ struct vt { int state; /* enum state */ struct { struct vt_param v[16]; - size_t idx; + int idx; } params; struct { uint8_t data[2]; - size_t idx; + int idx; } intermediates; struct { uint8_t data[1024]; - size_t idx; + int idx; } osc; struct { uint8_t data[4]; - size_t idx; - size_t left; + int idx; + int left; } utf8; struct attributes attrs; bool dim; -- cgit v1.3 From 9682e15deb2037b4da2b9796be81bd3f80e1a153 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 2 Jul 2019 22:18:25 +0200 Subject: term: "cache" pointer to current line This adds a pointer to the first cell on the current line. This pointer must be updated every time the row changes. The advantage is mainly that PRINT doesn't have to call grid_get_range(), which is fairly expensive. --- terminal.c | 12 ++++++++++++ terminal.h | 1 + vt.c | 6 +----- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'terminal.h') diff --git a/terminal.c b/terminal.c index f11ddad6..25e1246e 100644 --- a/terminal.c +++ b/terminal.c @@ -169,6 +169,12 @@ term_cursor_to(struct terminal *term, int row, int col) term->cursor.linear = new_linear; term->cursor.col = col; term->cursor.row = row; + + size_t len = term->cols; + term->grid->cur_line = grid_get_range( + term->grid, term->cursor.linear - col, &len); + + assert(len == (size_t)term->cols); } void @@ -253,6 +259,12 @@ term_scroll_partial(struct terminal *term, struct scroll_region region, int rows max(0, region.end - rows) * term->cols, 0, rows * term->cols); term_damage_scroll(term, DAMAGE_SCROLL, region, rows); + + size_t len = term->cols; + term->grid->cur_line = grid_get_range( + term->grid, term->cursor.linear - term->cursor.col, &len); + + assert(len == (size_t)term->cols); } void diff --git a/terminal.h b/terminal.h index 4efaab9f..66f6bde0 100644 --- a/terminal.h +++ b/terminal.h @@ -66,6 +66,7 @@ struct grid { int offset; struct cell *cells; + struct cell *cur_line; tll(struct damage) damage; tll(struct damage) scroll_damage; diff --git a/vt.c b/vt.c index 5d04008b..f2d85d4b 100644 --- a/vt.c +++ b/vt.c @@ -678,11 +678,7 @@ action(struct terminal *term, enum action action, uint8_t c) term_cursor_to(term, term->cursor.row + 1, 0); } - size_t cell_count = 1; - struct cell *cell = grid_get_range( - term->grid, term->cursor.linear, &cell_count); - assert(cell_count == 1); - + struct cell *cell = &term->grid->cur_line[term->cursor.col]; term_damage_update(term, term->cursor.linear, 1); if (term->vt.utf8.idx > 0) { -- cgit v1.3 From 5e8c75aa38ee0fc394556e0759b42b1713948412 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 3 Jul 2019 14:14:46 +0200 Subject: csi: implement 'civis' (show/hide cursor) --- csi.c | 4 ++-- main.c | 3 ++- terminal.h | 1 + 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'terminal.h') diff --git a/csi.c b/csi.c index dd292b79..57da1c06 100644 --- a/csi.c +++ b/csi.c @@ -567,7 +567,7 @@ csi_dispatch(struct terminal *term, uint8_t final) break; case 25: - LOG_WARN("unimplemented: civis"); + term->hide_cursor = false; break; case 1000: @@ -625,7 +625,7 @@ csi_dispatch(struct terminal *term, uint8_t final) break; case 25: - LOG_WARN("unimplemented: civis"); + term->hide_cursor = true; break; case 1000: diff --git a/main.c b/main.c index 460f36e4..a29f5d8c 100644 --- a/main.c +++ b/main.c @@ -134,7 +134,8 @@ grid_render_update(struct context *c, struct buffer *buf, const struct damage *d /* Cursor here? */ bool has_cursor - = c->term.cursor.linear == linear_cursor - c->term.grid->offset; + = (!c->term.hide_cursor && + (c->term.cursor.linear == linear_cursor - c->term.grid->offset)); int x = col * c->term.cell_width; int y = row * c->term.cell_height; diff --git a/terminal.h b/terminal.h index 66f6bde0..a96b1b70 100644 --- a/terminal.h +++ b/terminal.h @@ -131,6 +131,7 @@ struct terminal { pid_t slave; int ptmx; + bool hide_cursor; enum decckm decckm; enum keypad_mode keypad_mode; bool bracketed_paste; -- cgit v1.3 From 90dadfcc228d890fb95cc7c210b24cd024f096ac Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 3 Jul 2019 21:16:41 +0200 Subject: vt: implement (untested!) insert mode \E4l is not horizontal index, but disable INSERT mode --- csi.c | 14 +++++++------- terminal.h | 4 +++- vt.c | 9 +++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'terminal.h') diff --git a/csi.c b/csi.c index 4be35c60..6fca2c24 100644 --- a/csi.c +++ b/csi.c @@ -484,16 +484,16 @@ csi_dispatch(struct terminal *term, uint8_t final) break; } - case 'l': { - /* Horizontal index */ + case 'h': + /* smir - insert mode enable */ assert(false && "untested"); - int param = param_get(term, 0, 1); - int col = term->cursor.col; + term->insert_mode = true; + break; - col = (col + param * 8) / 8 * 8; - term_cursor_right(term, col - term->cursor.col); + case 'l': + /* rmir - insert mode disable */ + term->insert_mode = false; break; - } case 'r': { int start = param_get(term, 0, 1); diff --git a/terminal.h b/terminal.h index a96b1b70..f48158e5 100644 --- a/terminal.h +++ b/terminal.h @@ -131,9 +131,11 @@ struct terminal { pid_t slave; int ptmx; - bool hide_cursor; enum decckm decckm; enum keypad_mode keypad_mode; + bool hide_cursor; + bool auto_margin; + bool insert_mode; bool bracketed_paste; struct vt vt; diff --git a/vt.c b/vt.c index c5786b2f..b00b840d 100644 --- a/vt.c +++ b/vt.c @@ -701,6 +701,15 @@ action(struct terminal *term, enum action action, uint8_t c) struct cell *cell = &term->grid->cur_line[term->cursor.col]; term_damage_update(term, term->cursor.linear, 1); + if (term->insert_mode) { + assert(false && "untested"); + grid_memmove( + term->grid, term->cursor.linear + 1, term->cursor.linear, + term->cols - term->cursor.col - 1); + term_damage_update( + term, term->cursor.linear + 1, term->cols - term->cursor.col - 1); + } + if (term->vt.utf8.idx > 0) { //LOG_DBG("print: UTF8: %.*s", (int)term->vt.utf8.idx, term->vt.utf8.data); memcpy(cell->c, term->vt.utf8.data, term->vt.utf8.idx); -- cgit v1.3