Website Summary Files Commits Branches @commit @diff @stats
path: root / src / Generic / ConsoleInterface / Menu.h
diff options
context:
space:
mode:
Commit3098e987d83a7fa2ea33e66b901e6941233a9879 (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-05-28 09:33:26 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-05-28 09:33:26 +0300
Files8fe54cd3f7c29b24b822762d7249e6310ae97d6a /src/Generic/ConsoleInterface/Menu.h
FMI-OOP-P2_Tables-3098e987d83a7fa2ea33e66b901e6941233a9879.tar
FMI-OOP-P2_Tables-3098e987d83a7fa2ea33e66b901e6941233a9879.tar.gz
FMI-OOP-P2_Tables-3098e987d83a7fa2ea33e66b901e6941233a9879.zip
Parent12df7aa3b9ec4bc6d9b74ae86ef0248d049f8785 (diff)
Added generic stuff from previous project
1 files changed, 46 insertions, 0 deletions
-rw-r--r--src/Generic/ConsoleInterface/Menu.h46
diff --git a/src/Generic/ConsoleInterface/Menu.h b/src/Generic/ConsoleInterface/Menu.h
new file mode 100644
index 0000000..e0ea685
--- /dev/null
+++ b/src/Generic/ConsoleInterface/Menu.h
@@ -0,0 +1,46 @@
+#ifndef HEADER_CONSOLEINTERFACE_MENU
+#define HEADER_CONSOLEINTERFACE_MENU
+
+/*! \file Menu.h
+ * \brief Stores the declaration of class Menu
+ */
+
+#include "Command.h"
+#include "../List/List.hpp"
+
+/*! \brief Handles navigation between multiple commands
+ *
+ * Shows the title, then below it an Error/Warning/Success message if set,
+ * lists all command options as an enumerated list, takes command index
+ * 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;
+
+ //! Lists commands and after user input executes an appropriate command run() function
+ void navigate() const;
+};
+
+#endif