aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2019-11-29 23:32:34 +0000
committerDaniel Eklöf <daniel@ekloef.se>2019-11-29 23:32:34 +0000
commit0e5a69d8692def68bbd046f91acb36a1193268a9 (patch)
tree914ae99a74e9f266b98a448a63a4be777b3e1dab
parentterm: reset: set 'origin' to ORIGIN_ABSOLUTE (diff)
vt: don't try to move cursor outside the terminal
When we insert an auto-newline, we must make sure we don't try to move outside the terminal window. This can for example happen when a scrolling region have been configured, and the cursor is **outside** the scrolling region (i.e. it's in the bottom margin).
-rw-r--r--vt.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/vt.c b/vt.c
index 7c174b01..f1adc5f6 100644
--- a/vt.c
+++ b/vt.c
@@ -12,6 +12,7 @@
#include "grid.h"
#include "osc.h"
+#define min(x, y) ((x) < (y) ? (x) : (y))
#define max(x, y) ((x) > (y) ? (x) : (y))
#define UNHANDLED() LOG_DBG("unhandled: %s", esc_as_string(term, final))
@@ -717,13 +718,16 @@ esc_dispatch(struct terminal *term, uint8_t final)
static inline void
pre_print(struct terminal *term)
{
- if (unlikely(term->cursor.lcf) && term->auto_margin) {
- if (term->cursor.point.row == term->scroll_region.end - 1) {
- term_scroll(term, 1);
- term_cursor_to(term, term->cursor.point.row, 0);
- } else
- term_cursor_to(term, term->cursor.point.row + 1, 0);
- }
+ if (likely(!term->cursor.lcf))
+ return;
+ if (unlikely(!term->auto_margin))
+ return;
+
+ if (term->cursor.point.row == term->scroll_region.end - 1) {
+ term_scroll(term, 1);
+ term_cursor_to(term, term->cursor.point.row, 0);
+ } else
+ term_cursor_to(term, min(term->cursor.point.row + 1, term->rows - 1), 0);
}
static inline void