Improve key press handling
BackTab (Shift-Tab) on both unix and windows
F1...F5 on linux console
Ctrl-Space on windows
diff --git a/src/keys.rs b/src/keys.rs
index 273236a..0cd5e1e 100644
--- a/src/keys.rs
+++ b/src/keys.rs
@@ -3,7 +3,8 @@
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum KeyPress {
UnknownEscSeq,
- Backspace,
+ Backspace, // Ctrl('H')
+ BackTab,
Char(char),
ControlDown,
ControlLeft,
@@ -14,7 +15,7 @@
Down,
End,
Enter, // Ctrl('M')
- Esc,
+ Esc, // Ctrl('[')
F(u8),
Home,
Insert,
diff --git a/src/tty/unix.rs b/src/tty/unix.rs
index 059c322..82229d4 100644
--- a/src/tty/unix.rs
+++ b/src/tty/unix.rs
@@ -163,6 +163,20 @@
self.extended_escape(seq2)
}
}
+ } else if seq2 == '[' {
+ let seq3 = try!(self.next_char());
+ // Linux console
+ Ok(match seq3 {
+ 'A' => KeyPress::F(1),
+ 'B' => KeyPress::F(2),
+ 'C' => KeyPress::F(3),
+ 'D' => KeyPress::F(4),
+ 'E' => KeyPress::F(5),
+ _ => {
+ debug!(target: "rustyline", "unsupported esc sequence: ESC [ [ {:?}", seq3);
+ KeyPress::UnknownEscSeq
+ }
+ })
} else {
// ANSI
Ok(match seq2 {
@@ -172,6 +186,7 @@
'D' => KeyPress::Left, // kcub1
'F' => KeyPress::End,
'H' => KeyPress::Home, // khome
+ 'Z' => KeyPress::BackTab,
_ => {
debug!(target: "rustyline", "unsupported esc sequence: ESC [ {:?}", seq2);
KeyPress::UnknownEscSeq
@@ -251,13 +266,13 @@
('2', 'D') => KeyPress::ShiftLeft,
_ => {
debug!(target: "rustyline",
- "unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5);
+ "unsupported esc sequence: ESC [ 1 ; {} {:?}", seq4, seq5);
KeyPress::UnknownEscSeq
}
})
} else {
debug!(target: "rustyline",
- "unsupported esc sequence: ESC [ {} ; {} {}", seq2, seq4, seq5);
+ "unsupported esc sequence: ESC [ {} ; {} {:?}", seq2, seq4, seq5);
Ok(KeyPress::UnknownEscSeq)
}
} else {
@@ -296,8 +311,8 @@
'S' => KeyPress::F(4), // kf4
'a' => KeyPress::ControlUp,
'b' => KeyPress::ControlDown,
- 'c' => KeyPress::ControlRight,
- 'd' => KeyPress::ControlLeft,
+ 'c' => KeyPress::ControlRight, // rxvt
+ 'd' => KeyPress::ControlLeft, // rxvt
_ => {
debug!(target: "rustyline", "unsupported esc sequence: ESC O {:?}", seq2);
KeyPress::UnknownEscSeq
diff --git a/src/tty/windows.rs b/src/tty/windows.rs
index 50d0355..65b699f 100644
--- a/src/tty/windows.rs
+++ b/src/tty/windows.rs
@@ -229,7 +229,13 @@
if meta {
return Ok(KeyPress::Meta(c));
} else {
- return Ok(keys::char_to_key_press(c));
+ let mut key = keys::char_to_key_press(c);
+ if key == KeyPress::Tab && shift {
+ key = KeyPress::BackTab;
+ } else if key == KeyPress::Char(' ') && ctrl {
+ key = KeyPress::Ctrl(' ');
+ }
+ return Ok(key);
}
}
}