Class: Cased::CLI::Recorder
- Inherits:
-
Object
- Object
- Cased::CLI::Recorder
- Defined in:
- lib/cased/cli/recorder.rb
Constant Summary collapse
- KEY =
'CASED_CLI_RECORDING'
- TRUE =
'1'
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#events ⇒ Object
readonly
Returns the value of attribute events.
-
#height ⇒ Object
readonly
Returns the value of attribute height.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#width ⇒ Object
readonly
Returns the value of attribute width.
-
#writer ⇒ Object
Returns the value of attribute writer.
Class Method Summary collapse
-
.recording? ⇒ Boolean
If CLI session is being recorded.
Instance Method Summary collapse
-
#initialize(command, env: {}) ⇒ Recorder
constructor
A new instance of Recorder.
- #start ⇒ Object
Constructor Details
#initialize(command, env: {}) ⇒ Recorder
Returns a new instance of Recorder.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/cased/cli/recorder.rb', line 19 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 |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
11 12 13 |
# File 'lib/cased/cli/recorder.rb', line 11 def command @command end |
#events ⇒ Object (readonly)
Returns the value of attribute events.
11 12 13 |
# File 'lib/cased/cli/recorder.rb', line 11 def events @events end |
#height ⇒ Object (readonly)
Returns the value of attribute height.
11 12 13 |
# File 'lib/cased/cli/recorder.rb', line 11 def height @height end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/cased/cli/recorder.rb', line 11 def @options end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at.
11 12 13 |
# File 'lib/cased/cli/recorder.rb', line 11 def started_at @started_at end |
#width ⇒ Object (readonly)
Returns the value of attribute width.
11 12 13 |
# File 'lib/cased/cli/recorder.rb', line 11 def width @width end |
#writer ⇒ Object
Returns the value of attribute writer.
12 13 14 |
# File 'lib/cased/cli/recorder.rb', line 12 def writer @writer end |
Class Method Details
Instance Method Details
#start ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cased/cli/recorder.rb', line 40 def start writer.time do Subprocess.check_call(command, ) do |t| t.communicate do |stdout, _stderr| $stdout.write(stdout) writer << stdout.gsub("\n", "\r\n") end end end end |