Class: Potty::Mouth::Prompt::Ask
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Attributes inherited from View
Instance Method Summary collapse
- #build_layout ⇒ Object
- #handle_escape ⇒ Object
- #handle_key(ch) ⇒ Object
-
#initialize(app, prompt:, default: '') ⇒ Ask
constructor
A new instance of Ask.
Methods inherited from Base
Methods inherited from View
#activate, #deactivate, #layout_widgets, #on_activate, #on_deactivate, #render, #spacing, #tick
Constructor Details
#initialize(app, prompt:, default: '') ⇒ Ask
Returns a new instance of Ask.
115 116 117 118 119 120 |
# File 'lib/potty/mouth.rb', line 115 def initialize(app, prompt:, default: '') @prompt = prompt @default = default @result = nil super(app) end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
113 114 115 |
# File 'lib/potty/mouth.rb', line 113 def result @result end |
Instance Method Details
#build_layout ⇒ Object
122 123 124 125 126 |
# File 'lib/potty/mouth.rb', line 122 def build_layout @field = Potty::Widgets::TextInput.new(app, text: @default) @widgets = [Potty::Widgets::Label.new(app, text: @prompt, color: :info), @field] @field.focus end |
#handle_escape ⇒ Object
139 140 141 142 143 |
# File 'lib/potty/mouth.rb', line 139 def handle_escape @result = nil app.quit true end |
#handle_key(ch) ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'lib/potty/mouth.rb', line 128 def handle_key(ch) # Intercept Enter before super (which would otherwise advance focus) # — a single-field prompt submits on Enter. if Potty::Keys.enter?(ch) @result = @field.text app.quit return true end super end |