pub trait Key: Clone + PartialEq + Eq + Send + Sync + 'static {
fn display(&self) -> String;
fn is_backspace(&self) -> bool;
fn from_char(_c: char) -> Option<Self>
where
Self: Sized,
{
None
}
fn from_special_name(_name: &str) -> Option<Self>
where
Self: Sized,
{
None
}
fn space() -> Self
where
Self: Sized;
}
pub fn parse_key_sequence<K: Key>(s: &str, leader: &K) -> Vec<K> {
let mut keys = Vec::new();
let mut chars = s.chars().peekable();
while let Some(c) = chars.next() {
if c == '<' {
let mut special = String::new();
while let Some(&next) = chars.peek() {
if next == '>' {
chars.next();
break;
}
special.push(chars.next().unwrap());
}
if special.eq_ignore_ascii_case("leader") {
keys.push(leader.clone());
continue;
}
if let Some(key) = K::from_special_name(&special) {
keys.push(key);
}
} else if let Some(key) = K::from_char(c) {
keys.push(key);
}
}
keys
}
#[cfg(test)]
mod tests {}