diff options
| Commit | acbf9eba57c6531a1589a6f72062a67e11e9f76e (patch) | |
|---|---|---|
| Author | 2022-05-28 20:35:09 +0300 | |
| Committer | 2022-05-28 20:35:09 +0300 | |
| Files | dc967e82735b6d695abe1a9a9e9d499458531f79 /src | |
| FMI-OOP-P2_Tables-acbf9eba57c6531a1589a6f72062a67e11e9f76e.tar FMI-OOP-P2_Tables-acbf9eba57c6531a1589a6f72062a67e11e9f76e.tar.gz FMI-OOP-P2_Tables-acbf9eba57c6531a1589a6f72062a67e11e9f76e.zip | ||
| Parent | 49e3e3737c1f26846ef443f2621bbc2a552184c9 (diff) | |
Autocommit at 28.05.2022 @ 20:35
3 files changed, 19 insertions, 3 deletions
| -rw-r--r-- | src/Generic/ConsoleInterface/Menu.cpp | 13 | ||||
| -rw-r--r-- | src/Generic/ConsoleInterface/Menu.h | 3 | ||||
| -rw-r--r-- | src/UserInterface/UserInterface.cpp | 6 |
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); } } diff --git a/src/Generic/ConsoleInterface/Menu.h b/src/Generic/ConsoleInterface/Menu.h index 68037df..faadba9 100644 --- a/src/Generic/ConsoleInterface/Menu.h +++ b/src/Generic/ConsoleInterface/Menu.h @@ -23,6 +23,9 @@ public: //! Copies commands Menu(const Command* commands, unsigned commandCount); + //! Adds a command to the internal Command list + void addCommand(const Command& command); + //! Lists commands and after user input executes an appropriate command run() function void navigate() const; }; diff --git a/src/UserInterface/UserInterface.cpp b/src/UserInterface/UserInterface.cpp new file mode 100644 index 0000000..2faeb84 --- /dev/null +++ b/src/UserInterface/UserInterface.cpp @@ -0,0 +1,6 @@ +#include "UserInterface.h" + +UserInterface::UserInterface(Table& table) : table(table), menu() { + menu.addCommand(Command("print", com_print)); + +} |
