lib/shellplay/session.rb in shellplay-0.1.1 vs lib/shellplay/session.rb in shellplay-0.1.2

- old
+ new

@@ -8,14 +8,15 @@ module Shellplay class Session include Cliprompt - attr_reader :title, :config, :pointer, :sequence, :prompt, :timeformat + attr_reader :title, :name, :config, :pointer, :sequence, :prompt, :timeformat def initialize(basedir = nil, basefile = nil, input = STDIN, output = STDOUT) @sequence = [] + @name = false @title = false @prompt = false @timeformat = false @pointer = 0 @basedir = basedir || File.join(ENV['HOME'], '.shellplay') @@ -29,23 +30,26 @@ sessions = Dir.glob(File.join(@basedir, '*.json')) if sessions.count == 0 @output.puts "There is no recorded session locally." @output.puts "Do you want to play a remote recording?" name = ask "url: " + session_name = File.basename(name, '.json') else @output.puts "What session do you want to load?" name = ask "(input a number or an url if you want to play a remote recording)", aslist: true, choices: sessions.map { |f| File.basename(f, '.json') } + session_name = name end end if /^https?:\/\//.match name infile = open(name) { |f| f.read } else infile = IO.read(File.join(@basedir, "#{name}.json")) end data = JSON.parse(infile) + @name = session_name @title = data['title'] @config = Shellplay::Config.new({ basedir: @basedir, basefile: File.join(@basedir, @basefile), prompt: data['prompt'], @@ -90,10 +94,10 @@ def save prepare h = {} h[:title] = @title h[:sequence] = @sequence.map(&:export) - outfile = File.join(@config.basedir, "#{@name}.json") + outfile = File.join(@basedir, "#{@name}.json") File.open(outfile, 'w') do |f| f.write JSON.pretty_generate(h) end end