| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include "linux.h" | ||
| 2 | #include "parse.h" | ||
| 3 | #include "util/xstring.h" | ||
| 4 | |||
| 5 | /* | ||
| 6 | The Linux console emits \033[[ followed by letters A-E for keys F1-F5. | ||
| 7 | This can't be parsed by term_parse_sequence() because [ is a final byte | ||
| 8 | (according to ECMA-48) and an input like \033[[A would be parsed as 2 | ||
| 9 | separate sequences: CSI [ and A. The first of these is meaningless and | ||
| 10 | the second corresponds to Shift+A, which is just wrong. Therefore, when | ||
| 11 | $TERM is set to "linux", input is first passed through this function to | ||
| 12 | handle this special case. | ||
| 13 | */ | ||
| 14 | 11 | ssize_t linux_parse_key(const char *buf, size_t length, KeyCode *k) | |
| 15 | { | ||
| 16 |
4/4✓ Branch 2 → 3 taken 8 times.
✓ Branch 2 → 5 taken 3 times.
✓ Branch 4 → 5 taken 1 time.
✓ Branch 4 → 6 taken 7 times.
|
11 | if (length < 3 || !mem_equal(buf, "\033[[", 3)) { |
| 17 | 4 | return term_parse_sequence(buf, length, k); | |
| 18 | } | ||
| 19 | |||
| 20 |
2/2✓ Branch 6 → 7 taken 6 times.
✓ Branch 6 → 10 taken 1 time.
|
7 | if (unlikely(length == 3)) { |
| 21 | return TPARSE_PARTIAL_MATCH; | ||
| 22 | } | ||
| 23 | |||
| 24 | // Letters A-E represent keys F1-F5 | ||
| 25 | 6 | char c = buf[3]; | |
| 26 |
2/2✓ Branch 7 → 8 taken 5 times.
✓ Branch 7 → 9 taken 1 time.
|
6 | if (c >= 'A' && c <= 'E') { |
| 27 | 5 | *k = KEY_F1 + (c - 'A'); | |
| 28 | 5 | return 4; | |
| 29 | } | ||
| 30 | |||
| 31 | // Consume and ignore "\033[[", as term_parse_sequence() would | ||
| 32 | 1 | *k = KEY_IGNORE; | |
| 33 | 1 | return 3; | |
| 34 | } | ||
| 35 |