Sha256: ab55953bcdb9a4f602f7a694e4c765d21dd2dc4609ad030700716b4013e44c59

Contents?: true

Size: 1.21 KB

Versions: 1

Compression:

Stored size: 1.21 KB

Contents

#!/usr/bin/env ruby

require 'paint'
require 'open3'

lib = File.expand_path('../../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)

require 'shellplay'

continue = true
sleeptime = 1.0/48.0

session = Shellplay::Session.new
prompt = "\e[36mrecord >\e[0m"

while continue do
  printf("\e[36mrecord >\e[33m %d > \e[0m", session.pointer)
  command = STDIN.gets.strip
  if command == "q"
    session.save
    puts "\nRecord ended.\n"
    continue = false
  else
    if command[0] == '#'
      command = command[1..-1].strip
      displaycommand = false
    else
      displaycommand = true
    end
    start_time = Time.now
    Open3.popen3("bash","-l","-c",command) do |i, o, e, t|
      screen = Shellplay::Screen.new
      out = o.read
      err = e.read
      end_time = Time.now
      elapsed = end_time - start_time
      session.add_screen({
        'displaycommand' => displaycommand,
        'stdin' => command,
        'stdout' => out,
        'stderr' => err,
        'timespent' => elapsed
        })
      out.split("\n").each do |line|
        puts line
        sleep sleeptime
      end
      err.split("\n").each do |line|
        puts Paint[line, :red]
      end
    end
    session.next
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shellplay-0.0.3 bin/shellrecord