Skip to content

Commit

Permalink
fix the behavior of commands \E[nE \E[nF moving cursor out of screen
Browse files Browse the repository at this point in the history
  • Loading branch information
viruscamp authored and Aetf committed Dec 24, 2023
1 parent d24ed61 commit 69922bd
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/tsm/tsm-vte.c
Original file line number Diff line number Diff line change
Expand Up @@ -1823,8 +1823,8 @@ static void do_csi(struct tsm_vte *vte, uint32_t data)
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
y = tsm_screen_get_cursor_y(vte->con);
tsm_screen_move_to(vte->con, 0, y + num);
tsm_screen_move_down(vte->con, num, false);
tsm_screen_move_line_home(vte->con);
break;
case 'e': /* VPR */
/* Vertical Line Position Relative */
Expand All @@ -1840,8 +1840,8 @@ static void do_csi(struct tsm_vte *vte, uint32_t data)
num = vte->csi_argv[0];
if (num <= 0)
num = 1;
y = tsm_screen_get_cursor_y(vte->con);
tsm_screen_move_to(vte->con, 0, y - num);
tsm_screen_move_up(vte->con, num, false);
tsm_screen_move_line_home(vte->con);
break;
case 'H': /* CUP */
case 'f': /* HVP */
Expand Down
16 changes: 16 additions & 0 deletions test/test_vte.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "test_common.h"

#include <xkbcommon/xkbcommon-keysyms.h>
#include <stdio.h>

static void log_cb(void *data, const char *file, int line, const char *func, const char *subs,
unsigned int sev, const char *format, va_list args)
Expand Down Expand Up @@ -292,6 +293,8 @@ START_TEST(test_vte_csi_cursor_up_down)
struct tsm_screen *screen;
struct tsm_vte *vte;
int r;
int h, w;
char csi_cmd[64];

r = tsm_screen_new(&screen, log_cb, NULL);
ck_assert_int_eq(r, 0);
Expand All @@ -310,6 +313,19 @@ START_TEST(test_vte_csi_cursor_up_down)
tsm_vte_input(vte, "\033[1E", 4);
assert_tsm_screen_cursor_pos(screen, 0, 1);

h = tsm_screen_get_height(screen);
w = tsm_screen_get_width(screen);

// move cursor up out of screen, should at first line
sprintf(csi_cmd, "\033[%dF", h + 10);
tsm_vte_input(vte, csi_cmd, strlen(csi_cmd));
assert_tsm_screen_cursor_pos(screen, 0, 0);

// move cursor down out of screen, should at last line
sprintf(csi_cmd, "\033[%dE", h + 10);
tsm_vte_input(vte, csi_cmd, strlen(csi_cmd));
assert_tsm_screen_cursor_pos(screen, 0, h - 1);

tsm_vte_unref(vte);
vte = NULL;

Expand Down

0 comments on commit 69922bd

Please sign in to comment.