1#ifndef PFLIB_TOOL_MENU_H
2#define PFLIB_TOOL_MENU_H
14#include "pflib/Exception.h"
15#include "pflib/logging/Logging.h"
17namespace pflib::menu {
67 bool preserve_last_blank =
false);
229 static ::pflib::logging::logger the_log_;
246 static char*
matcher(
const char* text,
int state);
308 unsigned int category = 0) {
309 lines_.emplace_back(name, desc, ex, category);
328 unsigned int category = 0) {
329 lines_.emplace_back(name, desc, ex, category);
355 unsigned int category = 0) {
357 lines_.emplace_back(name, desc, sb, category);
379 lines_.emplace_back(
"EXIT",
"leave this menu");
380 lines_.emplace_back(
"HELP",
"print help for this menu",
382 lines_.emplace_back(
"PWD",
"print current menu path",
384 pflib_log(info) <<
"Current menu: ";
416 const char* name =
"",
Menu* parent =
nullptr)
423 void hide(
unsigned int categories) {
434 for (
const auto& l :
lines_) {
468 for (
const auto& l :
lines_) {
519 const Line* theMatch = 0;
525 for (
size_t i = 0; i <
lines_.size(); i++)
526 if (strcasecmp(request.
c_str(),
lines_[i].name()) == 0) {
530 if (nmatch > 1) theMatch = 0;
533 printf(
" Command '%s' not understood.\n\n", request.
c_str());
536 if (theMatch->
execute(p_target)) {
541 }
while (theMatch == 0 or not theMatch->
empty());
585 unsigned int category = 0) {
586 return root()->
submenu(name, desc, render_func, category);
598 for (
const auto& l :
lines_) {
656 Line(
const char* n,
const char* d)
688 pflib_log(error) <<
"[" << e.
name() <<
"] : " << e.
message();
690 pflib_log(error) <<
"Unknown Exception " << e.
what();
716 void hide(
unsigned int categories) {
PFlib.
Definition Exception.h:12
const std::string & message() const
Get the message of the exception.
Definition Exception.h:52
virtual const char * what() const
The error message.
Definition Exception.h:76
const std::string & name() const
Get the name of the exception.
Definition Exception.h:46