Class: Clack::Prompts::Select
- Inherits:
-
Core::Prompt
- Object
- Core::Prompt
- Clack::Prompts::Select
- Includes:
- Core::OptionsHelper
- Defined in:
- lib/clack/prompts/select.rb
Overview
Single-selection prompt from a list of options.
Navigate with arrow keys or j/k (vim-style). Press Enter to confirm. Supports disabled options, hints, and scrolling for long lists.
Options can be:
-
Strings: ‘[“a”, “b”, “c”]` (value and label are the same)
-
Hashes: ‘[“a”, label: “Option A”, hint: “details”, disabled: false]`
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:, initial_value: nil, max_items: nil, **opts) ⇒ Select
constructor
A new instance of Select.
Methods included from Core::OptionsHelper
#find_initial_cursor, #find_next_enabled, #first_enabled_index, #move_selection, #navigable_items, normalize_option, #normalize_options, #update_scroll, #visible_options
Methods inherited from Core::Prompt
flush_resize, register, #request_redraw, #run, setup_signal_handler, unregister
Constructor Details
#initialize(message:, options:, initial_value: nil, max_items: nil, **opts) ⇒ Select
Returns a new instance of Select.
40 41 42 43 44 45 46 47 |
# File 'lib/clack/prompts/select.rb', line 40 def initialize(message:, options:, initial_value: nil, max_items: nil, **opts) super(message:, **opts) @options = () @max_items = max_items @scroll_offset = 0 @option_index = find_initial_cursor(initial_value) update_value end |