diff options
author | June McEnroe <june@causal.agency> | 2019-07-15 22:49:49 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2019-07-15 22:49:49 -0400 |
commit | a2c500dbc880b4d3f1a4d5f378ba98c11ddeda41 (patch) | |
tree | a348b985ed529c007170091fe480f0986e9fdf58 | |
parent | Add CSI names to shotty -d (diff) | |
download | src-a2c500dbc880b4d3f1a4d5f378ba98c11ddeda41.tar.gz src-a2c500dbc880b4d3f1a4d5f378ba98c11ddeda41.zip |
Implement scrolling region
Diffstat (limited to '')
-rw-r--r-- | bin/shotty.c | 82 |
1 files changed, 53 insertions, 29 deletions
diff --git a/bin/shotty.c b/bin/shotty.c index 978b5e78..3e0cfb25 100644 --- a/bin/shotty.c +++ b/bin/shotty.c @@ -53,6 +53,9 @@ static bool debug; static uint y, x; static bool insert; +static struct { + uint top, bot; +} scroll; static struct Style style; static struct Cell *cells; @@ -111,38 +114,52 @@ static void html(bool cursor) { static char updateNUL(wchar_t ch) { switch (ch) { - case BS: if (x) x--; return NUL; - case NL: y = MIN(y + 1, rows - 1); return NUL; - case CR: x = 0; return NUL; - case ESC: return ESC; - } - if (ch < ' ') { - warnx("unhandled \\x%02X", ch); - return NUL; - } + break; case ESC: return ESC; + + break; case BS: if (x) x--; + break; case CR: x = 0; + + 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)); + } else { + y = MIN(y + 1, rows - 1); + } + } - int width = wcwidth(ch); - if (width < 0) { - warnx("unhandled \\u%X", ch); - return NUL; - } - if (x + width > cols) { - warnx("cannot fit '%lc'", ch); - return NUL; - } + break; default: { + if (ch < ' ') { + warnx("unhandled \\x%02X", ch); + return NUL; + } - if (insert) { - move(cell(y, x + width), cell(y, x), cols - x - width); - } - cell(y, x)->style = style; - cell(y, x)->ch = ch; + int width = wcwidth(ch); + if (width < 0) { + warnx("unhandled \\u%X", ch); + return NUL; + } + if (x + width > cols) { + warnx("cannot fit '%lc'", ch); + return NUL; + } - for (int i = 1; i < width; ++i) { - cell(y, x + i)->style = style; - cell(y, x + i)->ch = '\0'; - } - x = MIN(x + width, cols - 1); + if (insert) { + move(cell(y, x + width), cell(y, x), cols - x - width); + } + cell(y, x)->style = style; + cell(y, x)->ch = ch; + for (int i = 1; i < width; ++i) { + cell(y, x + i)->style = style; + cell(y, x + i)->ch = '\0'; + } + x = MIN(x + width, cols - 1); + } + } return NUL; } @@ -166,7 +183,8 @@ static char updateNUL(wchar_t ch) { X('d', VPA) \ X('h', SM) \ X('l', RM) \ - X('m', SGR) + X('m', SGR) \ + X('r', DECSTBM) enum { #define X(ch, name) name = ch, @@ -311,6 +329,11 @@ static char updateCSI(wchar_t ch) { } } + break; case DECSTBM: { + scroll.top = (n > 0 ? ps[0] - 1 : 0); + scroll.bot = (n > 1 ? ps[1] - 1 : rows - 1); + } + break; case 't': // ignore break; default: warnx("unhandled CSI %lc", ch); @@ -393,6 +416,7 @@ int main(int argc, char *argv[]) { rows = window.ws_row; cols = window.ws_col; } + scroll.bot = rows - 1; cells = calloc(rows * cols, sizeof(*cells)); if (!cells) err(EX_OSERR, "calloc"); |