From efb309d4cdb2f4c3926b0550d9dc1661c1e4a091 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Thu, 7 Jan 2016 14:34:47 -0600 Subject: Make scan_key() specify timeout in miliseconds, split out terminal_probesize(), add function key definitions and shift/ctrl/alt cursor keys. --- toys/example/test_scankey.c | 19 ++++++++++++++++--- toys/other/hexedit.c | 2 +- 2 files changed, 17 insertions(+), 4 deletions(-) (limited to 'toys') diff --git a/toys/example/test_scankey.c b/toys/example/test_scankey.c index 65c07204..57177416 100644 --- a/toys/example/test_scankey.c +++ b/toys/example/test_scankey.c @@ -1,6 +1,8 @@ /* test_scankey.c - collate incoming ansi escape sequences. * * Copyright 2015 Rob Landley + * + * TODO sigwinch USE_TEST_SCANKEY(NEWTOY(test_scankey, 0, 0)) @@ -37,10 +39,21 @@ void test_scankey_main(void) tty_jump(x, y); xputc(c); t[1&++tick] = time(0); - key = scan_key_getsize(scratch, !!t[0]+2*(t[0] != t[1]), &width, &height); + 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); tty_jump(0, 0); - printf("ESC to exit: key=%d x=%d y=%d width=%d height=%d ", - key, x, y, width, height); + printf("ESC to exit: "); + // Print unknown escape sequence + if (*scratch) { + printf("key=[ESC"); + // Fetch rest of sequence after deviation, time gap determines end + while (0<(key = scan_key_getsize(scratch, 0, &width, &height))) + printf("%c", key); + printf("] "); + } else printf("key=%d ", key); + printf("x=%d y=%d width=%d height=%d\033[K", x, y, width, height); + fflush(0); if (key == -2) continue; if (key <= ' ') break; diff --git a/toys/other/hexedit.c b/toys/other/hexedit.c index c45ef1ca..3c362dbd 100644 --- a/toys/other/hexedit.c +++ b/toys/other/hexedit.c @@ -176,7 +176,7 @@ void hexedit_main(void) xflush(); // Wait for next key - key = scan_key(keybuf, 1); + key = scan_key(keybuf, -1); // Exit for q, ctrl-c, ctrl-d, escape, or EOF if (key==-1 || key==3 || key==4 || key==27 || key=='q') break; highlight(x, y, 2); -- cgit v1.2.3