Class: VeryGood::Terminal

Inherits:
Object
  • Object
show all
Defined in:
lib/very_good/terminal.rb

Instance Method Summary collapse

Constructor Details

#initialize(width:, height:) ⇒ Terminal

Returns a new instance of Terminal.



3
4
5
# File 'lib/very_good/terminal.rb', line 3

def initialize(width:, height:)
  @state = State.new(width: width, height: height)
end

Instance Method Details

#clear!Object



28
29
30
# File 'lib/very_good/terminal.rb', line 28

def clear!
  output.write Ansi.clear
end

#move_cursor(x, y) ⇒ Object



32
33
34
# File 'lib/very_good/terminal.rb', line 32

def move_cursor(x, y)
  output.write Ansi.move_cursor(x, y)
end

#stateObject



7
8
9
# File 'lib/very_good/terminal.rb', line 7

def state
  @state
end

#state=(other) ⇒ Object



11
12
13
# File 'lib/very_good/terminal.rb', line 11

def state=(other)
  @state = other
end

#update!Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/very_good/terminal.rb', line 15

def update!
  clear!
  move_cursor(0, 0)

  state.lines.each do |line|
    line.each do |cell|
      output.write(cell.char)
    end
  end

  move_cursor(state.cursor.x, state.cursor.y)
end