Class: Clack::Prompts::SelectKey
- Inherits:
-
Core::Prompt
- Object
- Core::Prompt
- Clack::Prompts::SelectKey
- Defined in:
- lib/clack/prompts/select_key.rb
Overview
Quick selection via keyboard shortcuts.
Each option has an associated key. Pressing that key immediately
selects the option and submits (running validate: and transform:
like every other prompt).
Options format:
{ value: "x", label: "Do X", key: "x" }- explicit key{ value: "create", label: "Create" }- key defaults to first char{ create: "Create", quit: "Quit" }- Hash shorthand (value => label, key defaults to first char){ create: { label: "New project", key: "n" } }- Hash shorthand with explicit key
Constant Summary
Constants inherited from Core::Prompt
Core::Prompt::MIN_TERMINAL_WIDTH
Instance Attribute Summary
Attributes inherited from Core::Prompt
#error_message, #state, #value, #warning_message
Instance Method Summary collapse
-
#initialize(message:, options:, case_sensitive: false, initial_value: nil, **opts) ⇒ SelectKey
constructor
A new instance of SelectKey.
Methods inherited from Core::Prompt
flush_resize, register, #request_redraw, #run, setup_signal_handler, unregister
Constructor Details
#initialize(message:, options:, case_sensitive: false, initial_value: nil, **opts) ⇒ SelectKey
Returns a new instance of SelectKey.
36 37 38 39 40 41 42 |
# File 'lib/clack/prompts/select_key.rb', line 36 def initialize(message:, options:, case_sensitive: false, initial_value: nil, **opts) super(message:, **opts) @options = () @case_sensitive = case_sensitive @option_index = find_initial_index(initial_value) @value = current_option&.value end |