| Title: | Interactive Command-Line Menus |
| Version: | 0.1.3 |
| Author: | Petr Čala [aut, cre] |
| Maintainer: | Petr Čala <61505008@fsv.cuni.cz> |
| Description: | Provides interactive command-line menu functionality with single and multiple selection menus, keyboard navigation (arrow keys or vi-style j/k), preselection, and graceful fallback for non-interactive environments. Inspired by tools such as 'inquirer.js' https://github.com/SBoudrias/Inquirer.js, 'pick' https://github.com/aisk/pick, and 'survey' https://github.com/AlecAivazis/survey. Designed to be lightweight and easy to integrate into 'R' packages and scripts. |
| License: | MIT + file LICENSE |
| URL: | https://github.com/PetrCala/climenu |
| BugReports: | https://github.com/PetrCala/climenu/issues |
| Depends: | R (≥ 4.0.0) |
| Imports: | cli (≥ 3.6.0) |
| Suggests: | covr, devtools, keypress, knitr, rmarkdown, roxygen2 (≥ 7.0.0), testthat (≥ 3.0.0) |
| VignetteBuilder: | knitr |
| Config/testthat/edition: | 3 |
| Config/testthat/parallel: | TRUE |
| Encoding: | UTF-8 |
| RoxygenNote: | 7.3.3 |
| NeedsCompilation: | no |
| Packaged: | 2026-02-03 07:07:04 UTC; runner |
| Repository: | CRAN |
| Date/Publication: | 2026-02-06 13:40:06 UTC |
Multiple Selection Menu (Checkbox)
Description
Interactive menu for selecting multiple items from a list.
Uses arrow keys (or j/k) to navigate, Space to toggle, and Enter to confirm.
Optionally includes a "Select all" / "Deselect all" option at the top when
allow_select_all = TRUE.
Usage
checkbox(
choices,
prompt = "Select items (Space to toggle, Enter to confirm):",
selected = NULL,
return_index = FALSE,
max_visible = 10L,
allow_select_all = FALSE
)
Arguments
choices |
Character vector of choices to display |
prompt |
Prompt message to display |
selected |
Pre-selected items (indices or values) |
return_index |
Return indices instead of values (default: FALSE) |
max_visible |
Maximum number of items to display at once (default: 10). Set to NULL to show all items. |
allow_select_all |
If |
Value
Selected items as character vector or indices, or NULL if cancelled. The special "Select all" option is never included in the returned results.
Examples
if (interactive()) {
toppings <- checkbox(
c("Pepperoni", "Mushrooms", "Olives"),
prompt = "Select toppings:"
)
# With pre-selection
options <- checkbox(
c("Option A", "Option B", "Option C"),
selected = c(1, 3)
)
# With scrolling for long lists
items <- checkbox(1:100, max_visible = 10)
# With select all feature
methods <- checkbox(
c("method_a", "method_b", "method_c"),
allow_select_all = TRUE,
prompt = "Select methods to run:"
)
}
Interactive CLI Menu
Description
Creates an interactive menu in the R console allowing users to select items. Inspired by inquirer.js, Python's pick, and Go's survey libraries.
Usage
menu(
choices,
prompt = "Select an item:",
type = c("select", "checkbox"),
selected = NULL,
return_index = FALSE
)
Arguments
choices |
Character vector of choices to display |
prompt |
Prompt message to display (default: "Select an item:") |
type |
Menu type: "select" (single) or "checkbox" (multiple) (default: "select") |
selected |
Pre-selected items (indices or values) |
return_index |
Return indices instead of values (default: FALSE) |
Value
Selected item(s) as character vector or indices, or NULL if cancelled
Examples
if (interactive()) {
# Single selection
color <- menu(c("Red", "Green", "Blue"), prompt = "Pick a color:")
# Multiple selection
toppings <- menu(
c("Pepperoni", "Mushrooms", "Olives"),
type = "checkbox",
prompt = "Select toppings:"
)
}
Single Selection Menu
Description
Interactive menu for selecting a single item from a list. Uses arrow keys (or j/k) to navigate and Enter to select.
Usage
select(
choices,
prompt = "Select an item:",
selected = NULL,
return_index = FALSE,
max_visible = 10L
)
Arguments
choices |
Character vector of choices to display |
prompt |
Prompt message to display |
selected |
Pre-selected item (index or value) |
return_index |
Return index instead of value (default: FALSE) |
max_visible |
Maximum number of items to display at once (default: 10). Set to NULL to show all items. |
Value
Selected item as character or index, or NULL if cancelled
Examples
if (interactive()) {
choice <- select(c("Yes", "No", "Maybe"))
index <- select(c("First", "Second", "Third"), return_index = TRUE)
# With scrolling for long lists
choice <- select(1:100, max_visible = 10)
}