Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / ConsoleInterface / Menu.cpp
diff options
context:
space:
mode:
Commitacbf9eba57c6531a1589a6f72062a67e11e9f76e (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 20:35:09 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 20:35:09 +0300
Filesdc967e82735b6d695abe1a9a9e9d499458531f79 /src/Generic/ConsoleInterface/Menu.cpp
FMI-OOP-P2_Tables-acbf9eba57c6531a1589a6f72062a67e11e9f76e.tar
FMI-OOP-P2_Tables-acbf9eba57c6531a1589a6f72062a67e11e9f76e.tar.gz
FMI-OOP-P2_Tables-acbf9eba57c6531a1589a6f72062a67e11e9f76e.zip
Parent49e3e3737c1f26846ef443f2621bbc2a552184c9 (diff)
Autocommit at 28.05.2022 @ 20:35
1 files changed, 10 insertions, 3 deletions
-rw-r--r--src/Generic/ConsoleInterface/Menu.cpp13
diff --git a/src/Generic/ConsoleInterface/Menu.cpp b/src/Generic/ConsoleInterface/Menu.cpp
index c053f93..32f5104 100644
--- a/src/Generic/ConsoleInterface/Menu.cpp
+++ b/src/Generic/ConsoleInterface/Menu.cpp
@@ -10,6 +10,10 @@ unsigned indexOfCommandEnd(char* str) {
return ind;
}
+void Menu::addCommand(const Command& command) {
+ menuOptions.add(command);
+}
+
/*!
* Prints the title, then an Error/Warning/Sucess message (if set),
* prints all command names as an ordered list (starting from 1),
@@ -29,16 +33,19 @@ void Menu::navigate() const {
}
char buffer[MAX_LINE_WIDTH];
+ unsigned startIndex = 0;
while (strncmp(buffer, "quit", 4) != 0) {
clear();
+ startIndex = 0;
inputLineBox("> ", buffer, MAX_LINE_WIDTH);
- while (*buffer == ' ') buffer++;
+ while (buffer[startIndex] == ' ') startIndex++;
+
unsigned commandEnd = indexOfCommandEnd(buffer),
index = menuOptions.get_count();
for (unsigned i = 0; i < menuOptions.get_count(); i++) {
- if (strncmp(buffer, menuOptions[i].get_name(), commandEnd) == 0) {
+ if (strncmp(buffer + startIndex, menuOptions[i].get_name(), commandEnd) == 0) {
index = i;
break;
}
@@ -49,6 +56,6 @@ void Menu::navigate() const {
continue;
}
- menuOptions[index].run(buffer + commandEnd);
+ menuOptions[index].run(buffer + startIndex + commandEnd);
}
}