From 8fdb86c6c8dbf0adfa2d9af9e756843eb3622a8a Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Fri, 24 Aug 2018 15:35:04 +0200 Subject: run_key_action(): Approach for handling actions for different MapKinds Work out the essential body of the function, which necessitates looking inside a `MapGroup` and finding a `MapAction` corresponding to the `Trigger` given in the function argument. The function will then perform whatever action it can and return a `KeyActionResult` struct, allowing callers to pick up the baton. --- src/cocoa_bridge.rs | 50 ++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 46 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/cocoa_bridge.rs b/src/cocoa_bridge.rs index d57e5ee..97f741f 100644 --- a/src/cocoa_bridge.rs +++ b/src/cocoa_bridge.rs @@ -44,11 +44,53 @@ pub struct KeyActionResult<'a> { pub extern "C" fn run_key_action( trigger: &[HeadphoneButton] -) -> KeyActionResult { - KeyActionResult { - action: None, - kind: MapKind::Map, +) -> Option { + let sample_maps = "map k +map j"; + + // Figure out how to persist this without re-parsing + let map_group = MapGroup::parse(sample_maps).unwrap(); + + let map = map_group.maps.get(trigger); + let mode = map_group.modes.get(trigger); + + if let Some(map) = map { + return match map.kind { + MapKind::Map => { + Some(KeyActionResult { + action: None, //Some(m.action.as_str()), + kind: MapKind::Map, + }) + }, + MapKind::Command => { + Some(KeyActionResult { + action: None, + kind: MapKind::Command, + }) + }, + } } + + if let Some(mode) = mode { + } + + // match map_group.get(trigger) { + // Some(map_action) => { + // Some(KeyActionResult { + // action: map_action.action, + // kind: MapKind::Map, + // }) + // }, + // None => { + // // TODO: Figure out how to error + // None + // }, + // } + + None +} + +fn run_command(command: Action) -> Result { } -- cgit v1.2.3