mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 03:04:57 +00:00
LibVT: Ability to generate each of the 32 ASCII control characters
Before, it was only possible to generate 27 control characters (from ^A to ^Z, and ^\) (with only one possible key combination). Now, the remaining 5 (^@, ^[, ^], ^^, and ^_) can also be generated with control plus key combinations. :^) Also added are the legacy aliases supported by most terminals: Ctrl+{2, Space} -> ^@ (NUL) Ctrl+3 -> ^[ (ESC) Ctrl+4 -> ^\ Ctrl+5 -> ^] Ctrl+6 -> ^^ Ctrl+7 -> ^_ Ctrl+8 -> ^? (DEL) Ctrl+/ -> ^_ Note that now, one extra key combination corresponding to a character that shares the same least significant five bits with the original character (used in caret notation) can also generate a control character. For example, in the US English keyboard layout both Ctrl+[ and Ctrl+{ (same as Ctrl+Shift+[) will generate the Escape control character (^[).
This commit is contained in:
parent
cb02d52ac9
commit
ff33f00d16
1 changed files with 19 additions and 5 deletions
|
@ -1533,11 +1533,25 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
|
|||
// Key event was not one of the above special cases,
|
||||
// attempt to treat it as a character...
|
||||
if (ctrl) {
|
||||
if (code_point >= 'a' && code_point <= 'z') {
|
||||
code_point = code_point - 'a' + 1;
|
||||
} else if (code_point == '\\') {
|
||||
code_point = 0x1c;
|
||||
}
|
||||
constexpr auto ESC = '\033';
|
||||
constexpr auto NUL = 0;
|
||||
constexpr auto DEL = 0x7f;
|
||||
|
||||
if (code_point >= '@' && code_point < DEL)
|
||||
code_point &= 0x1f;
|
||||
// Legacy aliases
|
||||
else if (code_point == '2' || code_point == ' ')
|
||||
// Ctrl+{2, Space, @, `} -> ^@ (NUL)
|
||||
code_point = NUL;
|
||||
else if (code_point >= '3' && code_point <= '7')
|
||||
// Ctrl+3 -> ^[ (ESC), Ctrl+4 -> ^\, Ctrl+5 -> ^], Ctrl+6 -> ^^, Ctrl+7 -> ^_
|
||||
code_point = ESC + (code_point - '3');
|
||||
else if (code_point == '8')
|
||||
// Ctrl+8 -> ^? (DEL)
|
||||
code_point = DEL;
|
||||
else if (code_point == '/')
|
||||
// Ctrl+/ -> ^_
|
||||
code_point = '_' & 0x1f;
|
||||
}
|
||||
|
||||
// Alt modifier sends escape prefix.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue