|
pflib v3.9.0-rc3-11-g2537d8f
Pretty Fine HGCROC Interaction Library
|
Type-less menu base for common tasks. More...
#include <Menu.h>
Static Public Member Functions | |
| static void | set_history_filepath (std::string fp) |
| Decide where the filepath for reading/writing the history should be. | |
| static void | open_history () |
| open history and read from file (if it exists) | |
| static void | close_history () |
| close up history | |
| 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. | |
| 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. | |
| static std::string | readline (const std::string &prompt) |
| Read a string parameter without a default. | |
| static std::string | readline (const std::string &prompt, const std::vector< std::string > &opts, const std::string &def="") |
| Read a string parameter without a default but with the input list of options for tab-completion. | |
| static std::string | default_path (const std::string &name, const std::string &extension="") |
| Create a default path from the output directory and timestamp format parameters. | |
| static std::string | readline_path (const std::string &name, const std::string &extension="") |
| Read a path from the user using default_path to generate a default value. | |
| static int | readline_int (const std::string &prompt) |
| Read an integer parameter without a default. | |
| static int | readline_int (const std::string &prompt, int aval, bool ashex=false) |
| Read an integer parameter with a default. | |
| static double | readline_float (const std::string &prompt) |
| Read a float parameter with a default. | |
| static bool | readline_bool (const std::string &prompt, bool aval) |
| Read a bool parameter with a default. | |
| static std::string | readline_cmd () |
| Read a command from the menu. | |
| static void | add_to_command_queue (const std::string &str) |
| Add to the queue of commands to execute automatically. | |
Static Public Attributes | |
| static std::string | output_directory = "" |
| output directory to include in default path | |
| static std::string | timestamp_format = "_%Y%m%d_%H%M%S" |
| format of timestamp to append to default path | |
Protected Member Functions | |
| void | add_to_history (const std::string &cmd) const |
| Add a command to the history of commands that have been executed. | |
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_ |
| a pointer to the list of options when attempting readline completion | |
| ::pflib::logging::logger | the_log_ = ::pflib::logging::get("menu") |
Static Private Member Functions | |
| static char * | matcher (const char *text, int state) |
| matcher function following readline's function signature | |
Static Private Attributes | |
| static std::string | history_filepath_ = ".pflib-menu-history" |
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 |
|
static |
Create a default path from the output directory and timestamp format parameters.
| [in] | name | name to be included in output filename before timestamp |
| [in] | extension | extension of file including . |
|
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 |
open history and read from file (if it exists)
The history is stored at a file defined by set_history_filepath which is updated when the menu exits (either normally or with Ctrl+C).
|
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.
| [in] | prompt | Prompt string to the user |
| [in] | opts | list of options for tab completion of user entry |
| [in] | def | default value if user provides nothing |
|
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 |
|
static |
Read a path from the user using default_path to generate a default value.
The prompt is "Filename: " if an extension is given or "Filename (no extension):" if not. The arguments are then passed on to BaseMenu::default_path to create a default path for the user to confirm or rewrite if they desire.
|
staticprotected |
a pointer to the list of options when attempting readline completion
|
static |
format of timestamp to append to default path
The maximum size of the resulting timestamp is 64 characters, which should be more than enough. A complete specification of time down to the second is 14 characters, so this gives you the ability to add 50 characters of separators and other suffix-related things.