Website Summary Files Commits Branches @commit @diff @stats
path: root / src / ConsoleInterface / Menu.cpp
blob: bf746e4717a0506a736d409d3ab28770c35dad9f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include "Menu.h"
#include "Toolbox.hpp"

Menu::Menu() : menuOptions() {}

Menu::Menu(const Command* commands, unsigned commandCount) {
	menuOptions = List<Command>(commands, commandCount);
}

void Menu::addCommand(const Command& command) {
	menuOptions.add(command);
}

void Menu::navigate() const {
	if (menuOptions.get_count() == 0) {
		printLine("Menu is empty!");
		return;
	}

	resetOrderedList(0);
	printOrderedListElem("Go Back");
	for (unsigned i = 0; i < menuOptions.get_count(); i++)
		printOrderedListElem(menuOptions[i].get_nameInMenu());

	unsigned buffer = 0; // 0 is optionless continue, 1 is exit, others are options

	while (buffer != 1) {
		print("Execute No [0-");
		print(menuOptions.get_count());
		print("]: ");
		read(buffer);

		if (++buffer > 0)
			menuOptions[buffer - 1].run();
	}
}