Class: Xudoku::Cli::Screens::Base

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

Overview

:nodoc:

Direct Known Subclasses

Menu, Puzzle

Constant Summary collapse

TITLE_HEIGHT =
3
TITLE =
"X u d o k u"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app:, io:) ⇒ Base

Returns a new instance of Base.



13
14
15
16
17
18
19
20
# File 'lib/xudoku/cli/screens/base.rb', line 13

def initialize(app:, io:)
  @app = app
  @io = io
  @reader = TTY::Reader.new
  @first_render = true

  setup
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



11
12
13
# File 'lib/xudoku/cli/screens/base.rb', line 11

def app
  @app
end

#first_renderObject (readonly)

Returns the value of attribute first_render.



11
12
13
# File 'lib/xudoku/cli/screens/base.rb', line 11

def first_render
  @first_render
end

#ioObject (readonly)

Returns the value of attribute io.



11
12
13
# File 'lib/xudoku/cli/screens/base.rb', line 11

def io
  @io
end

#readerObject (readonly)

Returns the value of attribute reader.



11
12
13
# File 'lib/xudoku/cli/screens/base.rb', line 11

def reader
  @reader
end

Instance Method Details

#paint_screen(event = nil) ⇒ Object



26
27
28
# File 'lib/xudoku/cli/screens/base.rb', line 26

def paint_screen(event = nil)
  # To be implemented in sub classes
end

#redraw!Object



46
47
48
# File 'lib/xudoku/cli/screens/base.rb', line 46

def redraw!
  @first_render = true
end

#renderObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/xudoku/cli/screens/base.rb', line 30

def render
  write TTY::Cursor.clear_screen

  reader.on :keypress do |event|
    paint_screen(KeyEvent.new(event))
  end

  # Paint the first time
  paint_screen
  @first_render = false

  loop do
    reader.read_keypress
  end
end

#setupObject



22
23
24
# File 'lib/xudoku/cli/screens/base.rb', line 22

def setup
  # To be implemented in sub classes
end