lib/shellplay/session.rb in shellplay-0.0.10 vs lib/shellplay/session.rb in shellplay-0.0.11

- old
+ new

@@ -1,31 +1,40 @@ require "cliprompt" require "json" +require "open-uri" require "shellplay/config" require "shellplay/screen" module Shellplay class Session include Cliprompt - attr_reader :title, :config, :pointer, :sequence + attr_reader :title, :config, :pointer, :sequence, :prompt, :timeformat def initialize(input = STDIN, output = STDOUT) @sequence = [] @title = false + @prompt = false + @timeformat = false @config = Shellplay::Config.new(nil, input, output) @pointer = 0 end def import(name) name ||= ask "What session do you want to load?", aslist: true, choices: Dir.glob(File.join(@config.basedir, '*.json')).map { |f| File.basename(f, '.json') } - infile = File.join(@config.basedir, "#{name}.json") - data = JSON.parse(IO.read(infile)) + if /^https?:\/\//.match name + infile = open(name) { |f| f.read } + else + infile = IO.read(File.join(@config.basedir, "#{name}.json")) + end + data = JSON.parse(infile) @title = data['title'] + @prompt = data['prompt'] + @timeformat = data['timeformat'] data['sequence'].each do |screenhash| add_screen(screenhash) end end