diff options
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)); + +} |
