Class: TTY2::Prompt::Multiline Private

Inherits:
Question
  • Object
show all
Defined in:
lib/tty2/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, #quiet, #raw, #render, #render_error, #required, #to_s, #validate, #validation?, #value, #value?

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
# File 'lib/tty2/prompt/multiline.rb', line 14

def initialize(prompt, **options)
  super
  @help         = options[:help] || self.class::HELP
  @first_render = true
  @lines_count  = 0
end

Instance Method Details

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

Provide help information

Returns:

API:

  • public



26
27
28
29
30
# File 'lib/tty2/prompt/multiline.rb', line 26

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



36
37
38
# File 'lib/tty2/prompt/multiline.rb', line 36

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



55
56
57
58
59
60
61
62
63
64
# File 'lib/tty2/prompt/multiline.rb', line 55

def process_input(question)
  @prompt.print(question)
  @lines = read_input
  @input = "#{@lines.first.strip} ..." unless @lines.first.to_s.empty?
  if Utils.blank?(@input) && default?
    @input = default
    @lines = default
  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



32
33
34
# File 'lib/tty2/prompt/multiline.rb', line 32

def read_input
  @prompt.read_multiline
end

#refresh(lines, lines_to_clear) ⇒ 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



66
67
68
69
# File 'lib/tty2/prompt/multiline.rb', line 66

def refresh(lines, lines_to_clear)
  size = @lines_count + lines_to_clear + 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



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/tty2/prompt/multiline.rb', line 41

def render_question
  header = ["#{@prefix}#{message} "]
  if !echo?
    header
  elsif @done
    header << @prompt.decorate(@input.to_s, @active_color)
  elsif @first_render
    header << @prompt.decorate(help, @help_color)
    @first_render = false
  end
  header << "\n"
  header.join
end