scroll

scrollbackbuffer program for st
git clone git://git.suckless.org/scroll
Log | Files | Refs

commit db13d11496626604931053ac2d5a12f022efca43
parent 18fc6b49569b67647142602c2f6cb3f268cea6c3
Author: Jan Klemkow <j.klemkow@wemelug.de>
Date:   Thu,  2 Apr 2020 23:02:38 +0200

don't scroll if alternative screen is active

Diffstat:
Mscroll.c | 18++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)

diff --git a/scroll.c b/scroll.c @@ -58,6 +58,7 @@ pid_t child; int mfd; struct termios dfl; struct winsize ws; +static bool altscreen = false; /* is alternative screen active */ void die(const char *fmt, ...) @@ -188,7 +189,6 @@ strelen(const char *buf, size_t size) bool isaltscreen(char c) { - static bool alt = false; static enum {CHAR, BREK, ESC} state = CHAR; static char buf[BUFSIZ]; static size_t i = 0; @@ -219,18 +219,18 @@ isaltscreen(char c) if (strcmp(buf, "?1049h") == 0 || strcmp(buf, "?1047h") == 0 || strcmp(buf, "?47h" ) == 0) - alt = true; + altscreen = true; /* esc seq. disable alternative screen */ if (strcmp(buf, "?1049l") == 0 || strcmp(buf, "?1047l") == 0 || strcmp(buf, "?47l" ) == 0) - alt = false; + altscreen = false; } break; } - return alt; + return altscreen; } void @@ -389,11 +389,13 @@ main(int argc, char *argv[]) if (n <= 0 && errno != EINTR) die("read:"); - if (strncmp(KB_SCROLL_UP, input, n) == 0 || - strncmp(MS_SCROLL_UP, input, n) == 0) + if (!altscreen && + (strncmp(KB_SCROLL_UP, input, n) == 0 || + strncmp(MS_SCROLL_UP, input, n) == 0)) scrollup(); - else if (strncmp(KB_SCROLL_DOWN, input, n) == 0 || - strncmp(MS_SCROLL_DOWN, input, n) == 0) + else if (!altscreen && + (strncmp(KB_SCROLL_DOWN, input, n) == 0 || + strncmp(MS_SCROLL_DOWN, input, n) == 0)) scrolldown(buf, pos); else if (write(mfd, input, n) == -1) die("write:");