From d4fa36ec446e758a7c167cb2e9c7ce6a69678853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Haoran=20S=2E=20Diao=20=28=E5=88=81=E6=B5=A9=E7=84=B6=29?= <0@hairydiode.xyz> Date: Fri, 12 Sep 2025 22:59:16 -0700 Subject: Added scroll region restriction --- im.h | 12 ++++++++++++ ptyim.c | 2 ++ 2 files changed, 14 insertions(+) diff --git a/im.h b/im.h index 47ae538..b08b74a 100644 --- a/im.h +++ b/im.h @@ -212,6 +212,14 @@ void im_preview(int fd, int trows, int tcols) { //writes the preview write(fd,preview_buffer,strlen(preview_buffer)); } +void restrict_scroll(int fd, int trows, int tcols) { + char pos_str[32] = ""; + int l = snprintf(pos_str, 32, "\033[0;%dr", trows-1); + write(fd, pos_str,l); +} +void unrestrict_scroll(int fd) { + write(fd,"\033[0;0r", 6); +} //Displays the IM on the bottom line, input is the number of actual physical //rows and columns on the terminal descibed by fd void disp_im(int fd, int trows, int tcols) { @@ -225,6 +233,7 @@ void disp_im(int fd, int trows, int tcols) { int l = snprintf(pos_str, 32, "\033[%d;%df", trows, im_col); write(fd,"\0337",2); //saves previous cursor position + unrestrict_scroll(fd); //unrestricts the scrolling region write(fd, pos_str,l); write(fd,"\033[7m",4); //invert video @@ -249,6 +258,9 @@ void disp_im(int fd, int trows, int tcols) { if (IM_PREVIEW) { im_preview(fd, trows, tcols); } + //restricts scroll region again + restrict_scroll(fd, trows, tcols); + //resets scroll region //restore cursor pos and attrbutes write(fd,"\033[0m",4); write(fd,"\0338",2); diff --git a/ptyim.c b/ptyim.c index eedffd3..f6434c8 100644 --- a/ptyim.c +++ b/ptyim.c @@ -95,6 +95,8 @@ void exit_main() { restore_stdin(); //clears the screen so the im statusline goes away write(STDIN_FILENO,"\033[2J", 4); + //resets scroll region + unrestrict_scroll(STDIN_FILENO); _exit(0); } //hook for when the pty child process dies -- cgit v1.1