Class: Yatte::QuitController
- Inherits:
-
Object
- Object
- Yatte::QuitController
- Defined in:
- lib/yatte/quit_controller.rb
Overview
Owns the “press Ctrl-X N more time(s)” confirmation counter used by close-tab and quit. The counter decrements on each confirm_* call and resets on non-quit-related keys (via #reset).
Constant Summary collapse
- DEFAULT_CONFIRM_COUNT =
3
Instance Method Summary collapse
-
#confirm_close ⇒ Object
Returns true if the close should proceed now, false if blocked with a warning message.
-
#confirm_quit ⇒ Object
Returns true if the quit should proceed now, false if blocked with a warning message.
-
#initialize(status:) ⇒ QuitController
constructor
A new instance of QuitController.
- #reset ⇒ Object
Constructor Details
#initialize(status:) ⇒ QuitController
Returns a new instance of QuitController.
10 11 12 13 |
# File 'lib/yatte/quit_controller.rb', line 10 def initialize(status:) @status = status @count = DEFAULT_CONFIRM_COUNT end |
Instance Method Details
#confirm_close ⇒ Object
Returns true if the close should proceed now, false if blocked with a warning message. Resets after a successful confirmation.
21 22 23 24 25 26 27 28 29 |
# File 'lib/yatte/quit_controller.rb', line 21 def confirm_close @count -= 1 if @count > 0 @status.call(warning_for("Ctrl-W", "close")) return false end reset true end |
#confirm_quit ⇒ Object
Returns true if the quit should proceed now, false if blocked with a warning message. Does NOT reset afterwards — the editor is about to exit.
34 35 36 37 38 39 40 41 |
# File 'lib/yatte/quit_controller.rb', line 34 def confirm_quit @count -= 1 if @count > 0 @status.call(warning_for("Ctrl-Q", "quit")) return false end true end |
#reset ⇒ Object
15 16 17 |
# File 'lib/yatte/quit_controller.rb', line 15 def reset @count = DEFAULT_CONFIRM_COUNT end |