aboutsummaryrefslogtreecommitdiff
path: root/terminal.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-05 12:27:37 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-05 12:27:37 +0000
commit95eaad7ce4b40d1401cbc982966a9c7a0036e1fc (patch)
treee34a27c8443c1c0ad40fb47cad28f238e5f24a38 /terminal.c
parentcsi: DECCOLM erases screen (diff)
csi: implement DECOM - switch cursor origin between absolute and relative
The default is absolute mode, where 0,0 is the upper left corner of the screen. In relative mode, the origin is relative the top scroll margin. Internally, we always track the current cursor position in absolute mode. Every time we the client *sets* or *queries* the cursor position in relative mode, we translate it to absolute.
Diffstat (limited to 'terminal.c')
-rw-r--r--terminal.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/terminal.c b/terminal.c
index b7523d1b..2be46130 100644
--- a/terminal.c
+++ b/terminal.c
@@ -486,6 +486,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct wayland *wayl,
},
.alpha = conf->colors.alpha,
},
+ .origin = ORIGIN_ABSOLUTE,
.default_cursor_style = conf->cursor.style,
.cursor_style = conf->cursor.style,
.default_cursor_color = {
@@ -991,6 +992,30 @@ term_erase(struct terminal *term, const struct coord *start, const struct coord
erase_cell_range(term, grid_row(term->grid, end->row), 0, end->col);
}
+struct coord
+term_cursor_rel_to_abs(const struct terminal *term, int row, int col)
+{
+ switch (term->origin) {
+ case ORIGIN_ABSOLUTE:
+ return (struct coord) {
+ .col = min(col, term->cols - 1),
+ .row = min(row, term->rows - 1),
+ };
+ break;
+
+ case ORIGIN_RELATIVE: {
+ return (struct coord) {
+ .col = min(col, term->cols - 1),
+ .row = min(row + term->scroll_region.start, term->rows - 1),
+ };
+ break;
+ }
+ }
+
+ assert(false);
+ return (struct coord){-1, -1};
+}
+
void
term_cursor_to(struct terminal *term, int row, int col)
{
@@ -1006,6 +1031,13 @@ term_cursor_to(struct terminal *term, int row, int col)
}
void
+term_cursor_home(struct terminal *term)
+{
+ struct coord new_cursor = term_cursor_rel_to_abs(term, 0, 0);
+ term_cursor_to(term, new_cursor.row, new_cursor.col);
+}
+
+void
term_cursor_left(struct terminal *term, int count)
{
int move_amount = min(term->cursor.col, count);