diff options
author | Rob Landley <rob@landley.net> | 2016-01-07 14:34:47 -0600 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2016-01-07 14:34:47 -0600 |
commit | efb309d4cdb2f4c3926b0550d9dc1661c1e4a091 (patch) | |
tree | aee8bfabdaf7ecf20d0ad54f97df9f3bb1ca840e /toys/example | |
parent | d3a435e53c94ec25b4ae5fa2614f49ef8884e08a (diff) | |
download | toybox-efb309d4cdb2f4c3926b0550d9dc1661c1e4a091.tar.gz |
Make scan_key() specify timeout in miliseconds, split out terminal_probesize(),
add function key definitions and shift/ctrl/alt cursor keys.
Diffstat (limited to 'toys/example')
-rw-r--r-- | toys/example/test_scankey.c | 19 |
1 files changed, 16 insertions, 3 deletions
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 <rob@landley.net> + * + * 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; |