1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 22:07:35 +00:00

LibVT+LibLine: Use 1;mods CSI parameters for ctrl/alt/shift-arrow keys

xterms send a bitmask (+ 1) in the 2nd CSI parameter if "special"
keys (arrow keys, pgup/down, etc) are sent with modifiers held down.

Serenity's Terminal used to send ^[[O, which is a nonexistent
escape sequence and a misread of VT100's ^[O (ie the '[' is
replaced by 'O'). Since the xterm scheme also supports shift
and alt modifiers, switch to that.

More flexible, and makes ctrl-left/right and alt-left/right work
in SerenityOS's bash port.

Also do this for page up/down.

No behavior change for SerenityOS's Shell.
This commit is contained in:
Nico Weber 2020-09-13 21:08:19 -04:00 committed by Andreas Kling
parent 2fe127d96f
commit 83c07be794
2 changed files with 32 additions and 28 deletions

View file

@ -1026,19 +1026,27 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
bool ctrl = flags & Mod_Ctrl;
bool alt = flags & Mod_Alt;
bool shift = flags & Mod_Shift;
unsigned modifier_mask = int(shift) + (int(alt) << 1) + (int(ctrl) << 2);
auto emit_final_with_modifier = [this, modifier_mask](char final) {
if (modifier_mask)
emit_string(String::format("\e[1;%d%c", modifier_mask + 1, final));
else
emit_string(String::format("\e[%c", final));
};
switch (key) {
case KeyCode::Key_Up:
emit_string(ctrl ? "\033[OA" : "\033[A");
emit_final_with_modifier('A');
return;
case KeyCode::Key_Down:
emit_string(ctrl ? "\033[OB" : "\033[B");
emit_final_with_modifier('B');
return;
case KeyCode::Key_Right:
emit_string(ctrl ? "\033[OC" : "\033[C");
emit_final_with_modifier('C');
return;
case KeyCode::Key_Left:
emit_string(ctrl ? "\033[OD" : "\033[D");
emit_final_with_modifier('D');
return;
case KeyCode::Key_Insert:
emit_string("\033[2~");
@ -1047,10 +1055,10 @@ void Terminal::handle_key_press(KeyCode key, u32 code_point, u8 flags)
emit_string("\033[3~");
return;
case KeyCode::Key_Home:
emit_string("\033[H");
emit_final_with_modifier('H');
return;
case KeyCode::Key_End:
emit_string("\033[F");
emit_final_with_modifier('F');
return;
case KeyCode::Key_PageUp:
emit_string("\033[5~");