mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 06:13:20 +00:00
fish_key_reader: Humanize key descriptions
This used to print all codepoints outside of the ASCII range (i.e.
above 0x80) in \uXXXX or \UYYYYYYYY notation.
That's quite awkward, considering that this is about keys that are
being pressed, and many keyboards have actual symbols for these on
them - I have an "ö" key, so I would like to use `bind ö` and not
`bind \u00F6`. So we go by iswgraph.
On a slightly different note, `\e` was written as `\c[ (or \e)`. I do
not believe anyone really uses `\c[` (the `[` would need to
be escaped!), and it's confusing and unnecessary to even mention that.
(cherry picked from commit 55c425a0dd
)
This commit is contained in:
parent
4d59d9cfb5
commit
65db0b2ec8
3 changed files with 8 additions and 3 deletions
|
@ -56,7 +56,7 @@ Example
|
|||
> fish_key_reader --verbose
|
||||
Press a key:
|
||||
# press alt+enter
|
||||
hex: 1B char: \c[ (or \e)
|
||||
hex: 1B char: \e
|
||||
( 0.027 ms) hex: D char: \cM (or \r)
|
||||
bind \e\r 'do something'
|
||||
|
||||
|
|
|
@ -135,7 +135,10 @@ static void ascii_printable_to_symbol(wchar_t *buf, int buf_len, wchar_t wc, boo
|
|||
static wchar_t *char_to_symbol(wchar_t wc, bool bind_friendly) {
|
||||
static wchar_t buf[64];
|
||||
|
||||
if (wc < L' ') { // ASCII control character
|
||||
if (wc == '\x1b') {
|
||||
// Escape - this is *technically* also \c[
|
||||
std::swprintf(buf, sizeof(buf) / sizeof(*buf), L"\\e");
|
||||
} else if (wc < L' ') { // ASCII control character
|
||||
ctrl_to_symbol(buf, sizeof(buf) / sizeof(*buf), wc, bind_friendly);
|
||||
} else if (wc == L' ') { // the "space" character
|
||||
space_to_symbol(buf, sizeof(buf) / sizeof(*buf), wc, bind_friendly);
|
||||
|
@ -143,6 +146,8 @@ static wchar_t *char_to_symbol(wchar_t wc, bool bind_friendly) {
|
|||
del_to_symbol(buf, sizeof(buf) / sizeof(*buf), wc, bind_friendly);
|
||||
} else if (wc < 0x80) { // ASCII characters that are not control characters
|
||||
ascii_printable_to_symbol(buf, sizeof(buf) / sizeof(*buf), wc, bind_friendly);
|
||||
} else if (fish_iswgraph(wc)) {
|
||||
std::swprintf(buf, sizeof(buf) / sizeof(*buf), L"%lc", wc);
|
||||
}
|
||||
// Conditional handling of BMP Unicode characters depends on the encoding. Assume width of wchar_t
|
||||
// corresponds to the encoding, i.e. WCHAR_T_BITS == 16 implies UTF-16 and WCHAR_T_BITS == 32
|
||||
|
|
|
@ -31,7 +31,7 @@ expect_str("char: \\cG (or \\a)\r\nbind \\a 'do something'\r\n")
|
|||
sleep(0.020)
|
||||
# send "\x1B\xE1\x88\xB4"
|
||||
send("\x1B\u1234")
|
||||
expect_str("char: \\u1234\r\nbind \\e\\u1234 'do something'\r\n")
|
||||
expect_str("char: ሴ\r\nbind \\eሴ 'do something'\r\n")
|
||||
|
||||
# Is a NULL char echoed correctly?
|
||||
sleep(0.020)
|
||||
|
|
Loading…
Reference in a new issue