Class: TTY2::Prompt::Multiline Private
- 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
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
Instance Attribute Summary
Attributes inherited from Question
#message, #messages, #modifier, #validation
Instance Method Summary collapse
-
#help(value = (not_set = true)) ⇒ String
Provide help information.
-
#initialize(prompt, **options) ⇒ Multiline
constructor
private
A new instance of Multiline.
- #keyreturn ⇒ Object (also: #keyenter) private
- #process_input(question) ⇒ Object private
- #read_input ⇒ Object private
- #refresh(lines, lines_to_clear) ⇒ Object private
- #render_question ⇒ Object private
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/tty2/prompt/multiline.rb', line 14 def initialize(prompt, **) super @help = [:help] || self.class::HELP @first_render = true @lines_count = 0 end |
Instance Method Details
#help(value = (not_set = true)) ⇒ String
Provide help information
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 |
#keyreturn ⇒ Object 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.
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.
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_input ⇒ 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.
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.
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_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.
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}#{} "] 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 |