Class: Xudoku::Cli::Screens::Base
- Inherits:
-
Object
- Object
- Xudoku::Cli::Screens::Base
- Defined in:
- lib/xudoku/cli/screens/base.rb
Overview
:nodoc:
Constant Summary collapse
- TITLE_HEIGHT =
3- TITLE =
"X u d o k u"
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#first_render ⇒ Object
readonly
Returns the value of attribute first_render.
-
#io ⇒ Object
readonly
Returns the value of attribute io.
-
#reader ⇒ Object
readonly
Returns the value of attribute reader.
Instance Method Summary collapse
-
#initialize(app:, io:) ⇒ Base
constructor
A new instance of Base.
- #paint_screen(event = nil) ⇒ Object
- #redraw! ⇒ Object
- #render ⇒ Object
- #setup ⇒ Object
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
#app ⇒ Object (readonly)
Returns the value of attribute app.
11 12 13 |
# File 'lib/xudoku/cli/screens/base.rb', line 11 def app @app end |
#first_render ⇒ Object (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 |
#io ⇒ Object (readonly)
Returns the value of attribute io.
11 12 13 |
# File 'lib/xudoku/cli/screens/base.rb', line 11 def io @io end |
#reader ⇒ Object (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 |
#render ⇒ Object
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 |
#setup ⇒ Object
22 23 24 |
# File 'lib/xudoku/cli/screens/base.rb', line 22 def setup # To be implemented in sub classes end |