CTRL modified input
This commit is contained in:
parent
3800f31e92
commit
d8e5ea3262
|
@ -20,6 +20,7 @@ fn main() {
|
||||||
Key::Char('q') => break,
|
Key::Char('q') => break,
|
||||||
Key::Char(c) => println!("{}", c),
|
Key::Char(c) => println!("{}", c),
|
||||||
Key::Alt(c) => println!("^{}", c),
|
Key::Alt(c) => println!("^{}", c),
|
||||||
|
Key::Ctrl(c) => println!("*{}", c),
|
||||||
Key::Left => println!("←"),
|
Key::Left => println!("←"),
|
||||||
Key::Right => println!("→"),
|
Key::Right => println!("→"),
|
||||||
Key::Up => println!("↑"),
|
Key::Up => println!("↑"),
|
||||||
|
|
|
@ -43,6 +43,9 @@ pub trait TermWrite {
|
||||||
fn hide_cursor(&mut self) -> IoResult<usize> {
|
fn hide_cursor(&mut self) -> IoResult<usize> {
|
||||||
self.csi(b"?25l")
|
self.csi(b"?25l")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO insert mode
|
||||||
|
|
||||||
/// Reset the rendition mode.
|
/// Reset the rendition mode.
|
||||||
///
|
///
|
||||||
/// This will reset both the current style and color.
|
/// This will reset both the current style and color.
|
||||||
|
|
12
src/input.rs
12
src/input.rs
|
@ -17,10 +17,14 @@ pub enum Key {
|
||||||
Up,
|
Up,
|
||||||
/// Down arrow.
|
/// Down arrow.
|
||||||
Down,
|
Down,
|
||||||
/// Alt modified character.
|
|
||||||
Alt(char),
|
|
||||||
/// Normal character.
|
/// Normal character.
|
||||||
Char(char),
|
Char(char),
|
||||||
|
/// Alt modified character.
|
||||||
|
Alt(char),
|
||||||
|
/// Ctrl modified character.
|
||||||
|
///
|
||||||
|
/// Note that certain keys may not be modifiable with `ctrl`, due to limitations of terminals.
|
||||||
|
Ctrl(char),
|
||||||
/// Invalid character code.
|
/// Invalid character code.
|
||||||
Invalid,
|
Invalid,
|
||||||
// TODO handle errors better?
|
// TODO handle errors better?
|
||||||
|
@ -52,6 +56,10 @@ impl<I: Iterator<Item = Result<char, CharsError>>> Iterator for Keys<I> {
|
||||||
Some(Err(_)) | None => Key::Invalid,
|
Some(Err(_)) | None => Key::Invalid,
|
||||||
}),
|
}),
|
||||||
Some(Ok('\x7F')) => Some(Key::Backspace),
|
Some(Ok('\x7F')) => Some(Key::Backspace),
|
||||||
|
Some(Ok(c @ '\x10' ... '\x1A')) => Some(Key::Ctrl((c as u8 - 0x10 + b'p') as char)),
|
||||||
|
Some(Ok(c @ '\x01' ... '\x04')) => Some(Key::Ctrl((c as u8 - 0x1 + b'a') as char)),
|
||||||
|
Some(Ok(c @ '\x1C' ... '\x1F')) => Some(Key::Ctrl((c as u8 - 0x1C + b'4') as char)),
|
||||||
|
Some(Ok('\x06')) => Some(Key::Alt('f')),
|
||||||
Some(Ok(c)) => Some(Key::Char(c)),
|
Some(Ok(c)) => Some(Key::Char(c)),
|
||||||
None => None,
|
None => None,
|
||||||
Some(Err(_)) => Some(Key::Error),
|
Some(Err(_)) => Some(Key::Error),
|
||||||
|
|
Loading…
Reference in New Issue