class Cased::CLI::Asciinema::Writer

Constants

VERSION

Attributes

command[R]
finished_at[R]
height[RW]
started_at[R]
stream[R]
width[RW]

Public Class Methods

new(command: [], width: 80, height: 24) click to toggle source
# File lib/cased/cli/asciinema/writer.rb, line 19
def initialize(command: [], width: 80, height: 24)
  @command = command
  @width = width
  @height = height
  @stream = []
  @started_at = Time.now
end

Public Instance Methods

<<(output) click to toggle source
# File lib/cased/cli/asciinema/writer.rb, line 27
def <<(output)
  stream << [Time.now - started_at, 'o', output]
end
header() click to toggle source
# File lib/cased/cli/asciinema/writer.rb, line 46
def header
  {
    'version' => VERSION,
    'env' => {
      'SHELL' => ENV['SHELL'],
      'TERM' => ENV['TERM'],
    },
    'width' => width,
    'height' => height,
    'command' => command.join(' '),
  }.tap do |h|
    if started_at
      h['timestamp'] = started_at.to_i
    end

    if started_at && finished_at
      h['duration'] = finished_at - started_at
    end
  end
end
time() { || ... } click to toggle source
# File lib/cased/cli/asciinema/writer.rb, line 31
def time
  @started_at = Time.now
  ret = yield
  @finished_at = Time.now
  ret
end
to_cast() click to toggle source
# File lib/cased/cli/asciinema/writer.rb, line 38
def to_cast
  # In the event we didn't run the writer in a #time block, we should
  # set the finished time if it isn't set.
  @finished_at ||= Time.now

  File.new(header, stream).to_cast
end