class ShellCast::Recorder
Constants
- FOOTER
- HEADER
Public Class Methods
new()
click to toggle source
# File lib/shellcast/recorder.rb, line 39 def initialize @meta = {} end
record!()
click to toggle source
# File lib/shellcast/recorder.rb, line 35 def self.record! new.record! end
Public Instance Methods
record!()
click to toggle source
# File lib/shellcast/recorder.rb, line 43 def record! test_shellcast_data_dir request_metadata puts HEADER.black_on_white puts "Your session started" puts "Type Ctrl+D or exit to finish recording" init_terminal system(script_cmd) restore_terminal puts FOOTER.black_on_white puts "hint $ shellcast play #{shellcast_id}".green end
request_metadata()
click to toggle source
# File lib/shellcast/recorder.rb, line 56 def request_metadata print "Provide name for Your shellcast: " @meta["title"] = STDIN.gets.strip @meta["created_at"] = shellcast_id puts shellcast_file('meta') File.open(shellcast_file('meta'), 'w+') do |meta| meta.puts @meta.to_json end end
Private Instance Methods
init_terminal()
click to toggle source
# File lib/shellcast/recorder.rb, line 72 def init_terminal stty_data = `stty -a` @user_columns = stty_data.match(/columns (\d+)/)[1] @user_rows = stty_data.match(/rows (\d+)/)[1] puts "Saved terminal size #{@user_columns}X#{@user_rows}" system("stty columns 80 rows 24") end
restore_terminal()
click to toggle source
# File lib/shellcast/recorder.rb, line 80 def restore_terminal system("stty columns #{@user_columns} rows #{@user_rows}") end
script_cmd()
click to toggle source
# File lib/shellcast/recorder.rb, line 96 def script_cmd "script -c 'bash' #{shellcast_file('typescript')} -t 2> #{shellcast_file('timing')}" end
shellcast_dir()
click to toggle source
# File lib/shellcast/recorder.rb, line 84 def shellcast_dir @shellcast_dir ||= ShellCast.shellcast_dir(shellcast_id) end
shellcast_file(name)
click to toggle source
# File lib/shellcast/recorder.rb, line 92 def shellcast_file(name) File.join(ShellCast.shellcast_dir(shellcast_id), name) end
shellcast_id()
click to toggle source
# File lib/shellcast/recorder.rb, line 88 def shellcast_id @shellcast_id ||= Time.now.to_i.to_s end
test_shellcast_data_dir()
click to toggle source
# File lib/shellcast/recorder.rb, line 68 def test_shellcast_data_dir FileUtils.mkdir_p(shellcast_dir) unless File.exists?(shellcast_dir) end