Interactively Retrieve User Input
Different functions used in different contexts to capture user input.
more advanced and allow evaluation of arbitrary expressions, in addition to
searching for specific commands such as "Y", "N", etc.
only matches along specified values.
unitizer_prompt(text, browse.env = baseenv(), help = character(), help.opts = character(), valid.opts, hist.con = NULL, exit.condition = function(exp, env) FALSE, global, ...)
navigate_prompt(x, curr.id, text, browse.env1 = globalenv(), browse.env2 = globalenv(), help = character(), help.opts = character(), valid.opts)
simple_prompt(message, values = c("Y", "N"), prompt = "unitizer> ", attempts = 5L, case.sensitive = FALSE)
exit_fun(y, env, valid.vals)
read_line(prompt = "")
the prompt text to display
the environment to evaluate user expressions in; typically this will contain interesting objects (use
a character vector with help suggestions: the first value in the vector is
word_catoutput, the rest normal
a character vector of help options
the special letters user can type to get a special action, typically a character vector where the names are one letter (though they don't actually have to be) and are looked for as user typed input; note that the quit and help options will always be appended to this
connection to save history to
function used to evaluate whether user input should cause the prompt loop to exit; this function should accept two parameters:
expression typed in by the user
environment the environment user expressions get evaluated in
The function can then decide to exit or not based on either the literal expression or evaluate the expression and decide based on the result. This is implemented this way because
eval_user_expwill print to screen which may not be desirable. Function should return a value which will then be returned by
unitizer_prompt, unless this value is
FALSEin which case
unitizer_promptwill continue with normal evaluation.
unitizerGlobal or NULL, if the global state tracking object; will be used to record state after evaluating user expressions
additional arguments for
a unitizerBrowse object
which id we are currently browsing
environment to have user review tests, run commands, etc
character ask the user a question
character valid responses
how many times to try before erroring
whether to care about case sensitivity when matching user input
The set-up is intended to replicate something similar to what happens when
code hits a
browse() statement. User expressions are evaluated
and output to screen, and special expressions as described above cause the
evaluation loop to terminate.
navigate_prompt is just a wrapper around
provides the special shortcuts to navigate to other tests in the
review_prompt is also a wrapper, but used only when at the menu that
presents available test items to navigate to.
simple_prompt simpler prompting function used to allow user to select
from pre-specified values.
exit_fun is used as a generic function to pass to the
exit.condition argument of
read_line_set_vals are utility functions that
are used to implement a version of
readline that can be
automated for testing.
interactive_mode returns interactive status, accounting for whether
we are in faux-interactive mode as set by
unitizer_prompt: mixed allowable user input
unitizerBrowseobject, or allowable user input
unitizerBrowseobject, or "Q" if the user chose to quit
simple_prompt: one of
valuesas selected by user