From 70c772aedfabb36c5f3052cc4454ba591be2d308 Mon Sep 17 00:00:00 2001 From: WormHeamer Date: Tue, 4 Nov 2025 22:03:44 -0500 Subject: clarify scrolling behavior in comment --- main.c | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index bf79c26..c25a174 100644 --- a/main.c +++ b/main.c @@ -435,10 +435,12 @@ void vui_blit(void) { static unsigned cur_x = 0; static unsigned cur_y = 0; + /* vui_outs(CSI "H" CSI "0m"); attr_last = ATTR_DEFAULT; cur_x = 0; cur_y = 0; + */ scrolled_x = vui_win.scroll_x; scrolled_y = vui_win.scroll_y; @@ -473,41 +475,42 @@ void vui_blit(void) { vui_changes = 0; vui_max_change = 0; - /* TODO: - * - * Scroll without repainting whole screen: - * - * - \x1b[#L to insert blank lines - * - \x1b[#@ to insert blank chars - * - \x1b[#M to delete lines - * - \x1b[#P to delete chars - * - */ - if (vui_win.scroll_x || vui_win.scroll_y) { if (abs(vui_win.scroll_x) >= COLS || abs(vui_win.scroll_y) > LINES) { vui_outs(CSI "2J"); goto scrolled; } + /* spaces inserted by scrolling will have the last-used attribute */ + /* which we don't really want */ + attr_chg(&attr_last, ATTR_DEFAULT); + if (vui_win.scroll_x < 0) { + /* delete chars at start of line */ for (unsigned y = 0; y < LINES; y++) { curs_move(&cur_x, &cur_y, 0, y); vui_outf(CSI "%dP", -vui_win.scroll_x); } } else if (vui_win.scroll_x > 0) { + /* insert spaces at start of line */ for (unsigned y = 0; y < LINES; y++) { curs_move(&cur_x, &cur_y, 0, y); vui_outf(CSI "%d@", vui_win.scroll_x); } } + /* xterm has \x1b[S and \x1b[T to scroll directly */ + /* but these don't work in linux vtty */ if (vui_win.scroll_y < 0) { - if (vui_win.scroll_y == -1) vui_outs(CSI "S"); - else vui_outf(CSI "%dS", -vui_win.scroll_y); + /* delete lines at top */ + curs_move(&cur_x, &cur_y, 0, 0); + if (vui_win.scroll_y == -1) vui_outs(CSI "M"); + else vui_outf(CSI "%dM", -vui_win.scroll_y); } else if (vui_win.scroll_y > 0) { - if (vui_win.scroll_y == 1) vui_outs(CSI "T"); - else vui_outf(CSI "%dT", vui_win.scroll_y); + /* insert blank lines at top */ + curs_move(&cur_x, &cur_y, 0, 0); + if (vui_win.scroll_y == 1) vui_outs(CSI "L"); + else vui_outf(CSI "%dL", vui_win.scroll_y); } scrolled: @@ -641,7 +644,7 @@ int dx = 0, dy = 0; int camx = 0, camy = 0; int C = '*'; unsigned frame = 0; -int half_y = 1; +int half_y = 0; void draw(void *ctx) { (void)ctx; @@ -724,8 +727,10 @@ int main(int argc, const char **argv) { for (unsigned i = 0; i < isqrt(COLS * LINES) / 10; i++) { int tx = random() % COLS; int ty = random() % LINES; - VuiAttr a = ((random()&15) << 4) | (random()&15); - vui_chra(tx, ty, ' ' + (random() % 0x5f), a); + // VuiAttr a = ((random()&15) << 4) | (random()&15); + char ch = ' ' + (random() % 0x5f); + VuiAttr a = random() & ((1 << 13) - 1); + vui_chra(tx, ty, ch, a); } } @@ -735,9 +740,12 @@ int main(int argc, const char **argv) { for (unsigned x = 0; x < COLS; x++) { int tx = x + camx, ty = y + camy; char ch = " ',."[(tx^ty)&3]; - int abp = (((tx>>4)^(ty>>4)) % 3 == 0); + /* int abp = (((tx>>4)^(ty>>4)) % 3 == 0); VuiAttr aa = abp ? BG_CYAN : BG_WHITE; - VuiAttr ab = abp ? BG_BLUE : BG_RED; + VuiAttr ab = abp ? BG_BLUE : BG_RED; */ + unsigned abp = (tx >> 4) ^ (ty >> 4); + VuiAttr aa = (abp & 15) << 4; + VuiAttr ab = ((abp+1) & 15) << 4; VuiAttr a = (((tx>>2)^(ty>>2)) % 3 == 0) ? aa : ab; vui_chra(x, y, ch, a); } -- cgit v1.2.3