From 186cf03d687a1cacf0602a8344dcf643ec8d1348 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 27 Nov 2022 11:37:34 +0100 Subject: [PATCH] fix a few bugs in sixel --- Makefile | 8 +++---- keybinds.h | 2 ++ scripts/st_help | 1 - st.c | 56 +++++++++++++++++++++++++++++++++++-------------- 4 files changed, 46 insertions(+), 21 deletions(-) diff --git a/Makefile b/Makefile index c388e9c..253bda8 100644 --- a/Makefile +++ b/Makefile @@ -32,12 +32,12 @@ clean: rm -f st $(OBJ) st-$(VERSION).tar.gz dist: clean - mkdir -p st-$(VERSION) + mkdir -p st-spde-$(VERSION) cp -R LICENSE Makefile *.mk \ *.h *.info *.c *.desktop *.png docs/ scripts/ \ - st-$(VERSION) - tar -cf - st-$(VERSION) | gzip > st-$(VERSION).tar.gz - rm -rf st-$(VERSION) + st-spde-$(VERSION) + tar -cf - st-spde-$(VERSION) | gzip > st-spde-$(VERSION).tar.gz + rm -rf st-spde-$(VERSION) install: st mkdir -p $(DESTDIR)$(PREFIX)/bin diff --git a/keybinds.h b/keybinds.h index 7ff5705..aca3401 100644 --- a/keybinds.h +++ b/keybinds.h @@ -27,6 +27,8 @@ static Shortcut shortcuts[] = { { CONTROL|SHIFT, XK_H, kexec, {.scmd = "st_help" } }, { CONTROL|SHIFT, XK_E, kexec, {.scmd = "$EDITOR" } }, { CONTROL|SHIFT, XK_D, kexec, {.scmd = "$PERM !!" } }, + { CONTROL|SHIFT, XK_F, kexec, {.scmd = "$EDITOR $(find ~/.config -type f | fzf)" } }, + { CONTROL|SHIFT, XK_S, kexec, {.scmd = "$EDITOR $(find ~/Scripts -type f | fzf)" } }, { CONTROL|SHIFT, XK_K, kscrollup, {.i = -1} }, { CONTROL|SHIFT, XK_J, kscrolldown, {.i = -1} }, { CONTROL|SHIFT, XK_U, externalpipeout,{.v = listurl } }, diff --git a/scripts/st_help b/scripts/st_help index c2afdff..0ae4b4f 100755 --- a/scripts/st_help +++ b/scripts/st_help @@ -1,5 +1,4 @@ #!/bin/sh -# clear echo "This is a test of the st help keybind!" diff --git a/st.c b/st.c index 18b18b1..5d599e8 100644 --- a/st.c +++ b/st.c @@ -180,6 +180,7 @@ static void ttywriteraw(const char *, size_t); static void csidump(void); static void dcshandle(void); +static void scroll_images(int n); static void csihandle(void); static void readcolonargs(char **, int, int[][CAR_PER_ARG]); static void csiparse(void); @@ -1218,10 +1219,7 @@ kscrolldown(const Arg* a) tfulldirt(); } - /* TODO: Implement proper scrollback support - * For now, this will do */ - for (im = term.sixel.images; im; im = im->next) - im->should_delete = 1; + scroll_images(-1*n); } void @@ -1245,10 +1243,14 @@ kscrollup(const Arg* a) tfulldirt(); } - /* TODO: Implement proper scrollback support - * For now, this will do */ - for (im = term.sixel.images; im; im = im->next) - im->should_delete = 1; + if (term.scr + n > term.histi) + n = term.histi - term.scr; + + if (!n) + return; + + + scroll_images(n); } void @@ -1276,17 +1278,37 @@ tscrolldown(int orig, int n, int copyhist) term.line[i-n] = temp; } + scroll_images(n); + if (term.scr == 0) selscroll(orig, n); - /* TODO: Implement proper scrollback support - * For now, this will do */ - for (im = term.sixel.images; im; im = im->next) - im->should_delete = 1; - /* process scrolldown */ xsixelscrolldown(&term.sixel, n, term.bot); +} +void +scroll_images(int n) { + ImageList *im; + int tmp; + + /* maximum sixel distance in lines from current view before + * deallocation + * TODO: should be in config.h */ + int max_sixel_distance = 10000; + + for (im = term.sixel.images; im; im = im->next) { + im->y += n; + + /* check if the current sixel has exceeded the maximum + * draw distance, and should therefore be deleted */ + tmp = im->y; + if (tmp < 0) { tmp = tmp * -1; } + if (tmp > max_sixel_distance) { + fprintf(stderr, "im@0x%08x exceeded maximum distance\n"); + im->should_delete = 1; + } + } } void @@ -1294,7 +1316,6 @@ tscrollup(int orig, int n, int copyhist) { int i; Line temp; - ImageList *im; LIMIT(n, 0, term.bot-orig+1); @@ -1317,6 +1338,8 @@ tscrollup(int orig, int n, int copyhist) term.line[i+n] = temp; } + scroll_images(-1*n); + /* process scrollup */ xsixelscrollup(&term.sixel, n, term.top); @@ -1894,6 +1917,7 @@ csihandle(void) { char buf[40]; int len; + ImageList *im; switch (csiescseq.mode[0]) { default: @@ -2025,11 +2049,11 @@ csihandle(void) break; case 'S': /* SU -- Scroll line up */ DEFAULT(csiescseq.arg[0], 1); - tscrollup(term.top, csiescseq.arg[0], 0); + tscrollup(term.top, csiescseq.arg[0], 1); break; case 'T': /* SD -- Scroll line down */ DEFAULT(csiescseq.arg[0], 1); - tscrolldown(term.top, csiescseq.arg[0], 0); + tscrolldown(term.top, csiescseq.arg[0], 1); break; case 'L': /* IL -- Insert blank lines */ DEFAULT(csiescseq.arg[0], 1);