diff options
Documented ConsoleInterface
1 files changed, 47 insertions, 2 deletions
| -rw-r--r-- | src/Generic/ConsoleInterface/Menu.cpp | 49 |
diff --git a/src/Generic/ConsoleInterface/Menu.cpp b/src/Generic/ConsoleInterface/Menu.cpp index d672540..3ab857e 100644 --- a/src/Generic/ConsoleInterface/Menu.cpp +++ b/src/Generic/ConsoleInterface/Menu.cpp @@ -4,17 +4,29 @@ Menu::Menu() : Menu("Menu", false, false) {} +/*! \param title C-style string, class stores at most 255 characters (last character is always terminating zero) + * \param backExistsApp Flag whether or not to list the 0-th option as "Exit", rather than "Go Back" + * \param isSubMenu Flag whether or not to show the title as a subTitle or not + */ Menu::Menu(const char* title, bool backExistsApp, bool isSubMenu) : menuOptions() { this->backExistsApp = backExistsApp; this->isSubMenu = isSubMenu; - strcpy(this->title, title); + strncpy(this->title, title, 255); + this->title[255] = '\0'; } +/*! \param title C-style string, class stores at most 255 characters (last character is always terminating zero) + * \param backExistsApp Flag whether or not to list the 0-th option as "Exit", rather than "Go Back" + * \param isSubMenu Flag whether or not to show the title as a subTitle or not + * \param commands Pointer to an array of Command instances + * \param commandCount Number of elements that "commands" points to + */ Menu::Menu(const char* title, bool backExistsApp, bool isSubMenu, const Command* commands, unsigned commandCount) { this->backExistsApp = backExistsApp; this->isSubMenu = isSubMenu; menuOptions = List<Command>(commands, commandCount); - strcpy(this->title, title); + strncpy(this->title, title, 255); + this->title[255] = '\0'; } void Menu::addCommand(const Command& command) { @@ -30,21 +42,54 @@ enum MessageType { const char* msg; MessageType msgType; +/*! \param message C-style string, saves to pointer for later reuse when showing the message. + * + * Stores the message pointer in a global variable (in the cpp file) and + * sets it's type as an Error in another global variable (in the cpp file). + * + * The next time the whole Menu is shown, the message will appear below the title. + */ void Menu::registerError(const char* message) const { msg = message; msgType = Error; } +/*! \param message C-style string, saves to pointer for later reuse when showing the message. + * + * Stores the message pointer in a global variable (in the cpp file) and + * sets it's type as a Warning in another global variable (in the cpp file). + * + * The next time the whole Menu is shown, the message will appear below the title. + */ void Menu::registerWarning(const char* message) const { msg = message; msgType = Warning; } +/*! \param message C-style string, saves to pointer for later reuse when showing the message. + * + * Stores the message pointer in a global variable (in the cpp file) and + * sets it's type as Success in another global variable (in the cpp file). + * + * The next time the whole Menu is shown, the message will appear below the title. + */ void Menu::registerSuccess(const char* message) const { msg = message; msgType = Success; } +/*! + * Prints the title, then an Error/Warning/Sucess message (if set), + * prints all command names as an ordered list (starting from 1), + * waits for user input to select one of those commands (by list number) + * and finally executes the appropriate command's run() function. + * + * After the run() function exists, everything is reprinted. + * The 0 list index is always "Go Back"/"Exit" and it always stops the reprinting loop. + * + * If there are no commands, prints "Menu is empty!". + * If user input doesn't correspond to any command, registers an error message and reprints. + */ void Menu::navigate() const { if (menuOptions.get_count() == 0) { printLine("Menu is empty!"); |
