Class: TuiTui::Confirm
Overview
OK / Cancel confirmation modal.
Constant Summary collapse
- GAP =
2
Constants inherited from Modal
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.
15 16 17 18 19 20 21 |
# File 'lib/tui_tui/confirm.rb', line 15 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.
13 14 15 |
# File 'lib/tui_tui/confirm.rb', line 13 def focus @focus end |
Instance Method Details
#draw(canvas, size) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/tui_tui/confirm.rb', line 45 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
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/tui_tui/confirm.rb', line 23 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
36 37 38 39 40 41 42 43 |
# File 'lib/tui_tui/confirm.rb', line 36 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 |