Class: TTY::Prompt::Multiline Private

Inherits:
Question
  • Object
show all
Defined in:
lib/tty/prompt/multiline.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A prompt responsible for multi line user input

API:

  • private

Constant Summary collapse

HELP =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

API:

  • private

'(Press CTRL-D or CTRL-Z to finish)'.freeze

Constants inherited from Question

Question::UndefinedSetting

Instance Attribute Summary

Attributes inherited from Question

#message, #messages, #modifier, #validation

Instance Method Summary collapse

Methods inherited from Question

#call, #convert, #convert?, #convert_result, #default, #default?, #echo, #in, #in?, #inspect, #message_for, #modify, #raw, #render, #render_error, #required, #to_s, #validate, #validation?

Constructor Details

#initialize(prompt, options = {}) ⇒ Multiline

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Multiline.

API:

  • private



14
15
16
17
18
19
20
21
# 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

Instance Method Details

#help(value = (not_set = true)) ⇒ String

Provide help information

Returns:

API:

  • public



28
29
30
31
# File 'lib/tty/prompt/multiline.rb', line 28

def help(value = (not_set = true))
  return @help if not_set
  @help = value
end

#keyreturnObject Also known as: keyenter

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



37
38
39
# File 'lib/tty/prompt/multiline.rb', line 37

def keyreturn(*)
  @lines_count += 1
end

#process_input(question) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



56
57
58
59
60
61
62
63
# 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_inputObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



33
34
35
# File 'lib/tty/prompt/multiline.rb', line 33

def read_input
  @prompt.read_multiline
end

#refresh(lines) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



65
66
67
68
# File 'lib/tty/prompt/multiline.rb', line 65

def refresh(lines)
  size = @lines_count + lines + 1
  @prompt.clear_lines(size)
end

#render_questionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

API:

  • private



42
43
44
45
46
47
48
49
50
51
52
53
54
# 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