pflib v2.7.0-1-gd371ab6a
Polarfire Interaction Library
|
Type-less menu base for common tasks. More...
#include <Menu.h>
Static Public Member Functions | |
static std::string | readline (const std::string &prompt, const std::string &defval, bool preserve_last_blank=false) |
Read in a parameter using the default value if nothing provided. More... | |
static std::string | readline_nosplit (const std::string &prompt, const std::string &defval) |
Get a raw input value without the additional splitting and modifications done in base readline. More... | |
static std::string | readline (const std::string &prompt) |
Read a string parameter without a default. More... | |
static std::string | readline (const std::string &prompt, const std::vector< std::string > &opts) |
Read a string parameter without a default but with the input list of options for tab-completion (and validation) More... | |
static int | readline_int (const std::string &prompt) |
Read an integer parameter without a default. More... | |
static int | readline_int (const std::string &prompt, int aval) |
Read an integer parameter with a default. More... | |
static double | readline_float (const std::string &prompt) |
Read a float parameter with a default. More... | |
static bool | readline_bool (const std::string &prompt, bool aval) |
Read a bool parameter with a default. More... | |
static std::string | readline_cmd () |
Read a command from the menu. More... | |
static void | add_to_command_queue (const std::string &str) |
Add to the queue of commands to execute automatically. More... | |
Protected Member Functions | |
void | add_to_history (const std::string &cmd) const |
Add a command to the history of commands that have been executed. More... | |
Static Protected Attributes | |
static std::list< std::string > | cmdTextQueue_ |
the ordered list of commands to be executed from a script file | |
static std::vector< std::string > | cmd_options_ |
the current command options (for interfacing with readline's tab completion) | |
static const std::vector< std::string > * | rl_comp_opts_ = &BaseMenu::cmd_options_ |
a pointer to the list of options when attempting readline completion | |
Static Private Member Functions | |
static char * | matcher (const char *text, int state) |
matcher function following readline's function signature More... | |
Type-less menu base for common tasks.
This base menu class handles most of the interaction with the GNU readline library. This includes some helper commands for obtaining parameters via readline and keeping command history.
|
static |
Add to the queue of commands to execute automatically.
[in] | str | command to add into the queue |
|
protected |
Add a command to the history of commands that have been executed.
Uses readline's add_to_history.
[in] | cmd | Command string that was executed |
|
staticprivate |
matcher function following readline's function signature
We get the command options from the BaseMenu::rl_comp_opts_ which is determined by the Menu::command_options function at the beginning of Menu::steer or after leaving a sub-menu.
We check for matching with strncasecmp so that the tab completion is also case-insensitive (same as the menu selection itself).
[in] | text | the text to potentionally match |
[in] | state | 0 if first call, incrementing otherwise |
|
static |
Read a string parameter without a default.
[in] | prompt | The informing the user what the parameter is |
|
static |
Read in a parameter using the default value if nothing provided.
Expands '~' into $HOME within strings.
If the cmdTextQueue is not empty, then it uses the next command in that list rather than keyboard input. This leads to the effect that executables using this menu can provide an "initialization script" of commands by registering them in order with the BaseMenu::add_to_command_queue before launching the menu.
[in] | prompt | The informing the user what the parameter is |
[in] | defval | default value if user does not provide anything |
[in] | preserve_last_blank | keep whitespace at end of input |
|
static |
Read a string parameter without a default but with the input list of options for tab-completion (and validation)
[in] | prompt | The informing the user what the parameter is |
|
static |
Read a bool parameter with a default.
The characters y, Y, 1, t, and T are accepted as equivalent to "true" while all others are equivalent to "false". The prompt should be in the form of a yes/no question since the string ' [Y/N]' is appended to it before passing along.
[in] | prompt | The informing the user what the parameter is |
[in] | defval | default value if user does not provide anything |
|
static |
Read a command from the menu.
We use the prompt ' > ' before the command and we wrap the underlying readline call with the setup/teardown of the TAB-completion function that readline calls if the user presses TAB.
|
static |
Read a float parameter with a default.
Uses string readline and then converts the output string into a float using atof.
[in] | prompt | The informing the user what the parameter is |
[in] | defval | default value if user does not provide anything |
|
static |
Read an integer parameter without a default.
Uses string readline and then converts the output string into a integer using stol.
[in] | prompt | The informing the user what the parameter is |
|
static |
Read an integer parameter with a default.
Uses string readline and then converts the output string into a integer using stol.
[in] | prompt | The informing the user what the parameter is |
[in] | defval | default value if user does not provide anything |
|
static |
Get a raw input value without the additional splitting and modifications done in base readline.
[in] | prompt | The informing the user what the parameter is |
[in] | defval | default value if user does not provide anything |