diff options
Diffstat (limited to 'config.h')
-rw-r--r-- | config.h | 33 |
1 files changed, 31 insertions, 2 deletions
@@ -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; |