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
@ -116,6 +116,8 @@ pub(crate) mod keys {
|
||||
pub(crate) const ESC: &str = "esc";
|
||||
pub(crate) const SPACE: &str = "space";
|
||||
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 {
|
||||
@ -156,6 +158,8 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
KeyCode::Esc => f.write_str(keys::ESC)?,
|
||||
KeyCode::Char(' ') => f.write_str(keys::SPACE)?,
|
||||
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::Char(c) => f.write_fmt(format_args!("{}", c))?,
|
||||
};
|
||||
@ -228,6 +232,8 @@ fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
keys::ESC => KeyCode::Esc,
|
||||
keys::SPACE => 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()),
|
||||
function if function.len() > 1 && function.starts_with('F') => {
|
||||
let function: String = function.chars().skip(1).collect();
|
||||
@ -548,8 +554,6 @@ fn parsing_nonsensical_keys_fails() {
|
||||
|
||||
#[test]
|
||||
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>("percent").is_err());
|
||||
assert!(str::parse::<KeyEvent>("semicolon").is_err());
|
||||
|
Loading…
Reference in New Issue
Block a user