From 5be2c53d8c9e268d55ff1c63070ad2fcc343a8bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Thu, 8 Apr 2021 12:58:47 +0200 Subject: [PATCH] =?UTF-8?q?term/vt:=20only=20do=20reverse-wrapping=20(?= =?UTF-8?q?=E2=80=98bw=E2=80=99)=20on=20cub1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Foot currently does reverse-wrapping (‘auto_left_margin’, or ’bw’) on everything that calls ‘term_cursor_left()’. This is wrong; it should only be done for cub1. From man terminfo: auto_left_margin | bw | bw | cub1 wraps from column 0 to last column This patch moves the reverse-wrapping logic from term_cursor_left() to the handling of BS (backspace). Closes #441 --- terminal.c | 41 +++-------------------------------------- vt.c | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 40 deletions(-) diff --git a/terminal.c b/terminal.c index c05eb84e..e55230b4 100644 --- a/terminal.c +++ b/terminal.c @@ -1988,44 +1988,9 @@ term_cursor_home(struct terminal *term) void term_cursor_left(struct terminal *term, int count) { - xassert(count >= 0); - int new_col = term->grid->cursor.point.col - count; - - /* Reverse wrap */ - if (unlikely(new_col < 0)) { - if (likely(term->reverse_wrap && term->auto_margin)) { - - /* Number of rows to reverse wrap through */ - int row_count = (abs(new_col) - 1) / term->cols + 1; - - /* Row number cursor will end up on */ - int new_row_no = term->grid->cursor.point.row - row_count; - - /* New column number */ - new_col = term->cols - ((abs(new_col) - 1) % term->cols + 1); - xassert(new_col >= 0 && new_col < term->cols); - - /* Don't back up past the scroll region */ - /* TODO: should this be allowed? */ - if (new_row_no < term->scroll_region.start) { - new_row_no = term->scroll_region.start; - new_col = 0; - } - - struct row *new_row = grid_row(term->grid, new_row_no); - term->grid->cursor.point.col = new_col; - term->grid->cursor.point.row = new_row_no; - term->grid->cursor.lcf = false; - term->grid->cur_row = new_row; - return; - } - - /* Reverse wrap disabled - don't let cursor move past first column */ - new_col = 0; - } - - xassert(new_col >= 0); - term->grid->cursor.point.col = new_col; + int move_amount = min(term->grid->cursor.point.col, count); + term->grid->cursor.point.col -= move_amount; + xassert(term->grid->cursor.point.col >= 0); term->grid->cursor.lcf = false; } diff --git a/vt.c b/vt.c index af4691ea..d3523efd 100644 --- a/vt.c +++ b/vt.c @@ -142,8 +142,21 @@ action_execute(struct terminal *term, uint8_t c) #else if (term->grid->cursor.lcf) term->grid->cursor.lcf = false; - else - term_cursor_left(term, 1); + else { + /* Reverse wrap */ + if (unlikely(term->grid->cursor.point.col == 0) && + likely(term->reverse_wrap && term->auto_margin)) + { + if (term->grid->cursor.point.row <= term->scroll_region.start) { + /* Don’t wrap past, or inside, the scrolling region(?) */ + } else + term_cursor_to( + term, + term->grid->cursor.point.row - 1, + term->cols - 1); + } else + term_cursor_left(term, 1); + } #endif break;