summaryrefslogtreecommitdiff
path: root/keybinds.cpp
diff options
context:
space:
mode:
authorBossCode45 <human.cyborg42@gmail.com>2023-05-24 10:28:49 +1200
committerBossCode45 <human.cyborg42@gmail.com>2023-05-24 10:28:49 +1200
commitda3b5b2131d2b4ff5cb127e92090fca568376835 (patch)
tree3c3ca1dbb19683a22eefde705f2d8ac4d62ffdc3 /keybinds.cpp
parent6655d5dfb24ca3fd36b02550c526bca1f5d924e9 (diff)
downloadYATwm-da3b5b2131d2b4ff5cb127e92090fca568376835.tar.gz
YATwm-da3b5b2131d2b4ff5cb127e92090fca568376835.zip
in-progress: Config refactor started, changed all existing keybind command args and added in the new files, still many errors
Diffstat (limited to 'keybinds.cpp')
-rw-r--r--keybinds.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/keybinds.cpp b/keybinds.cpp
new file mode 100644
index 0000000..57f7003
--- /dev/null
+++ b/keybinds.cpp
@@ -0,0 +1,45 @@
+#include <iostream>
+
+#include "keybinds.h"
+
+using std::string, std::cin, std::cout, std::endl;
+
+KeybindsModule::KeybindsModule(CommandsModule& commandsModule)
+ :commandsModule(commandsModule)
+{
+ CommandArgType* bindArgs = new CommandArgType[2];
+ bindArgs[0] = STR;
+ bindArgs[1] = STR_REST;
+ commandsModule.addCommand("bind", &KeybindsModule::bind, 2, bindArgs, this);
+ commandsModule.addCommand("exit", &KeybindsModule::exit, 0, {}, this);
+ commandsModule.addCommand("readBinds", &KeybindsModule::readBinds, 0, {}, this);
+ exitNow = false;
+}
+
+const void KeybindsModule::bind(const CommandArg* argv)
+{
+ Err e = commandsModule.checkCommand(argv[1].str);
+ if(e.code != NOERR)
+ {
+ e.message = "Binding fail - " + e.message;
+ throw e;
+ }
+ binds.insert({argv[0].str, argv[1].str});
+}
+const void KeybindsModule::readBinds(const CommandArg* argv)
+{
+ cout << "Reading binds" << endl;
+ while(exitNow == false)
+ {
+ string key;
+ cout << "> ";
+ std::getline(std::cin, key);
+ commandsModule.runCommand(binds.find(key)->second);
+ }
+}
+
+const void KeybindsModule::exit(const CommandArg* argv)
+{
+ exitNow = true;
+ cout << "Exiting..." << endl;
+}