I've been tooling around w/ this input reader lately. Currently it only prints a report to stdout for each key pressed while it runs, but I would like to graduate it to a higher purpose sooner than later, as it seems to be coming along ok. So far it has a few things going for it:
- All its output is the result of a few concurrent processes in a single pipeline.
- It interprets and reports on each keypress as soon as it is made.
- It (to the best of my knowledge) reports on as many bytes per keypress as are sent for each keypress.
For example, if I run it and press the following keys/key-combinations in order ...
...it prints the following to the terminal screen, a line per keypress and as soon as each keypress is made:
\e:27 [:91 A:65
\e:27 [:91 1:49 ;:59 5:53 A:65
...where each byte in each keypress is printed like...
<space>(printable char|\C-escape|\octal-escape):[decimal byte value]
... as I considered appropriate.
Some of it confuses me though:
- Though I think I've tried all of the keys, and though I've definitely set
sttyto send 8-bit chars (w/
cs8), the ALT+SPACE combo seems to be the only one reporting any constituent byte higher than ASCII decimal 127.
- This is especially confusing as I assume it has something to do with the ALT modifier metafying (a concept which I admittedly understand very little about) the key sequence, but in seemingly every other case ALT+anykey just prefixes an ESC to the sequence, or otherwise subtly modifies an already escaped sequence.
- Should ALT not be shifting the sent sequence into the higher 128 - 255 range?
- (in a comment below derobert indicates the reader successfully interpreted and reported on multi-byte UTF-8
LC_*categories are set to
- Also concerning is that while I seem to get all of the bytes for each keypress, in its current form my script will delimit keypresses at
8now 32 bytes maximum.
- I previously thought 8 bytes sufficient, but I grow doubtful now when I consider whether multibyte chars in other locales might be combined with some of the longer escape sequences I'm seeing. And so I have extended the buffer - but with less certainty than 8 bytes initially provided me.
- Is there an upper-limit to how many bytes might be sent in a single keypress?