From 7f033b5f63d5cab2fb7b435ef93d9c6fd0346b27 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Sun, 28 Dec 2025 14:16:32 -0600 Subject: [PATCH] Reorder logic so display isn't a frame behind without more flush() calls. --- toys/example/demo_scankey.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/toys/example/demo_scankey.c b/toys/example/demo_scankey.c index 05ffc414..05ef4bb6 100644 --- a/toys/example/demo_scankey.c +++ b/toys/example/demo_scankey.c @@ -25,7 +25,7 @@ void demo_scankey_main(void) char c = 'X', scratch[16]; int key, x, y; - t[0] = t[1] = x = tick = 0; + t[0] = t[1] = x = tick = key = 0; memset(scratch, 0, 16); y = 1; @@ -35,11 +35,8 @@ void demo_scankey_main(void) xset_terminal(1, 1, 0, 0); // Raw mode for (;;) { - printf("\e[%u;%uH%c", y+1, x+1, c); t[1&++tick] = time(0); if (t[0] != t[1]) terminal_probesize(&width, &height); - // Don't block first time through, to force header print - key = scan_key_getsize(scratch, -1*!!t[0], &width, &height); printf("\e[HESC to exit: "); // Print unknown escape sequence if (*scratch) { @@ -49,9 +46,12 @@ void demo_scankey_main(void) printf("%c", key); printf("] "); } else printf("key=%d ", key); - printf("x=%d y=%d width=%d height=%d\e[K", x, y, width, height); + printf("x=%d y=%d width=%d height=%d tick=%u\e[K", x, y, width, height, tick); + printf("\e[%u;%uH%c", y+1, x+1, c); fflush(0); + key = scan_key_getsize(scratch, -1, &width, &height); + if (key == -2) continue; if (key <= ' ') break; if (key>=256) { -- 2.39.5