Move key binding groups to config crate

This commit is contained in:
Joscha 2023-04-27 15:31:49 +02:00
parent 5a0efd69e4
commit e1c3a463b2
7 changed files with 33 additions and 7 deletions

View file

@ -173,11 +173,35 @@ impl<'de> Deserialize<'de> for KeyPress {
pub struct KeyBinding(Vec<KeyPress>);
impl KeyBinding {
pub fn new() -> Self {
Self(vec![])
}
pub fn with_key(self, key: &str) -> Result<Self, ParseKeysError> {
self.with_keys([key])
}
pub fn with_keys<'a, I>(mut self, keys: I) -> Result<Self, ParseKeysError>
where
I: IntoIterator<Item = &'a str>,
{
for key in keys {
self.0.push(key.parse()?);
}
Ok(self)
}
pub fn matches(&self, event: KeyEvent) -> bool {
self.0.iter().any(|kp| kp.matches(event))
}
}
impl Default for KeyBinding {
fn default() -> Self {
Self::new()
}
}
impl Serialize for KeyBinding {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
if self.0.len() == 1 {