Sha256: 18e84ceb4aab60488080ae884e151bcd26897c840a6bbbe6a615b68ee4e4aa49
Contents?: true
Size: 1.98 KB
Versions: 1
Compression:
Stored size: 1.98 KB
Contents
#!/usr/bin/env ruby require 'paint' require 'json' require 'open3' lib = File.expand_path('../../lib', __FILE__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'shellplay/session' @session = Shellplay::Session.new @session.import(ARGV[0]) continue = true @sleeptime = 1.0/48.0 @lastelapsed = 0 counter = 1 def usage puts "\nCommands: " puts " h,? show help" puts " s list screens" puts " s# jump to screen #" puts " <enter> jump to next screen" puts " p jump to previous screen" puts " <command> execute a subcommand in a bash -l -c" puts " x,q quit" puts end def display(screen) if screen.displaycommand print @session.config.prompt sleep @sleeptime print screen.stdin STDIN.gets @lastelapsed = screen.timespent else @lastelapsed = 0 end puts screen.stdout puts Paint[screen.stderr, :red] end def shownext if @session.current_screen and @session.current_screen.stdin display @session.current_screen @session.next else puts "You are at the end of the session." @lastelapsed = 0 end end def show(index) if @session.show(index).stdin display @session.show(index) @session.next else puts "You are at the end of the session." @lastelapsed = 0 end end while continue do printf "\e[36m>\e[0m " printf "\e[35melapsed: #{@lastelapsed}s\e[0m " unless @lastelapsed == 0 command = STDIN.gets.strip case command when /^(?:q|x)$/ puts "\nPlay ended.\n" continue = false when /^(?:\?|h)$/ usage when /^s$/ @session.sequence.map { |c| c.stdin }.each_with_index do |l, i| printf(" s%-3s %s\n", i, l) end when /s([0-9]+)/ show($1) when '' shownext else Open3.popen3("bash","-l","-c",command.strip) do |i, o, e, t| o.read.split("\n").each do |line| puts line sleep sleeptime end e.read.split("\n").each do |line| puts Paint[line, :red] end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shellplay-0.0.3 | bin/shellplay |