Class: TuiTui::Modal::Confirm
- Inherits:
-
Modal
- Object
- Modal
- TuiTui::Modal::Confirm
- Defined in:
- lib/tui_tui/modal/confirm.rb
Overview
OK / Cancel confirmation modal.
Constant Summary collapse
- GAP =
2
Instance Attribute Summary collapse
-
#focus ⇒ Object
readonly
Returns the value of attribute focus.
Instance Method Summary collapse
- #draw(canvas, size) ⇒ Object
- #handle(key) ⇒ Object
- #handle_mouse(event) ⇒ Object
-
#initialize(message, ok: "OK", cancel: "Cancel", default: :cancel, theme: Theme::DEFAULT) ⇒ Confirm
constructor
A new instance of Confirm.
Constructor Details
#initialize(message, ok: "OK", cancel: "Cancel", default: :cancel, theme: Theme::DEFAULT) ⇒ Confirm
Returns a new instance of Confirm.
14 15 16 17 18 19 20 |
# File 'lib/tui_tui/modal/confirm.rb', line 14 def initialize(, ok: "OK", cancel: "Cancel", default: :cancel, theme: Theme::DEFAULT) @message = DisplayText.new() @ok = (ok) @cancel = (cancel) @focus = default @theme = theme end |
Instance Attribute Details
#focus ⇒ Object (readonly)
Returns the value of attribute focus.
12 13 14 |
# File 'lib/tui_tui/modal/confirm.rb', line 12 def focus @focus end |
Instance Method Details
#draw(canvas, size) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/tui_tui/modal/confirm.rb', line 44 def draw(canvas, size) inner = [@message.width, ].max rect, col = panel(canvas, inner: inner, body_rows: 3) canvas.text(rect.row + 1, col, @message.center(inner), theme.text) (canvas, rect.row + 3, col, inner) canvas end |
#handle(key) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/tui_tui/modal/confirm.rb', line 22 def handle(key) case key when :left, :right, "\t", "h", "l" toggle when "\r", " " @focus when "y", "Y" :ok when "n", "N", :escape, KeyCode::CTRL_C :cancel end end |
#handle_mouse(event) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/tui_tui/modal/confirm.rb', line 35 def handle_mouse(event) return nil unless event.action == :press && @buttons_row == event.row return :ok if hit?(event.col, @ok_at, @ok.width) return :cancel if hit?(event.col, @cancel_at, @cancel.width) nil end |