lib/tty/prompt/question.rb in tty-prompt-0.4.0 vs lib/tty/prompt/question.rb in tty-prompt-0.5.0
- old
+ new
@@ -22,28 +22,28 @@
# @api public
attr_reader :message
attr_reader :modifier
- attr_reader :prompt
-
attr_reader :validation
# Initialize a Question
#
# @api public
def initialize(prompt, options = {})
@prompt = prompt
+ @prefix = options.fetch(:prefix) { @prompt.prefix }
@default = options.fetch(:default) { UndefinedSetting }
@required = options.fetch(:required) { false }
@echo = options.fetch(:echo) { true }
@in = options.fetch(:in) { UndefinedSetting }
@modifier = options.fetch(:modifier) { [] }
@validation = options.fetch(:validation) { UndefinedSetting }
@read = options.fetch(:read) { UndefinedSetting }
@convert = options.fetch(:convert) { UndefinedSetting }
- @color = options.fetch(:color) { :green }
+ @active_color = options.fetch(:active_color) { @prompt.active_color }
+ @help_color = options.fetch(:help_color) { @prompt.help_color }
@messages = Utils.deep_copy(options.fetch(:messages) { { } })
@done = false
@input = nil
@evaluator = Evaluator.new(self)
@@ -113,18 +113,16 @@
# Render question
#
# @api private
def render_question
- header = "#{prompt.prefix}#{message} "
- if @convert == :bool && !@done
- header += @prompt.decorate('(Y/n)', :bright_black) + ' '
- elsif !echo?
+ header = "#{@prefix}#{message} "
+ if !echo?
header
elsif @done
- header += @prompt.decorate("#{@input}", @color)
- elsif default?
- header += @prompt.decorate("(#{default})", :bright_black) + ' '
+ header += @prompt.decorate("#{@input}", @active_color)
+ elsif default? && !Utils.blank?(@default)
+ header += @prompt.decorate("(#{default})", @help_color) + ' '
end
@prompt.print(header)
@prompt.print("\n") if @done
end