aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cocoa_bridge.rs34
-rw-r--r--src/lib.rs2
-rw-r--r--src/parser.rs47
3 files changed, 65 insertions, 18 deletions
diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs
index 8718e58..265c052 100644
--- a/src/cocoa_bridge.rs
+++ b/src/cocoa_bridge.rs
@@ -11,7 +11,7 @@ use libc::{c_char, size_t};
use stderrlog;
use xdg;
-use {HeadphoneButton, MapGroup, MapKind};
+use {Action, HeadphoneButton, MapGroup, MapKind};
#[repr(C)]
struct renameMeMapGroup {
@@ -290,13 +290,17 @@ mode <play><up> {
if let Some(map) = mode.get(trigger) {
return match map.kind {
MapKind::Map => {
- type_string(&map.action, &[], 0.0, 0.0);
-
- Some(
- KeyActionResult::new(ActionKind::Map)
- .with_action(&map.action)
- .in_mode(trigger)
- )
+ if let Action::String(s) = &map.action {
+ type_string(s, &[], 0.0, 0.0);
+
+ Some(
+ KeyActionResult::new(ActionKind::Map)
+ .with_action(s)
+ .in_mode(trigger)
+ )
+ } else {
+ None
+ }
},
MapKind::Command => {
Some(
@@ -314,12 +318,16 @@ mode <play><up> {
if let Some(map) = map {
return match map.kind {
MapKind::Map => {
- type_string(&map.action, &[], 0.0, 0.0);
+ if let Action::String(s) = &map.action {
+ type_string(s, &[], 0.0, 0.0);
- Some(
- KeyActionResult::new(ActionKind::Map)
- .with_action(&map.action)
- )
+ Some(
+ KeyActionResult::new(ActionKind::Map)
+ .with_action(s)
+ )
+ } else {
+ None
+ }
},
MapKind::Command => {
Some(
diff --git a/src/lib.rs b/src/lib.rs
index 795d1d9..b51b165 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -13,6 +13,6 @@ extern crate xdg;
mod cocoa_bridge;
mod parser;
-use parser::{HeadphoneButton, MapGroup, MapKind};
+use parser::{Action, HeadphoneButton, MapGroup, MapKind};
pub use cocoa_bridge::*;
diff --git a/src/parser.rs b/src/parser.rs
index 57abbbb..6ac52f1 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -1,5 +1,6 @@
use std::collections::HashMap;
+use autopilot;
use autopilot::key::{Flag, KeyCodeConvertible};
use combine::*;
use combine::easy::Errors as CombineErrors;
@@ -22,11 +23,48 @@ pub enum HeadphoneButton {
Down,
}
type Trigger = Vec<HeadphoneButton>;
-type Action = String;
+// type Action = String;
-enum Action2<'a, T: 'a + KeyCodeConvertible> {
- Map(&'a [(T, &'a [Flag])]),
- Command(&'a [&'a str]),
+// enum Action2<'a, T: 'a + KeyCodeConvertible> {
+// Map(&'a [(T, &'a [Flag])]),
+// Command(&'a [&'a str]),
+// }
+
+#[derive(Debug)]
+struct Character(autopilot::key::Character);
+
+impl PartialEq for Character {
+ fn eq(&self, other: &Character) -> bool {
+ (self.0).0 == (other.0).0
+ }
+}
+
+#[derive(Debug)]
+struct KeyCode(autopilot::key::Code);
+
+impl PartialEq for KeyCode {
+ fn eq(&self, other: &KeyCode) -> bool {
+ (self.0).0 == (other.0).0
+ }
+}
+
+#[derive(Debug, PartialEq)]
+enum KeyboardKey {
+ Character(Character),
+ KeyCode(KeyCode),
+}
+
+#[derive(Debug, PartialEq)]
+struct KeyboardKeyWithModifiers {
+ key: KeyboardKey,
+ flags: Vec<Flag>,
+}
+
+#[derive(Debug, PartialEq)]
+pub enum Action {
+ String(String),
+ Map(Vec<KeyboardKeyWithModifiers>),
+ Command(Vec<String>),
}
#[repr(C)]
@@ -123,6 +161,7 @@ where
I::Error: ParseError<I::Item, I::Range, I::Position>,
{
take_until(newline())
+ .map(|action| Action::String(action))
}
fn whitespace_separator<I>() -> impl Parser<Input = I>