Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / ConsoleInterface
diff options
context:
space:
mode:
Commit49e3e3737c1f26846ef443f2621bbc2a552184c9 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 20:30:07 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 20:30:07 +0300
Filesb2160e1c62d3e810d9270f37c9ac9b2d66f7121f /src/Generic/ConsoleInterface
FMI-OOP-P2_Tables-49e3e3737c1f26846ef443f2621bbc2a552184c9.tar
FMI-OOP-P2_Tables-49e3e3737c1f26846ef443f2621bbc2a552184c9.tar.gz
FMI-OOP-P2_Tables-49e3e3737c1f26846ef443f2621bbc2a552184c9.zip
Parent7b72e6a872a82450796d7da65a290bab9c100ae3 (diff)
Autocommit at 28.05.2022 @ 20:30
3 files changed, 12 insertions, 12 deletions
-rw-r--r--src/Generic/ConsoleInterface/Command.cpp16
-rw-r--r--src/Generic/ConsoleInterface/Command.h2
-rw-r--r--src/Generic/ConsoleInterface/Menu.cpp6
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++) {