This commit is contained in:
2025-09-20 17:57:56 -05:00
parent a896b772fb
commit 90c3b6149e
16 changed files with 469 additions and 74 deletions

View File

@@ -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) {
}