class TTY::Prompt::Multiline

A prompt responsible for multi line user input

@api private

Constants

HELP

Public Class Methods

new(prompt, options = {}) click to toggle source
Calls superclass method
# File lib/tty/prompt/multiline.rb, line 14
def initialize(prompt, options = {})
  super
  @help         = options[:help] || self.class::HELP
  @first_render = true
  @lines_count  = 0

  @prompt.subscribe(self)
end

Public Instance Methods

help(value = (not_set = true)) click to toggle source

Provide help information

@return [String]

@api public

# File lib/tty/prompt/multiline.rb, line 28
def help(value = (not_set = true))
  return @help if not_set
  @help = value
end
keyenter(*)
Alias for: keyreturn
keyreturn(*) click to toggle source
# File lib/tty/prompt/multiline.rb, line 37
def keyreturn(*)
  @lines_count += 1
end
Also aliased as: keyenter
process_input(question) click to toggle source
# File lib/tty/prompt/multiline.rb, line 56
def process_input(question)
  @lines = read_input
  @input = "#{@lines.first.strip} ..." unless @lines.first.to_s.empty?
  if Utils.blank?(@input)
    @input = default? ? default : nil
  end
  @evaluator.(@lines)
end
read_input() click to toggle source
# File lib/tty/prompt/multiline.rb, line 33
def read_input
  @prompt.read_multiline
end
refresh(lines) click to toggle source
# File lib/tty/prompt/multiline.rb, line 65
def refresh(lines)
  size = @lines_count + lines + 1
  @prompt.clear_lines(size)
end
render_question() click to toggle source
# File lib/tty/prompt/multiline.rb, line 42
def render_question
  header = "#{@prefix}#{message} "
  if !echo?
    header
  elsif @done
    header += @prompt.decorate("#{@input}", @active_color)
  elsif @first_render
    header += @prompt.decorate(help, @help_color)
    @first_render = false
  end
  header += "\n"
  header
end