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

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.

"(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.


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

Instance Method Details

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

Provide help information

Returns:

  • (String)

26
27
28
29
# File 'lib/tty/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.


35
36
37
# File 'lib/tty/prompt/multiline.rb', line 35

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.


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

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.


31
32
33
# File 'lib/tty/prompt/multiline.rb', line 31

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.


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

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.


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

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.join
end