summaryrefslogtreecommitdiff
path: root/keybinds.cpp
blob: 57f7003702e5937abfce52f713e7d4574c4ab81d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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;
}