Skip to main content

nex_core/
hotkey.rs

1#[derive(Debug, Clone, PartialEq, Eq)]
2pub struct Hotkey {
3    pub modifiers: Vec<String>,
4    pub key: String,
5}
6
7pub fn parse_hotkey(input: &str) -> Result<Hotkey, String> {
8    let parts: Vec<&str> = input.split('+').collect();
9    if parts.len() < 2 {
10        return Err("invalid hotkey".into());
11    }
12
13    Ok(Hotkey {
14        modifiers: parts[..parts.len() - 1]
15            .iter()
16            .map(|s| s.to_string())
17            .collect(),
18        key: parts[parts.len() - 1].to_string(),
19    })
20}