Class: Tatty::Stage
- Inherits:
-
Object
- Object
- Tatty::Stage
- Defined in:
- lib/tatty/stage.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#framerate ⇒ Object
Returns the value of attribute framerate.
Instance Method Summary collapse
- #draw ⇒ Object
- #goto(klass, **kargs) ⇒ Object
-
#initialize ⇒ Stage
constructor
A new instance of Stage.
- #keypress(evt) ⇒ Object
- #leave ⇒ Object
- #move_to(x, y) ⇒ Object
- #render(out) ⇒ Object
- #render_at(x, y, out) ⇒ Object
- #render_box(*content, **kwargs, &block) ⇒ Object
- #screen_height ⇒ Object
- #screen_size ⇒ Object
- #screen_width ⇒ Object
- #step ⇒ Object
Constructor Details
#initialize ⇒ Stage
Returns a new instance of Stage.
9 10 11 12 13 |
# File 'lib/tatty/stage.rb', line 9 def initialize @cursor = TTY::Cursor @framerate = 0.1 @buffer = "" end |
Instance Attribute Details
#framerate ⇒ Object
Returns the value of attribute framerate.
7 8 9 |
# File 'lib/tatty/stage.rb', line 7 def framerate @framerate end |
Instance Method Details
#draw ⇒ Object
53 54 55 |
# File 'lib/tatty/stage.rb', line 53 def draw render "not implemented" end |
#goto(klass, **kargs) ⇒ Object
18 19 20 |
# File 'lib/tatty/stage.rb', line 18 def goto(klass, **kargs) ::Tatty.goto(klass, **kargs) end |
#keypress(evt) ⇒ Object
22 23 |
# File 'lib/tatty/stage.rb', line 22 def keypress(evt) end |
#leave ⇒ Object
15 16 |
# File 'lib/tatty/stage.rb', line 15 def leave end |
#move_to(x, y) ⇒ Object
37 38 39 |
# File 'lib/tatty/stage.rb', line 37 def move_to(x, y) render @cursor.move_to(x, y) end |
#render(out) ⇒ Object
41 42 43 |
# File 'lib/tatty/stage.rb', line 41 def render(out) @buffer += out end |
#render_at(x, y, out) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/tatty/stage.rb', line 45 def render_at(x, y, out) out.to_s.each_line do |line| render @cursor.move_to(x, y) render line y += 1 end end |
#render_box(*content, **kwargs, &block) ⇒ Object
69 70 71 72 73 74 |
# File 'lib/tatty/stage.rb', line 69 def render_box(*content, **kwargs, &block) render @cursor.save move_to(0, 0) render TTY::Box.frame(*content, **kwargs, &block) render @cursor.restore end |
#screen_height ⇒ Object
33 34 35 |
# File 'lib/tatty/stage.rb', line 33 def screen_height TTY::Screen.height end |
#screen_size ⇒ Object
25 26 27 |
# File 'lib/tatty/stage.rb', line 25 def screen_size TTY::Screen.size end |
#screen_width ⇒ Object
29 30 31 |
# File 'lib/tatty/stage.rb', line 29 def screen_width TTY::Screen.width end |
#step ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/tatty/stage.rb', line 57 def step last_buffer = @buffer @buffer = "" render @cursor.clear_screen move_to(0, 0) self.draw if last_buffer != @buffer print @buffer end sleep(@framerate) end |