diff options
Autocommit at 05.05.2022 @ 21:29
4 files changed, 36 insertions, 20 deletions
| -rw-r--r-- | src/ConsoleInterface/Menu.cpp | 28 | ||||
| -rw-r--r-- | src/ConsoleInterface/Menu.h | 7 | ||||
| -rw-r--r-- | src/ConsoleInterface/Toolbox.cpp | 10 | ||||
| -rw-r--r-- | src/ConsoleInterface/Toolbox.hpp | 11 |
diff --git a/src/ConsoleInterface/Menu.cpp b/src/ConsoleInterface/Menu.cpp index beb69c2..caba7e8 100644 --- a/src/ConsoleInterface/Menu.cpp +++ b/src/ConsoleInterface/Menu.cpp @@ -2,13 +2,17 @@ #include "Toolbox.hpp" #include <cstring> -Menu::Menu() : Menu("Menu") {} +Menu::Menu() : Menu("Menu", false, false) {} -Menu::Menu(const char* title) : menuOptions() { +Menu::Menu(const char* title, bool backExistsApp, bool isSubMenu) : menuOptions() { + this->backExistsApp = backExistsApp; + this->isSubMenu = isSubMenu; strcpy(this->title, title); } -Menu::Menu(const char* title, const Command* commands, unsigned commandCount) { +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); } @@ -51,17 +55,25 @@ void Menu::navigate() const { while (buffer != 0) { clear(); - title(title); + if (isSubMenu) + subTitleBox(title); + else + titleBox(title); + switch(msgType) { - case Error: error(msg.get_cstr()); msgType = NoPrint; break; - case Warning: warning(msg.get_cstr()); msgType = NoPrint; break; - case Success: success(msg.get_cstr()); msgType = NoPrint; break; + case Error: errorBox(msg.get_cstr()); msgType = NoPrint; break; + case Warning: warningBox(msg.get_cstr()); msgType = NoPrint; break; + case Success: successBox(msg.get_cstr()); msgType = NoPrint; break; case NoPrint: printLine(""); break; } printLine(""); resetOrderedList(0); - printOrderedListElem("Go Back"); + if (backExistsApp) + printOrderedListElem("Exit"); + else + printOrderedListElem("Go Back"); + for (unsigned i = 0; i < menuOptions.get_count(); i++) printOrderedListElem(menuOptions[i].get_nameInMenu()); diff --git a/src/ConsoleInterface/Menu.h b/src/ConsoleInterface/Menu.h index bdfb602..2501871 100644 --- a/src/ConsoleInterface/Menu.h +++ b/src/ConsoleInterface/Menu.h @@ -8,10 +8,13 @@ class Menu { char title[256]; List<Command> menuOptions; + bool backExistsApp; + bool isSubMenu; + public: Menu(); - Menu(const char* title); - Menu(const char* title, const Command* commands, unsigned commandCount); + Menu(const char* title, bool backExistsApp, bool isSubMenu); + Menu(const char* title, bool backExistsApp, bool isSubMenu, const Command* commands, unsigned commandCount); void addCommand(const Command& command); diff --git a/src/ConsoleInterface/Toolbox.cpp b/src/ConsoleInterface/Toolbox.cpp index ea291bd..6dca150 100644 --- a/src/ConsoleInterface/Toolbox.cpp +++ b/src/ConsoleInterface/Toolbox.cpp @@ -30,23 +30,23 @@ void inputLineBox(const char* label, char* output, unsigned maxWidth) { std::cin.getline(output, maxWidth); } -void title(const char* title) { +void titleBox(const char* title) { std::cout << std::endl << "### " << title << " ###" << std::endl; } -void printSubTitle(const char* title) { +void subTitleBox(const char* title) { std::cout << std::endl << "+#+ " << title << " +#+" << std::endl; } -void success(const char* message) { +void successBox(const char* message) { std::cout << "<S> " << message << std::endl; } -void warning(const char* message) { +void warningBox(const char* message) { std::cout << "<W> " << message << std::endl; } -void error(const char* message) { +void errorBox(const char* message) { std::cout << "<E> " << message << std::endl; } diff --git a/src/ConsoleInterface/Toolbox.hpp b/src/ConsoleInterface/Toolbox.hpp index 2398abc..bb79b9e 100644 --- a/src/ConsoleInterface/Toolbox.hpp +++ b/src/ConsoleInterface/Toolbox.hpp @@ -7,11 +7,12 @@ #define MAX_LINE_WIDTH 1024 void clear(); -void title(const char* title); -void printSubTitle(const char* title); -void success(const char* message); -void warning(const char* message); -void error(const char* message); +void titleBox(const char* title); +void subTitleBox(const char* title); + +void successBox(const char* message); +void warningBox(const char* message); +void errorBox(const char* message); void inputLineBox(const char* label, char* output, unsigned maxWidth); void resetOrderedList(int starter = 1); |
