Class: TTY::Prompt::Multiline Private
- 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
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) ⇒ Object private
- #render_question ⇒ Object private
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.
14 15 16 17 18 19 20 21 |
# File 'lib/tty/prompt/multiline.rb', line 14 def initialize(prompt, = {}) super @help = [: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
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 |
#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.
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.
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_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.
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.
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_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.
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}#{} " 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 |