Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / ConsoleInterface / Menu.cpp
diff options
context:
space:
mode:
Commit7b72e6a872a82450796d7da65a290bab9c100ae3 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 20:25:05 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 20:25:05 +0300
Files6cccbd464955cbd13d6eee92e5ed5dc880e7db60 /src/Generic/ConsoleInterface/Menu.cpp
FMI-OOP-P2_Tables-7b72e6a872a82450796d7da65a290bab9c100ae3.tar
FMI-OOP-P2_Tables-7b72e6a872a82450796d7da65a290bab9c100ae3.tar.gz
FMI-OOP-P2_Tables-7b72e6a872a82450796d7da65a290bab9c100ae3.zip
Parentf3671d418a098f1fd7aa530b2ef6c975193fce1f (diff)
Autocommit at 28.05.2022 @ 20:25
1 files changed, 12 insertions, 5 deletions
-rw-r--r--src/Generic/ConsoleInterface/Menu.cpp17
diff --git a/src/Generic/ConsoleInterface/Menu.cpp b/src/Generic/ConsoleInterface/Menu.cpp
index 16032eb..69bb7b9 100644
--- a/src/Generic/ConsoleInterface/Menu.cpp
+++ b/src/Generic/ConsoleInterface/Menu.cpp
@@ -4,6 +4,13 @@
Menu::Menu() : menuOptions() {}
+unsigned indexOfCommandEnd(char*& str) {
+ while (*str == ' ') str++;
+ unsigned ind = 0;
+ while (str[ind] != ' ') ind++;
+ return ind;
+}
+
/*!
* Prints the title, then an Error/Warning/Sucess message (if set),
* prints all command names as an ordered list (starting from 1),
@@ -28,20 +35,20 @@ void Menu::navigate() const {
clear();
inputLineBox("> ", buffer, MAX_LINE_WIDTH);
- unsigned index = menuOptions.get_count();
+ unsigned commandEnd = indexOfCommandEnd(buffer),
+ index = menuOptions.get_count();
for (unsigned i = 0; i < menuOptions.get_count(); i++) {
- if (strncmp(buffer, menuOptions[i].get_nameInMenu(), MAX_LINE_WIDTH) == 0) {
+ if (strncmp(buffer, menuOptions[i].get_name(), commandEnd) == 0) {
index = i;
break;
}
}
if (index > menuOptions.get_count()) {
- printline("Invalid menu option!");
+ printLine("Invalid menu option!");
continue;
}
-
- menuOptions[index].run();
+ menuOptions[index].run(buffer + commandEnd);
}
}