aboutsummaryrefslogtreecommitdiff
path: root/lib/Daffm/Action/Keymap.hs
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Daffm/Action/Keymap.hs')
-rw-r--r--lib/Daffm/Action/Keymap.hs23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/Daffm/Action/Keymap.hs b/lib/Daffm/Action/Keymap.hs
new file mode 100644
index 0000000..4463446
--- /dev/null
+++ b/lib/Daffm/Action/Keymap.hs
@@ -0,0 +1,23 @@
+module Daffm.Action.Keymap where
+
+import Control.Monad.State (get, modify)
+import Daffm.Action.Commands
+import Daffm.Keymap (matchKeySequence)
+import Daffm.Types
+
+processKeySequence :: AppEvent KeyMatchResult
+processKeySequence = do
+ (AppState {stateKeyMap, stateKeySequence}) <- get
+ let match = matchKeySequence stateKeyMap stateKeySequence
+ case match of
+ MatchSuccess cmd -> do
+ processCommand cmd
+ modify (\st -> st {stateKeySequence = []})
+ MatchPartial -> pure ()
+ MatchFailure -> do
+ modify (\st -> st {stateKeySequence = []})
+ pure match
+
+appendToKeySequence :: Key -> AppEvent ()
+appendToKeySequence key =
+ modify (\st -> st {stateKeySequence = stateKeySequence st <> [key]})