Sha256: 8061b5e3e7349e0042fce1c0e3e037b0fb9eefd03e762db8298d652dbbf7d3fa
Contents?: true
Size: 1.23 KB
Versions: 4
Compression:
Stored size: 1.23 KB
Contents
# frozen_string_literal: true require 'subprocess' module Cased module CLI class Recorder KEY = 'CASED_CLI_RECORDING' TRUE = '1' attr_reader :command, :events, :started_at, :width, :height, :options attr_accessor :writer # @return [Boolean] if CLI session is being recorded. def self.recording? ENV[KEY] == TRUE end def initialize(command, env: {}) @command = command @events = [] @width = Subprocess.check_output(%w[tput cols]).strip.to_i @height = Subprocess.check_output(%w[tput lines]).strip.to_i subprocess_env = ENV.to_h.dup subprocess_env[KEY] = TRUE subprocess_env.merge!(env) @writer = Cased::CLI::Asciinema::Writer.new( command: command, width: width, height: height, ) @options = { stdout: Subprocess::PIPE, env: subprocess_env, } end def start writer.time do Subprocess.check_call(command, options) do |t| t.communicate do |stdout, _stderr| $stdout.write(stdout) writer << stdout.gsub("\n", "\r\n") end end end end end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
cased-ruby-0.8.0 | lib/cased/cli/recorder.rb |
cased-ruby-0.7.1 | lib/cased/cli/recorder.rb |
cased-ruby-0.7.0 | lib/cased/cli/recorder.rb |
cased-ruby-0.6.1 | lib/cased/cli/recorder.rb |