diff options
Autocommit at 28.05.2022 @ 20:30
3 files changed, 12 insertions, 12 deletions
| -rw-r--r-- | src/Generic/ConsoleInterface/Command.cpp | 16 | ||||
| -rw-r--r-- | src/Generic/ConsoleInterface/Command.h | 2 | ||||
| -rw-r--r-- | src/Generic/ConsoleInterface/Menu.cpp | 6 |
diff --git a/src/Generic/ConsoleInterface/Command.cpp b/src/Generic/ConsoleInterface/Command.cpp index c14bcc8..d05dc8d 100644 --- a/src/Generic/ConsoleInterface/Command.cpp +++ b/src/Generic/ConsoleInterface/Command.cpp @@ -3,22 +3,22 @@ Command::Command() : Command("", nullptr) {} -/*! \param nameInMenu C-style string, class stores at most 255 characters (last character is always terminating zero) +/*! \param name C-style string, class stores at most 255 characters (last character is always terminating zero) * \param exec Function pointer that will be executed when run() is called. Can be nullptr. */ -Command::Command(const char* nameInMenu, void (*exec)()) { - strncpy(this->nameInMenu, nameInMenu, 255); - this->nameInMenu[255] = '\0'; +Command::Command(const char* name, void (*exec)(const char* params)) { + strncpy(this->name, name, 255); + this->name[255] = '\0'; this->exec = exec; } /*! Executes the stored function pointer, when it's not nullptr. Otherwise does nothing. */ -void Command::run() const { +void Command::run(const char* params) const { if (exec != nullptr) - exec(); + exec(params); } -const char* Command::get_nameInMenu() const { - return nameInMenu; +const char* Command::get_name() const { + return name; } diff --git a/src/Generic/ConsoleInterface/Command.h b/src/Generic/ConsoleInterface/Command.h index 8e40955..393d705 100644 --- a/src/Generic/ConsoleInterface/Command.h +++ b/src/Generic/ConsoleInterface/Command.h @@ -19,7 +19,7 @@ public: //! Copies contents of nameInMenu and stores exec Command(const char* name, void (*exec)(const char* params)); //! Executes the stored function pointer - void run() const; + void run(const char* params) const; const char* get_name() const; }; diff --git a/src/Generic/ConsoleInterface/Menu.cpp b/src/Generic/ConsoleInterface/Menu.cpp index 69bb7b9..c053f93 100644 --- a/src/Generic/ConsoleInterface/Menu.cpp +++ b/src/Generic/ConsoleInterface/Menu.cpp @@ -4,8 +4,7 @@ Menu::Menu() : menuOptions() {} -unsigned indexOfCommandEnd(char*& str) { - while (*str == ' ') str++; +unsigned indexOfCommandEnd(char* str) { unsigned ind = 0; while (str[ind] != ' ') ind++; return ind; @@ -31,10 +30,11 @@ void Menu::navigate() const { char buffer[MAX_LINE_WIDTH]; - while (buffer != 0) { + while (strncmp(buffer, "quit", 4) != 0) { clear(); inputLineBox("> ", buffer, MAX_LINE_WIDTH); + while (*buffer == ' ') buffer++; unsigned commandEnd = indexOfCommandEnd(buffer), index = menuOptions.get_count(); for (unsigned i = 0; i < menuOptions.get_count(); i++) { |
