Input
This commit is contained in:
@@ -13,16 +13,23 @@ Console::Console(void) :
|
||||
variables(),
|
||||
buffer()
|
||||
{
|
||||
this->registerCommand("echo", [](auto console, auto args) {
|
||||
if(args.size() == 0) {
|
||||
console.print("Usage: echo <message>");
|
||||
return;
|
||||
}
|
||||
console.print("%s", args[0].c_str());
|
||||
});
|
||||
}
|
||||
|
||||
void Console::registerCommand(
|
||||
const std::string &cmd,
|
||||
const std::function<void(std::vector<std::string>&)> &callback
|
||||
const std::function<void(Console&, const std::vector<std::string>&)> &cb
|
||||
) {
|
||||
assertTrue(cmd.length() > 0, "cmd length must be > 0");
|
||||
assertTrue(callback != nullptr, "callback must not be null");
|
||||
assertTrue(cb != nullptr, "callback must not be null");
|
||||
|
||||
this->commands[cmd] = callback;
|
||||
this->commands[cmd] = cb;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
@@ -121,7 +128,7 @@ void Console::update() {
|
||||
printf("Console: Variable '%s' ", cmdName.c_str());
|
||||
continue;
|
||||
}
|
||||
itCmd->second(args);
|
||||
itCmd->second(*this, args);
|
||||
}
|
||||
buffer.clear();
|
||||
}
|
||||
@@ -141,6 +148,20 @@ void Console::exec(const std::string &str) {
|
||||
}
|
||||
}
|
||||
|
||||
void Console::print(const char_t *fmt, ...) {
|
||||
va_list args;
|
||||
va_start(args, fmt);
|
||||
|
||||
vprintf(fmt, args);
|
||||
printf("\n");
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
void Console::print(std::string str) {
|
||||
this->print("%s", str.c_str());
|
||||
}
|
||||
|
||||
Console::~Console(void) {
|
||||
|
||||
}
|
Reference in New Issue
Block a user