class TTY::Prompt::Slider
A class responsible for gathering numeric input from range
@api public
Constants
- FORMAT
- HELP
Public Class Methods
new(prompt, options = {})
click to toggle source
Initailize a Slider
@param [Prompt] prompt
the prompt
@param [Hash] options
the options to configure this slider
@option options [Integer] :min The minimum value @option options [Integer] :max The maximum value @option options [Integer] :step The step value @option options [String] :format The display format
@api public
# File lib/tty/prompt/slider.rb, line 29 def initialize(prompt, options = {}) @prompt = prompt @prefix = options.fetch(:prefix) { @prompt.prefix } @min = options.fetch(:min) { 0 } @max = options.fetch(:max) { 10 } @step = options.fetch(:step) { 1 } @default = options[:default] @active_color = options.fetch(:active_color) { @prompt.active_color } @help_color = options.fetch(:help_color) { @prompt.help_color } @format = options.fetch(:format) { FORMAT } @first_render = true @done = false @prompt.subscribe(self) end
Public Instance Methods
call(question, &block)
click to toggle source
Call the slider by passing question
@param [String] question
the question to ask
@apu public
# File lib/tty/prompt/slider.rb, line 97 def call(question, &block) @question = question block.call(self) if block @active = initial render end
default(value)
click to toggle source
@api public
# File lib/tty/prompt/slider.rb, line 68 def default(value) @default = value end
format(value)
click to toggle source
# File lib/tty/prompt/slider.rb, line 87 def format(value) @format = value end
initial()
click to toggle source
Setup initial active position
@return [Integer]
@api private
# File lib/tty/prompt/slider.rb, line 50 def initial if @default.nil? range.size / 2 else range.index(@default) end end
keyleft(*)
click to toggle source
# File lib/tty/prompt/slider.rb, line 104 def keyleft(*) @active -= 1 if @active > 0 end
Also aliased as: keydown
keyreturn(*)
click to toggle source
# File lib/tty/prompt/slider.rb, line 114 def keyreturn(*) @done = true end
keyright(*)
click to toggle source
# File lib/tty/prompt/slider.rb, line 109 def keyright(*) @active += 1 if (@active + 1) < range.size end
Also aliased as: keyup
max(value)
click to toggle source
@api public
# File lib/tty/prompt/slider.rb, line 78 def max(value) @max = value end
min(value)
click to toggle source
@api public
# File lib/tty/prompt/slider.rb, line 73 def min(value) @min = value end
range()
click to toggle source
Range of numbers to render
@return [Array]
@apip private
# File lib/tty/prompt/slider.rb, line 63 def range (@min..@max).step(@step).to_a end
step(value)
click to toggle source
@api public
# File lib/tty/prompt/slider.rb, line 83 def step(value) @step = value end