Class: Xudoku::Cli::App
- Inherits:
-
Object
- Object
- Xudoku::Cli::App
- Defined in:
- lib/xudoku/cli/app.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#current_screen ⇒ Object
readonly
Returns the value of attribute current_screen.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
Instance Method Summary collapse
- #handle(event_name) ⇒ Object
-
#initialize(io = $stdout) ⇒ App
constructor
A new instance of App.
- #run ⇒ Object
- #running? ⇒ Boolean
- #switch_to(klass) ⇒ Object
Constructor Details
#initialize(io = $stdout) ⇒ App
Returns a new instance of App.
9 10 11 12 13 14 15 |
# File 'lib/xudoku/cli/app.rb', line 9 def initialize(io = $stdout) @io = io Signal.trap "WINCH" do @current_screen&.redraw! end end |
Instance Attribute Details
#current_screen ⇒ Object (readonly)
Returns the value of attribute current_screen.
7 8 9 |
# File 'lib/xudoku/cli/app.rb', line 7 def current_screen @current_screen end |
#io ⇒ Object (readonly)
Returns the value of attribute io.
7 8 9 |
# File 'lib/xudoku/cli/app.rb', line 7 def io @io end |
Instance Method Details
#handle(event_name) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/xudoku/cli/app.rb', line 29 def handle(event_name) case event_name when :quit @running = false exit! when :menu switch_to Screens::Menu when :new_puzzle switch_to Screens::Puzzle end end |
#run ⇒ Object
17 18 19 20 21 22 |
# File 'lib/xudoku/cli/app.rb', line 17 def run return if @running @running = true switch_to Screens::Menu end |
#running? ⇒ Boolean
41 42 43 |
# File 'lib/xudoku/cli/app.rb', line 41 def running? !!@running end |
#switch_to(klass) ⇒ Object
24 25 26 27 |
# File 'lib/xudoku/cli/app.rb', line 24 def switch_to(klass) @current_screen = klass.new(app: self, io: @io) @current_screen.render end |