Class: Clack::Prompts::Range
- Inherits:
-
Core::Prompt
- Object
- Core::Prompt
- Clack::Prompts::Range
- Defined in:
- lib/clack/prompts/range.rb
Overview
Range/slider prompt for numeric selection.
Displays a horizontal slider track. Navigate with arrow keys or vim bindings. Press Enter to confirm.
Constant Summary collapse
- TRACK_WIDTH =
30- TRACK_CHAR =
━ (box drawings heavy horizontal)
"\u2501"- HANDLE_CHAR =
● (black circle)
"\u25CF"
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:, min: 0, max: 100, step: 1, initial_value: nil, default: nil, **opts) ⇒ Range
constructor
A new instance of Range.
Methods inherited from Core::Prompt
flush_resize, register, #request_redraw, #run, setup_signal_handler, unregister
Constructor Details
#initialize(message:, min: 0, max: 100, step: 1, initial_value: nil, default: nil, **opts) ⇒ Range
Returns a new instance of Range.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/clack/prompts/range.rb', line 32 def initialize(message:, min: 0, max: 100, step: 1, initial_value: nil, default: nil, **opts) super(message:, **opts) raise ArgumentError, "min must be less than max" if min >= max raise ArgumentError, "step must be positive" if step <= 0 @min = min @max = max @step = step @value = clamp(initial_value || default || min) end |