lib/tty/prompt/slider.rb in tty-prompt-0.4.0 vs lib/tty/prompt/slider.rb in tty-prompt-0.5.0
- old
+ new
@@ -12,17 +12,19 @@
# Initailize a Slider
#
# @api public
def initialize(prompt, options = {})
@prompt = prompt
- @first_render = true
- @done = false
- @color = options.fetch(:color) { :green }
+ @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 }
+ @first_render = true
+ @done = false
@prompt.subscribe(self)
end
# Setup initial active position
@@ -131,24 +133,24 @@
# Render question with the slider
#
# @api private
def render_question
- header = "#{@prompt.prefix}#{@question} #{render_header}"
+ header = "#{@prefix}#{@question} #{render_header}"
@prompt.puts(header)
@first_render = false
@prompt.print(render_slider) unless @done
end
# Render actual answer or help
#
# @api private
def render_header
if @done
- @prompt.decorate(render_answer.to_s, @color)
+ @prompt.decorate(render_answer.to_s, @active_color)
elsif @first_render
- @prompt.decorate(HELP, :bright_black)
+ @prompt.decorate(HELP, @help_color)
end
end
# Render slider representation
#
@@ -157,10 +159,10 @@
# @api private
def render_slider
output = ''
output << Symbols::SLIDER_END
output << '-' * @active
- output << @prompt.decorate(Symbols::SLIDER_HANDLE, @color)
+ output << @prompt.decorate(Symbols::SLIDER_HANDLE, @active_color)
output << '-' * (range.size - @active - 1)
output << Symbols::SLIDER_END
output << " #{range[@active]}"
output
end