Website Summary Files Commits Branches @commit @diff @stats
path: root / src / ConsoleInterface / Menu.cpp
blob: 669fb6c244f92a9f77e8b3b3551ddea745732b24 (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
#include "Menu.h"
#include "Toolbox.h"

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

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

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

	unsigned buffer = 0;
	while (0 == buffer || buffer >= menuOptions.get_count()) {
		std::cout << "Execute No [1-" << menuOptions.get_count() << "]: ";
		std::cin >> buffer;
	}

	menuOptions[buffer - 1].run();
}