Class: Potty::Mouth::Prompt::Confirm

Inherits:
Base
  • Object
show all
Defined in:
lib/potty/mouth.rb

Instance Attribute Summary collapse

Attributes inherited from View

#app, #widgets

Instance Method Summary collapse

Methods inherited from Base

#spacing

Methods inherited from View

#activate, #deactivate, #layout_widgets, #on_activate, #on_deactivate, #render, #spacing, #tick

Constructor Details

#initialize(app, prompt:, default: false) ⇒ Confirm

Returns a new instance of Confirm.



149
150
151
152
153
154
# File 'lib/potty/mouth.rb', line 149

def initialize(app, prompt:, default: false)
  @prompt = prompt
  @default = default
  @result = nil
  super(app)
end

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



147
148
149
# File 'lib/potty/mouth.rb', line 147

def result
  @result
end

Instance Method Details

#build_layoutObject



156
157
158
159
# File 'lib/potty/mouth.rb', line 156

def build_layout
  hint = @default ? '[Y/n]' : '[y/N]'
  @widgets = [Potty::Widgets::Label.new(app, text: "#{@prompt} #{hint}", color: :info)]
end

#handle_escapeObject



170
171
172
# File 'lib/potty/mouth.rb', line 170

def handle_escape
  finish(@default)
end

#handle_key(ch) ⇒ Object



161
162
163
164
165
166
167
168
# File 'lib/potty/mouth.rb', line 161

def handle_key(ch)
  case ch
  when 'y'.ord, 'Y'.ord then finish(true)
  when 'n'.ord, 'N'.ord then finish(false)
  when *Potty::Keys::ENTERS then finish(@default)
  else false
  end
end