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 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'im.h') 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); -- cgit v1.1