Class: Xudoku::Cli::App

Inherits:
Object
  • Object
show all
Defined in:
lib/xudoku/cli/app.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Instance Method Summary collapse

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_screenObject (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

#ioObject (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

#runObject



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

Returns:

  • (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