Class: Tatty::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/tatty/stage.rb

Direct Known Subclasses

Petli::Stages::Base

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStage

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

#framerateObject

Returns the value of attribute framerate.



7
8
9
# File 'lib/tatty/stage.rb', line 7

def framerate
  @framerate
end

Instance Method Details

#drawObject



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

#leaveObject



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_heightObject



33
34
35
# File 'lib/tatty/stage.rb', line 33

def screen_height
  TTY::Screen.height
end

#screen_sizeObject



25
26
27
# File 'lib/tatty/stage.rb', line 25

def screen_size
  TTY::Screen.size
end

#screen_widthObject



29
30
31
# File 'lib/tatty/stage.rb', line 29

def screen_width
  TTY::Screen.width
end

#stepObject



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