menu-example.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #include "door.h"
  2. int main(int argc, char *argv[]) {
  3. door::Door door("example", argc, argv);
  4. // reset colors, clear screen.
  5. door << door::reset << door::cls << door::nl;
  6. door::Menu menu(10, 5, 25);
  7. menu.setColor(door::ANSIColor(door::COLOR::YELLOW, door::COLOR::BLUE,
  8. door::ATTR::BOLD)); // set border
  9. menu.setTitle(std::make_unique<door::Line>("Menu Example"), 1);
  10. int arrows = 15;
  11. door::updateFunction arrowsUpdate = [&arrows](void) -> std::string {
  12. std::string text = "Arrows (";
  13. text += std::to_string(arrows);
  14. text += " in stock)";
  15. return text;
  16. };
  17. menu.addSelection('A', "Arrows (0 in stock)", arrowsUpdate);
  18. menu.addSelection('C', "Color selection");
  19. menu.addSelection('P', "Pants");
  20. menu.addSelection('Q', "Quit");
  21. int r = 0;
  22. while (r >= 0) {
  23. menu.update();
  24. r = menu.choose(door);
  25. if (r > 0) {
  26. // we did not timeout
  27. char c = menu.which(r - 1);
  28. if (c == 'A') {
  29. if (arrows > 0)
  30. --arrows;
  31. else {
  32. door << door::Goto(1, 17) << door::reset
  33. << "Sorry, we're out of stock.";
  34. continue;
  35. }
  36. }
  37. door << door::Goto(1, 17) << door::reset << "You chose " << c << "!";
  38. if (c == 'Q')
  39. break;
  40. }
  41. }
  42. door << door::nl << "Returing to BBS... " << door::nl;
  43. }