Class: Clack::Prompts::Text
- Inherits:
-
Core::Prompt
- Object
- Core::Prompt
- Clack::Prompts::Text
- Includes:
- Core::TextInputHelper
- Defined in:
- lib/clack/prompts/text.rb
Overview
Single-line text input prompt with cursor navigation.
Features:
-
Arrow key cursor movement (left/right)
-
Backspace/delete support
-
Placeholder text (shown when empty)
-
Default value (used if submitted empty)
-
Initial value (pre-filled, editable)
-
Validation support
-
Tab completion (optional)
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:, placeholder: nil, default_value: nil, initial_value: nil, completions: nil, **opts) ⇒ Text
constructor
A new instance of Text.
Methods included from Core::TextInputHelper
#current_placeholder, #format_placeholder_with_cursor, #handle_text_input, #input_display, #placeholder_display, #text_value, #text_value=, #value_with_cursor
Methods inherited from Core::Prompt
flush_resize, register, #request_redraw, #run, setup_signal_handler, unregister
Constructor Details
#initialize(message:, placeholder: nil, default_value: nil, initial_value: nil, completions: nil, **opts) ⇒ Text
Returns a new instance of Text.
52 53 54 55 56 57 58 59 |
# File 'lib/clack/prompts/text.rb', line 52 def initialize(message:, placeholder: nil, default_value: nil, initial_value: nil, completions: nil, **opts) super(message:, **opts) @placeholder = placeholder @default_value = default_value @completions = completions @value = initial_value || "" @cursor = @value.grapheme_clusters.length end |