diff options
| author | Daniel Eklöf <daniel@ekloef.se> | 2019-11-05 12:27:37 +0000 |
|---|---|---|
| committer | Daniel Eklöf <daniel@ekloef.se> | 2019-11-05 12:27:37 +0000 |
| commit | 95eaad7ce4b40d1401cbc982966a9c7a0036e1fc (patch) | |
| tree | e34a27c8443c1c0ad40fb47cad28f238e5f24a38 /terminal.c | |
| parent | csi: 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.c | 32 |
1 files changed, 32 insertions, 0 deletions
@@ -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); |
