Class: Clack::Prompts::AutocompleteMultiselect
- Inherits:
-
Core::Prompt
- Object
- Core::Prompt
- Clack::Prompts::AutocompleteMultiselect
- Defined in:
- lib/clack/prompts/autocomplete_multiselect.rb
Overview
Type-to-filter autocomplete with multiple selection.
Combines text input filtering with checkbox-style selection. Type to filter, Space to toggle, Enter to confirm.
Unlike Multiselect, the āaā (select all) and āiā (invert) shortcuts are not available because those characters are needed for the search field. Similarly, vim-style j/k navigation is disabled in favor of typing.
Constant Summary
Constants included from Core::SelectionManager
Core::SelectionManager::REQUIRED_ERROR
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:, max_items: 5, placeholder: nil, required: true, initial_values: [], filter: nil, **opts) ⇒ AutocompleteMultiselect
constructor
A new instance of AutocompleteMultiselect.
Methods included from Core::SelectionManager
#selected_labels, #toggle_value, #update_selection_value, #validate_selection
Methods included from Core::TextInputHelper
#current_placeholder, #format_placeholder_with_cursor, #input_display, #placeholder_display, #value_with_cursor
Methods included from Core::OptionsHelper
#find_initial_cursor, #find_next_enabled, #first_enabled_index, #move_cursor, #move_selection, 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:, max_items: 5, placeholder: nil, required: true, initial_values: [], filter: nil, **opts) ⇒ AutocompleteMultiselect
Returns a new instance of AutocompleteMultiselect.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/clack/prompts/autocomplete_multiselect.rb', line 44 def initialize(message:, options:, max_items: 5, placeholder: nil, required: true, initial_values: [], filter: nil, **opts) if opts.key?(:initial_value) raise ArgumentError, "AutocompleteMultiselect uses initial_values: (plural), not initial_value:" end super(message:, **opts) @all_options = () @max_items = max_items @placeholder = placeholder @required = required @filter = filter @search_text = "" @cursor = 0 @option_index = 0 @scroll_offset = 0 valid_values = Set.new(@all_options.map { |o| o.value }) @selected = Set.new(initial_values) & valid_values update_filtered end |