Class: Terminal

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

Defined Under Namespace

Classes: Process

Constant Summary collapse

BINARY_PATH =

BINARY_PATH = (File.dirname(__FILE__) + “/../../bin/” + “terminal”).to_s

'terminal'

Instance Method Summary collapse

Constructor Details

#initialize(width, height) ⇒ Terminal

Returns a new instance of Terminal.



12
13
14
# File 'lib/asciinema/terminal.rb', line 12

def initialize(width, height)
  @process = Process.new("#{BINARY_PATH} #{width} #{height}")
end

Instance Method Details

#cursorObject



28
29
30
31
32
33
# File 'lib/asciinema/terminal.rb', line 28

def cursor
  process.write("c\n")
  c = Yajl::Parser.new.parse(process.read_line)

  Cursor.new(c['x'], c['y'], c['visible'])
end

#feed(data) ⇒ Object



16
17
18
19
# File 'lib/asciinema/terminal.rb', line 16

def feed(data)
  process.write("d\n#{data.bytesize}\n")
  process.write(data)
end

#releaseObject



35
36
37
# File 'lib/asciinema/terminal.rb', line 35

def release
  process.stop
end

#snapshotObject



21
22
23
24
25
26
# File 'lib/asciinema/terminal.rb', line 21

def snapshot
  process.write("p\n")
  lines = Yajl::Parser.new.parse(process.read_line)

  Snapshot.build(lines)
end