Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / ConsoleInterface
diff options
context:
space:
mode:
Commitd01238def9403291528436aae7f0be9bcc8a921c (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 20:10:00 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 20:10:00 +0300
Files3bfc27361a0abef06498a0ca52da2911b23a36bc /src/Generic/ConsoleInterface
FMI-OOP-P2_Tables-d01238def9403291528436aae7f0be9bcc8a921c.tar
FMI-OOP-P2_Tables-d01238def9403291528436aae7f0be9bcc8a921c.tar.gz
FMI-OOP-P2_Tables-d01238def9403291528436aae7f0be9bcc8a921c.zip
Parent7ea8801641356bcc6d564b96e27ebb06527a479b (diff)
Autocommit at 28.05.2022 @ 20:10
2 files changed, 5 insertions, 105 deletions
-rw-r--r--src/Generic/ConsoleInterface/Menu.cpp90
-rw-r--r--src/Generic/ConsoleInterface/Menu.h20
diff --git a/src/Generic/ConsoleInterface/Menu.cpp b/src/Generic/ConsoleInterface/Menu.cpp
index 3ab857e..39084a1 100644
--- a/src/Generic/ConsoleInterface/Menu.cpp
+++ b/src/Generic/ConsoleInterface/Menu.cpp
@@ -2,81 +2,7 @@
#include "Toolbox.hpp"
#include <cstring>
-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;
- 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);
- strncpy(this->title, title, 255);
- this->title[255] = '\0';
-}
-
-void Menu::addCommand(const Command& command) {
- menuOptions.add(command);
-}
-
-enum MessageType {
- NoPrint,
- Success,
- Warning,
- Error,
-};
-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;
-}
+Menu::Menu() : menuOptions() {}
/*!
* Prints the title, then an Error/Warning/Sucess message (if set),
@@ -100,18 +26,8 @@ void Menu::navigate() const {
while (buffer != 0) {
clear();
- if (isSubMenu)
- subTitleBox(title);
- else
- titleBox(title);
-
- switch(msgType) {
- case Error: errorBox(msg); msgType = NoPrint; break;
- case Warning: warningBox(msg); msgType = NoPrint; break;
- case Success: successBox(msg); msgType = NoPrint; break;
- case NoPrint: printLine(""); break;
- }
- printLine("");
+ print("> ");
+ readLine();
resetOrderedList(0);
if (backExistsApp)
diff --git a/src/Generic/ConsoleInterface/Menu.h b/src/Generic/ConsoleInterface/Menu.h
index e0ea685..68037df 100644
--- a/src/Generic/ConsoleInterface/Menu.h
+++ b/src/Generic/ConsoleInterface/Menu.h
@@ -15,29 +15,13 @@
* and calls the chosen command's run() function.
*/
class Menu {
- char title[256];
List<Command> menuOptions;
- bool backExistsApp;
- bool isSubMenu;
-
public:
//! Sets name as "Menu", leaves all flags to false and creates an empty Command list
Menu();
- //! Copies title, saves flags and creates and empty Command list
- Menu(const char* title, bool backExistsApp, bool isSubMenu);
- //! Copies title, saves flags and copies commands
- Menu(const char* title, bool backExistsApp, bool isSubMenu, const Command* commands, unsigned commandCount);
-
- //! Adds a command to the internal Command list
- void addCommand(const Command& command);
-
- //! Tell Menu to show an error message next time it prints
- void registerError(const char* message) const;
- //! Tell Menu to show a warning message next time it prints
- void registerWarning(const char* message) const;
- //! Tell Menu to show a success message next time it prints
- void registerSuccess(const char* message) const;
+ //! Copies commands
+ Menu(const Command* commands, unsigned commandCount);
//! Lists commands and after user input executes an appropriate command run() function
void navigate() const;