Bugz Door Project
menu-example.cpp

Example using menusThis example shows a menu, and demonstrates the new menu update ability.

#include "door.h"
int main(int argc, char *argv[]) {
door::Door door("example", argc, argv);
// reset colors, clear screen.
door::Menu menu(10, 5, 25);
door::ATTR::BOLD)); // set border
menu.setTitle(std::make_unique<door::Line>("Menu Example"), 1);
int arrows = 15;
door::updateFunction arrowsUpdate = [&arrows](void) -> std::string {
std::string text = "Arrows (";
text += std::to_string(arrows);
text += " in stock)";
return text;
};
menu.addSelection('A', "Arrows (0 in stock)", arrowsUpdate);
menu.addSelection('C', "Color selection");
menu.addSelection('P', "Pants");
menu.addSelection('Q', "Quit");
int r = 0;
while (r >= 0) {
menu.update();
r = menu.choose(door);
if (r > 0) {
// we did not timeout
char c = menu.which(r - 1);
if (c == 'A') {
if (arrows > 0)
--arrows;
else {
<< "Sorry, we're out of stock.";
continue;
}
}
door << door::Goto(1, 17) << door::reset << "You chose " << c << "!";
if (c == 'Q')
break;
}
}
door << door::nl << "Returing to BBS... " << door::nl;
}
door::Goto
ANSI Goto X, Y position.
Definition: door.h:425
door::Door
Definition: door.h:190
door::ATTR::BOLD
@ BOLD
BOLD is the same as BRIGHT.
door::ANSIColor
Foreground, Background and Attributes.
Definition: door.h:137
door::Menu
Definition: door.h:686
door::cls
Clrscr cls
Definition: door.cpp:1352
door::updateFunction
std::function< std::string(void)> updateFunction
Definition: door.h:374
door::nl
NewLine nl
Definition: door.cpp:1380
door::Panel::update
bool update(Door &d)
Updates a panel.
Definition: panel.cpp:273
door::COLOR::YELLOW
@ YELLOW
YELLOW (3)
door::reset
ANSIColor reset(ATTR::RESET)
reset colors to normal
Definition: door.h:414
door
The BBS door project. This is an attempt at writing a C++ BBS door toolkit.
Definition: ansicolor.cpp:9
door::Menu::choose
int choose(Door &door)
Definition: panel.cpp:757
door::COLOR::BLUE
@ BLUE
BLUE (4)