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:
A-Walrus 2022-08-30 04:58:51 +03:00 committed by GitHub
parent 841766ef82
commit ae81fbdbf6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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());