Description Usage Arguments Details Value See Also Examples
This function allows you to interact with a user by posing questions that
accept text input. It's inspired by usethis::ui_yeah()
and
shiny::textInput()
. It wraps base::readline()
with cli::cli_text()
allowing you to format questions using the cli
package.
1 | cl_text_input(prompt, .envir = parent.frame(1))
|
prompt |
A character string with the question to be asked. Passed into
|
.envir |
Used to ensure that |
In general, I would recommend using cl_text_action
as it
accepts code to execute depending on the user's input, but this function is
perhaps more adaptable.
A character string containing the user's response.
Other command-line-tools:
cl_text_action()
,
cl_yes_no_action()
,
cl_yes_no_lgl()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | favorite_cat_question <- function() {
answer <- cl_text_input("Name your {.strong favorite} cat.")
if (tolower(answer) != "tucker") {
cli::cli_alert_danger("\U1F63E Come meet my cat, Tucker,
and I think you'll change your mind!")
} else {
cli::cli_alert_success("Correct answer! \U1F63B")
}
}
favorite_dog_question <- function() {
answer <- cl_text_input("Name your {.strong favorite} dog.")
if (tolower(answer) != "ella") {
cli::cli_alert_danger("\U1F44E Come meet my dog, Ella,
and I think you'll change your mind!")
} else {
cli::cli_alert_success("Correct answer!\U1F436")
}
}
if (interactive()) favorite_cat_question()
if (interactive()) favorite_dog_question()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.