diff options
author | June McEnroe <june@causal.agency> | 2019-08-06 14:50:24 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-08-06 14:50:24 -0400 |
commit | 2c508afc6e3a42478264272d5c6c8e70159f8e3f (patch) | |
tree | 7a45fe6bfbffd4dccd258e2d32e5edac5fc11e0d | |
parent | Fix DECSTBM in termSnapshot (diff) | |
download | stream-2c508afc6e3a42478264272d5c6c8e70159f8e3f.tar.gz stream-2c508afc6e3a42478264272d5c6c8e70159f8e3f.zip |
Factor out scrolling
-rw-r--r-- | term.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/term.c b/term.c index dff09f4..18eeb66 100644 --- a/term.c +++ b/term.c @@ -74,6 +74,22 @@ static void move(struct Cell *dst, struct Cell *src, uint len) { memmove(dst, src, sizeof(*dst) * len); } +static void scrollUp(uint n) { + move( + cell(scroll.top, 0), cell(scroll.top + n, 0), + cols * (scroll.bot - scroll.top - (n - 1)) + ); + clear(cell(scroll.bot - (n - 1), 0), cell(scroll.bot, cols - 1)); +} + +static void scrollDown(uint n) { + move( + cell(scroll.top + n, 0), cell(scroll.top, 0), + cols * (scroll.bot - scroll.top - (n - 1)) + ); + clear(cell(scroll.top, 0), cell(scroll.top + (n - 1), cols - 1)); +} + static char updateNUL(wchar_t ch) { switch (ch) { break; case ESC: return ESC; @@ -83,11 +99,7 @@ static char updateNUL(wchar_t ch) { break; case NL: { if (y == scroll.bot) { - move( - cell(scroll.top, 0), cell(scroll.top + 1, 0), - cols * (scroll.bot - scroll.top) - ); - clear(cell(scroll.bot, 0), cell(scroll.bot, cols - 1)); + scrollUp(1); } else { y = MIN(y + 1, rows - 1); } @@ -133,13 +145,7 @@ static char updateESC(wchar_t ch) { break; case CSI: return CSI; break; case OSC: return OSC; - break; case RI: { - move( - cell(scroll.top + 1, 0), cell(scroll.top, 0), - cols * (scroll.bot - scroll.top) - ); - clear(cell(scroll.top, 0), cell(scroll.top, cols - 1)); - } + break; case RI: scrollDown(1); break; case '(': discard = true; return ESC; break; case '=': // ignore |