diff options
author | Elliott Hughes <enh@google.com> | 2019-03-23 12:32:40 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2019-04-11 17:04:21 -0500 |
commit | e478b177ab79aab7b5dfa52e5a0853e144a62327 (patch) | |
tree | 5d5cadcda868ece523c205aff61c8ef1aa4443d1 /lib/lib.h | |
parent | 1a0ec19591a104b1d14b4a7ecae47740997953a4 (diff) | |
download | toybox-e478b177ab79aab7b5dfa52e5a0853e144a62327.tar.gz |
scan_key: support more terminals.
Although we can get away with ignoring termcap/terminfo on the output
side by restricting ourselves to generally-supported escape sequences,
the input side is trickier because we need to support the sequences sent
by common terminals. Luckily, this isn't is as bad as it sounds because
only Home/End commonly differ. But it does mean we need a slightly
different implementation to deal with the many-to-one mapping.
Since we can't use TAGGED_ARRAY for this (without inflicting pain on all
the callers) I've also switched to OR-ing in the modifier keys, so we
have (say) KEY_UP|KEY_SHIFT rather than a separate KEY_SUP. This also
generalizes better should we ever need to support multiple modifiers at
once.
To reduce the number of #defines, I've also switched from KEY_F1,
KEY_F2, and so on to KEY_FN+1, KEY_FN+2, and so on. This isn't obviously
necessary, and easily undone if we'd rather have move #defines in return
for slightly more natural naming.
To enable all this, I've inverted scan_key and scan_key_getsize so that
scan_key_getsize is now the underlying function, and we don't waste all
the top bits encoding width and height between scan_key and
scan_key_getsize.
Tested by pressing Home and End in hexedit in all of the terminals
available to me.
Diffstat (limited to 'lib/lib.h')
-rw-r--r-- | lib/lib.h | 18 |
1 files changed, 16 insertions, 2 deletions
@@ -295,14 +295,28 @@ int draw_trim_esc(char *str, int padto, int width, char *escmore, int (*escout)(FILE *out, int cols,int wc)); int draw_trim(char *str, int padto, int width); -// interestingtimes.c +// tty.c int tty_fd(void); int terminal_size(unsigned *xx, unsigned *yy); int terminal_probesize(unsigned *xx, unsigned *yy); +#define KEY_UP 0 +#define KEY_DOWN 1 +#define KEY_RIGHT 2 +#define KEY_LEFT 3 +#define KEY_PGUP 4 +#define KEY_PGDN 5 +#define KEY_HOME 6 +#define KEY_END 7 +#define KEY_INSERT 8 +#define KEY_DELETE 9 +#define KEY_FN 10 // F1 = KEY_FN+1, F2 = KEY_FN+2, ... +#define KEY_SHIFT (1<<16) +#define KEY_CTRL (1<<17) +#define KEY_ALT (1<<18) +int scan_key(char *scratch, int timeout_ms); int scan_key_getsize(char *scratch, int timeout_ms, unsigned *xx, unsigned *yy); int set_terminal(int fd, int raw, int speed, struct termios *old); void xset_terminal(int fd, int raw, int speed, struct termios *old); -int scan_key(char *scratch, int timeout_ms); void tty_esc(char *s); void tty_jump(int x, int y); void tty_reset(void); |