diff options
| author | Teddy Wing | 2018-10-18 13:11:59 +0200 |
|---|---|---|
| committer | Teddy Wing | 2018-10-18 13:11:59 +0200 |
| commit | 3edf1126464eb798b6f95789fcce114bad2c05b8 (patch) | |
| tree | 03d195e608c46a7c71e497715d31bfffe6370374 /src/parser.rs | |
| parent | 7e21e54447846d182f02c25d285a25c992c9f775 (diff) | |
| download | dome-key-map-3edf1126464eb798b6f95789fcce114bad2c05b8.tar.bz2 | |
Add a `<Nop>` pseudo-key
This "key" creates an empty action that doesn't do anything. Allows
users to clear the default behaviour of a headphone button.
Diffstat (limited to 'src/parser.rs')
| -rw-r--r-- | src/parser.rs | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/src/parser.rs b/src/parser.rs index 0cfac2e..7ccaf6b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -72,6 +72,7 @@ pub enum KeyboardKey { Character(Character), KeyCode(KeyCode), NXKey(NXKey), + Nop, } #[derive(Debug, PartialEq)] @@ -107,6 +108,7 @@ impl KeyboardKeyWithModifiers { dkess_press_key(nx, flags); } }, + KeyboardKey::Nop => (), } } } @@ -323,7 +325,7 @@ where between( token('<'), token('>'), - or( + choice(( try(( many(key_modifier()), or( @@ -336,8 +338,9 @@ where action_character().map(|c| KeyboardKey::Character(Character::new(c)) ), - )) - ) + )), + try((value(vec![]), nop())), + )) ).map(|(modifiers, key): (Vec<Flag>, KeyboardKey)| { KeyboardKeyWithModifiers::new( key, @@ -492,6 +495,15 @@ where ) } +fn nop<I>() -> impl Parser<Input = I, Output = KeyboardKey> +where + I: Stream<Item = char>, + I::Error: ParseError<I::Item, I::Range, I::Position>, +{ + string_case_insensitive("Nop") + .map(|_| KeyboardKey::Nop) +} + fn whitespace_separator<I>() -> impl Parser<Input = I> where I: Stream<Item = char>, @@ -1016,6 +1028,21 @@ mod tests { } #[test] + fn action_parses_map_with_nop() { + let text = "<Nop>"; + + let expected = Action::Map(vec![ + KeyboardKeyWithModifiers::new( + KeyboardKey::Nop, + vec![], + ), + ]); + let result = action_map().easy_parse(text).map(|t| t.0); + + assert_eq!(result, Ok(expected)); + } + + #[test] fn map_parses_map_line() { let text = "map <play><down> test "; |
