Allow less than and greater than in macros (#3556)
* Allow less than and greater than in macros * Fix failing test
This commit is contained in:
parent
841766ef82
commit
ae81fbdbf6
1 changed files with 6 additions and 2 deletions
|
@ -116,6 +116,8 @@ pub(crate) mod keys {
|
||||||
pub(crate) const ESC: &str = "esc";
|
pub(crate) const ESC: &str = "esc";
|
||||||
pub(crate) const SPACE: &str = "space";
|
pub(crate) const SPACE: &str = "space";
|
||||||
pub(crate) const MINUS: &str = "minus";
|
pub(crate) const MINUS: &str = "minus";
|
||||||
|
pub(crate) const LESS_THAN: &str = "lt";
|
||||||
|
pub(crate) const GREATER_THAN: &str = "gt";
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for KeyEvent {
|
impl fmt::Display for KeyEvent {
|
||||||
|
@ -156,6 +158,8 @@ impl fmt::Display for KeyEvent {
|
||||||
KeyCode::Esc => f.write_str(keys::ESC)?,
|
KeyCode::Esc => f.write_str(keys::ESC)?,
|
||||||
KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
|
KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
|
||||||
KeyCode::Char('-') => f.write_str(keys::MINUS)?,
|
KeyCode::Char('-') => f.write_str(keys::MINUS)?,
|
||||||
|
KeyCode::Char('<') => f.write_str(keys::LESS_THAN)?,
|
||||||
|
KeyCode::Char('>') => f.write_str(keys::GREATER_THAN)?,
|
||||||
KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
|
KeyCode::F(i) => f.write_fmt(format_args!("F{}", i))?,
|
||||||
KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
|
KeyCode::Char(c) => f.write_fmt(format_args!("{}", c))?,
|
||||||
};
|
};
|
||||||
|
@ -228,6 +232,8 @@ impl std::str::FromStr for KeyEvent {
|
||||||
keys::ESC => KeyCode::Esc,
|
keys::ESC => KeyCode::Esc,
|
||||||
keys::SPACE => KeyCode::Char(' '),
|
keys::SPACE => KeyCode::Char(' '),
|
||||||
keys::MINUS => KeyCode::Char('-'),
|
keys::MINUS => KeyCode::Char('-'),
|
||||||
|
keys::LESS_THAN => KeyCode::Char('<'),
|
||||||
|
keys::GREATER_THAN => KeyCode::Char('>'),
|
||||||
single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
|
single if single.chars().count() == 1 => KeyCode::Char(single.chars().next().unwrap()),
|
||||||
function if function.len() > 1 && function.starts_with('F') => {
|
function if function.len() > 1 && function.starts_with('F') => {
|
||||||
let function: String = function.chars().skip(1).collect();
|
let function: String = function.chars().skip(1).collect();
|
||||||
|
@ -548,8 +554,6 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn parsing_unsupported_named_keys() {
|
fn parsing_unsupported_named_keys() {
|
||||||
assert!(str::parse::<KeyEvent>("lt").is_err());
|
|
||||||
assert!(str::parse::<KeyEvent>("gt").is_err());
|
|
||||||
assert!(str::parse::<KeyEvent>("plus").is_err());
|
assert!(str::parse::<KeyEvent>("plus").is_err());
|
||||||
assert!(str::parse::<KeyEvent>("percent").is_err());
|
assert!(str::parse::<KeyEvent>("percent").is_err());
|
||||||
assert!(str::parse::<KeyEvent>("semicolon").is_err());
|
assert!(str::parse::<KeyEvent>("semicolon").is_err());
|
||||||
|
|
Loading…
Reference in a new issue