summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHaoran S. Diao (刁浩然) <0@hairydiode.xyz>2025-09-12 22:59:16 -0700
committerHaoran S. Diao (刁浩然) <0@hairydiode.xyz>2025-09-12 22:59:16 -0700
commitd4fa36ec446e758a7c167cb2e9c7ce6a69678853 (patch)
treefd421bf04887c13f7cc9baa81d34e9b11f219e08
parent9a6954f9720784bc79668bcc6456f6a3f6a0c5a1 (diff)
Added scroll region restriction
-rw-r--r--im.h12
-rw-r--r--ptyim.c2
2 files changed, 14 insertions, 0 deletions
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