Correctly handle Backspace and Delete

The default characters sent for this were incorrect. Delete now sends
xterm-compatible escapes (dch1, kdch1), and Backspace sends the delete
code 0x7f.
This commit is contained in:
Joe Wilm 2016-07-04 09:24:51 -07:00
parent f895c2da30
commit 6be23659ef
2 changed files with 21 additions and 2 deletions

View File

@ -230,6 +230,17 @@ static F12_BINDINGS: &'static [Binding] = &[
Binding { mods: modifier::ANY, send: "\x1b[24~", mode: mode::ANY, notmode: mode::NONE },
];
/// Bindings for the Backspace key
static BACKSPACE_BINDINGS: &'static [Binding] = &[
Binding { mods: modifier::ANY, send: "\x7f", mode: mode::ANY, notmode: mode::NONE },
];
/// Bindings for the Delete key
static DELETE_BINDINGS: &'static [Binding] = &[
Binding { mods: modifier::ANY, send: "\x1b[3~", mode: mode::APP_KEYPAD, notmode: mode::NONE },
Binding { mods: modifier::ANY, send: "\x1b[P", mode: mode::ANY, notmode: mode::APP_KEYPAD },
];
// key mods escape appkey appcursor crlf
//
// notes: appkey = DECPAM (application keypad mode); not enabled is "normal keypad"
@ -287,6 +298,8 @@ impl Processor {
VirtualKeyCode::F10 => F10_BINDINGS,
VirtualKeyCode::F11 => F11_BINDINGS,
VirtualKeyCode::F12 => F12_BINDINGS,
VirtualKeyCode::Back => BACKSPACE_BINDINGS,
VirtualKeyCode::Delete => DELETE_BINDINGS,
// Mode keys ignored now
VirtualKeyCode::LAlt | VirtualKeyCode::RAlt | VirtualKeyCode::LShift |
VirtualKeyCode::RShift | VirtualKeyCode::LControl | VirtualKeyCode::RControl |

View File

@ -230,8 +230,14 @@ fn main() {
match event {
glutin::Event::Closed => break 'main_loop,
glutin::Event::ReceivedCharacter(c) => {
let encoded = c.encode_utf8();
writer.write(encoded.as_slice()).unwrap();
match c {
// Ignore BACKSPACE and DEL. These are handled specially.
'\u{8}' | '\u{7f}' => (),
_ => {
let encoded = c.encode_utf8();
writer.write(encoded.as_slice()).unwrap();
}
}
},
glutin::Event::Resized(w, h) => {
terminal.resize(w as f32, h as f32);