vtgl

terminal emulator implemented in OpenGL
git clone anongit@rnpnr.xyz:vtgl.git
Log | Files | Refs | Feed | LICENSE

Commit: 9edafe03dabd3bca362786b4e7d98ed8d21a2c34
Parent: 6bd4cdf7b61e6779842fd151f2419b8029dc9f4c
Author: Randy Palamar
Date:   Fri, 14 Feb 2025 22:40:20 -0700

terminal: fix cursor down movement

The bounds on the cursors movement depend on whether or not the
cursor is currently inside the margins or not. This fixes the
distinction in this direction. Other directions are broken in the
same way and will be fixed later.

Diffstat:
Mterminal.c | 11++++++++++-
Mtests/test.c | 4++--
2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/terminal.c b/terminal.c @@ -372,6 +372,15 @@ cursor_step_raw(Term *t, i32 step, i32 rows, i32 cols) cursor_move_to(t, t->cursor.pos.y + rows, t->cursor.pos.x + cols); } +static void +cursor_down(Term *t, i32 requested_count) +{ + i32 cursor_y = t->cursor.pos.y; + i32 max = cursor_y <= t->bot ? (t->bot - cursor_y) : (t->size.h - cursor_y - 1); + i32 count = MIN(max, MAX(requested_count, 1)); + cursor_move_to(t, t->cursor.pos.y + count, t->cursor.pos.x); +} + static i32 next_tab_position(Term *t, b32 backwards) { @@ -925,7 +934,7 @@ handle_csi(Term *t, CSI *csi) switch (csi->mode) { case 'A': cursor_step_raw(t, ORONE(csi->argv[0]), -1, 0); break; - case 'B': cursor_step_raw(t, ORONE(csi->argv[0]), 1, 0); break; + case 'B': cursor_down(t, csi->argv[0]); break; case 'C': cursor_step_raw(t, ORONE(csi->argv[0]), 0, 1); break; case 'D': cursor_step_raw(t, ORONE(csi->argv[0]), 0, -1); break; case 'E': cursor_move_to(t, p.y + ORONE(csi->argv[0]), 0); break; diff --git a/tests/test.c b/tests/test.c @@ -651,8 +651,8 @@ static TEST_FN(cursor_down_v3) handle_input(term, arena, raw); result.status = term->views[term->view_idx].fb.rows[0][0].cp == 'A'; - result.status &= term->views[term->view_idx].fb.rows[4][1].cp == 'X'; - result.status &= term->cursor.pos.y == 4 && term->cursor.pos.x == 2; + result.status &= term->views[term->view_idx].fb.rows[8][0].cp == 'X'; + result.status &= term->cursor.pos.y == 8 && term->cursor.pos.x == 1; return result; }