Module: Tatty

Defined in:
lib/tatty.rb,
lib/tatty/db.rb,
lib/tatty/anim.rb,
lib/tatty/atlas.rb,
lib/tatty/stage.rb

Defined Under Namespace

Classes: Anim, Atlas, DB, Stage

Class Method Summary collapse

Class Method Details

.goto(klass, **kargs) ⇒ Object



35
36
37
38
# File 'lib/tatty.rb', line 35

def self.goto(klass, **kargs)
  @stage.leave unless @stage.nil?
  @stage = klass.new(**kargs)
end

.run(klass, **kargs) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/tatty.rb', line 10

def self.run(klass, **kargs)
  self.goto(klass, **kargs)
  @reader = TTY::Reader.new
  @reader.on(:keypress) do |event|
    self.stage.keypress(event)
  end

  begin
    TTY::Cursor.invisible do
      while true
        @reader.read_keypress(nonblock: true)
        @stage.step
      end
    end
  rescue Interrupt => e
  ensure
    print TTY::Cursor.clear_screen
    print TTY::Cursor.move_to(0, 0)
  end
end

.stageObject



31
32
33
# File 'lib/tatty.rb', line 31

def self.stage
  @stage
end