Skip to main content

ez_tui/inputs/
matcher.rs

1use crate::inputs::hotkeys::HotKey;
2use crossterm::event::KeyEvent;
3use derive_more::Constructor;
4
5/// A struct associating some [`HotKey`]s with an action
6#[derive(Clone, Debug, Eq, PartialEq, Constructor)]
7pub struct Matcher {
8    hotkeys: Vec<HotKey>,
9    name: String,
10}
11impl Matcher {
12    /// Check if the given event triggers this [`Matcher`]
13    #[must_use]
14    pub fn matches(&self, event: &KeyEvent) -> bool {
15        self.hotkeys.iter().any(|hotkey| hotkey.matches(event))
16    }
17
18    /// A list of all [`HotKey`]s that can trigger this [`Matcher`]
19    #[must_use]
20    pub fn hotkeys(&self) -> Vec<HotKey> {
21        self.hotkeys.clone()
22    }
23
24    /// A name for this [`Matcher`]
25    #[must_use]
26    pub fn name(&self) -> String {
27        self.name.clone()
28    }
29}