Skip to content
Snippets Groups Projects
Commit d8e5ea32 authored by Ticki's avatar Ticki
Browse files

CTRL modified input

parent 3800f31e
No related branches found
No related tags found
No related merge requests found
......@@ -20,6 +20,7 @@ fn main() {
Key::Char('q') => break,
Key::Char(c) => println!("{}", c),
Key::Alt(c) => println!("^{}", c),
Key::Ctrl(c) => println!("*{}", c),
Key::Left => println!("←"),
Key::Right => println!("→"),
Key::Up => println!("↑"),
......
......@@ -43,6 +43,9 @@ pub trait TermWrite {
fn hide_cursor(&mut self) -> IoResult<usize> {
self.csi(b"?25l")
}
// TODO insert mode
/// Reset the rendition mode.
///
/// This will reset both the current style and color.
......
......@@ -17,10 +17,14 @@ pub enum Key {
Up,
/// Down arrow.
Down,
/// Alt modified character.
Alt(char),
/// Normal character.
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,
// 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(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)),
None => None,
Some(Err(_)) => Some(Key::Error),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment