Check if stdin is a terminal (libc::isatty == 1)
If not, open /dev/tty
Put the terminal in raw input mode
Enable TCSADRAIN
Read a byte
If \x1b, csi, so read next byte
If next byte is [, start reading control sequence
Match next byte
A => up
B => down
C => right
D => left
H => home
F => end
Z => shift-tab
_ =>
Match next byte
~ =>
Match next byte
1 => home
2 => insert
3 => delete
4 => end
5 => page up
6 => page down
7 => home
8 => end
Else, the escape sequence was unknown
Else, the escape sequence was unknown
Else, if next byte is not [, bail out on unknown control sequence
Else, if there was no next byte, input was
Else, if byte & 224u8 == 192u8, Unicode 2-byte
Else, if byte & 240u8 == 224u8, Unicode 3-byte
Else, if byte & 248u8 == 240u8, Unicode 4-byte
Else:
If byte == \r || byte == \n,
If byte == \t,
If byte == \x7f,
If byte == \x1b,
If byte == \x01,
If byte == \x05,
If byte == \x08,
Else, char = byte
Else, if no byte to read:
If stdin is a terminal, return None
Disable TCSADRAIN