Class: Clack::Prompts::Autocomplete
- Inherits:
-
Core::Prompt
- Object
- Core::Prompt
- Clack::Prompts::Autocomplete
- Includes:
- Core::OptionsHelper, Core::TextInputHelper
- Defined in:
- lib/clack/prompts/autocomplete.rb
Overview
Type-to-filter autocomplete prompt.
Combines text input with a filtered option list. Type to filter, use arrow keys to navigate matches, Enter to select.
By default, filtering uses fuzzy matching across value, label, and hint fields, sorted by relevance score. Supply a custom filter proc to override this behavior.
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:, max_items: 5, placeholder: nil, filter: nil, **opts) ⇒ Autocomplete
constructor
A new instance of Autocomplete.
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, filter: nil, **opts) ⇒ Autocomplete
Returns a new instance of Autocomplete.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/clack/prompts/autocomplete.rb', line 47 def initialize(message:, options:, max_items: 5, placeholder: nil, filter: nil, **opts) super(message:, **opts) @all_options = () @max_items = max_items @placeholder = placeholder @filter = filter @search_text = "" @cursor = 0 @option_index = 0 @scroll_offset = 0 update_filtered end |