diff --git a/doc_src/cmds/fish_key_reader.rst b/doc_src/cmds/fish_key_reader.rst index cfe967874..851ff3daa 100644 --- a/doc_src/cmds/fish_key_reader.rst +++ b/doc_src/cmds/fish_key_reader.rst @@ -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' diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index b63664f76..1731003ec 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -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 diff --git a/tests/pexpects/fkr.py b/tests/pexpects/fkr.py index 9db0f1777..95ebfa3e8 100644 --- a/tests/pexpects/fkr.py +++ b/tests/pexpects/fkr.py @@ -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)