Package 'climenu'

Title: Interactive Command-Line Menus
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.
Authors: Petr Čala [aut, cre]
Maintainer: Petr Čala <[email protected]>
License: MIT + file LICENSE
Version: 0.1.7
Built: 2026-05-15 05:39:26 UTC
Source: https://github.com/petrcala/climenu

Help Index


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 TRUE, adds a "Select all" / "Deselect all" option at the top of the menu. When selected, toggles all items at once. The option text dynamically changes based on selection state (default: FALSE).

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:"
  )
}

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)
}