summaryrefslogtreecommitdiff
path: root/config.h
diff options
context:
space:
mode:
Diffstat (limited to 'config.h')
-rw-r--r--config.h33
1 files changed, 31 insertions, 2 deletions
diff --git a/config.h b/config.h
index 0f9ab5d..f9de97a 100644
--- a/config.h
+++ b/config.h
@@ -1,12 +1,41 @@
#pragma once
#include <unordered_map>
+#include <vector>
#include "command.h"
+#include "either.h"
+
using namespace std;
-using Keybindings = unordered_map<int,Command>;
+class KeyInputMachine{
+ struct TreeNode{
+ Command *cmd=nullptr;
+ unordered_map<int,TreeNode*> *m=nullptr;
+
+ ~TreeNode();
+ };
+
+ TreeNode root;
+ TreeNode *current=&root;
+
+public:
+ KeyInputMachine();
+ KeyInputMachine(const vector<pair<vector<int>,Command>> &list);
+ KeyInputMachine(const KeyInputMachine&) = delete;
+
+ //Overwrites if already existent; ambiguous-prefix bindings not permitted
+ //at the moment
+ void insert(const vector<int> &keys,const Command &cmd);
+
+ //If Left, then true indicates 'still possibilities'; false indicates 'no more
+ //possible sequences left, error'
+ Either<bool,Command> input(int key);
+
+ //Cancel the current input combination
+ void cancel();
+};
-extern Keybindings global_keybindings;
+extern KeyInputMachine global_keyinput;