trecs 0.0.9 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e99047b216ec42e9c6b739b7b1563954a71d0a25
4
- data.tar.gz: 21164adc5f38c05126e72f7296f27ed98fd48a83
3
+ metadata.gz: 757f42c4df411d64d4dc4d17376c0f745bd944da
4
+ data.tar.gz: e36e0606e3856f86687f4a541c9c359878ada950
5
5
  SHA512:
6
- metadata.gz: 3de81b0147f53c3d85092c99e709f52e5d1be3f3b69fcb8892456714ed6b9cce1e606252d60a27219a5ae9a57ebdb94cb9a7ead785e82ebf09031d14723d6530
7
- data.tar.gz: 384093b957ef8bb64469f2e90768d1101bc0d37d9ab0c3d656a912f970f0b1f6acbac25f120e682e3b8e1613817d33d256dcd7c11c8623aa04d3e77d5bf7ae07
6
+ metadata.gz: dc09b46d6ea86b06692337e2d449576ff3881505c9084592855d6a2c89f94dc42cf80c1119d6aebae34a98a80239c903378f7d052acf668be2b7144494066862
7
+ data.tar.gz: e558d76ab3bf1277184acc067db519a9b99c3b8e6687b9607bf5ddda5c5ee7fe775d9b249da9924506db463e7ba244af44981f2b9884cf53efcacc2a2d8aa328
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trecs (0.0.9)
4
+ trecs (0.1.0)
5
5
  rubyzip (~> 1.1.4)
6
6
  trollop (~> 2.0)
7
7
 
data/bin/trecs CHANGED
@@ -41,7 +41,9 @@ player_options = {
41
41
  step: opts[:step],
42
42
  }
43
43
 
44
- #p opts
45
- #p player_options
46
44
  player = TRecs::Player.new(player_options)
47
45
  player.play
46
+
47
+ puts "Finished"
48
+ puts "Replay with:"
49
+ puts " bin/trecs #{opts[:trecs_file]}"
data/bin/trecs_record ADDED
@@ -0,0 +1,66 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.expand_path("../../lib", __FILE__))
4
+ require "trecs"
5
+ require "recorder"
6
+ require "trollop"
7
+
8
+
9
+ opts = Trollop::options do
10
+ opt :step, "Time in ms between frames", short: 's', default: 100
11
+ opt :format, "File format", type: String, default: "yaml_store"
12
+ opt :strategy, "Strategy", type: String, default: "incremental"
13
+
14
+ opt :message, "Message to record", type: String, default: "TRecs!"
15
+ opt :input_file, "File to record", type: String, default: ""
16
+ opt :terminal, "Launch terminal", default: true
17
+
18
+ end
19
+ opts[:trecs_file] = ARGV[0]
20
+
21
+ writer_file = "writers/#{opts[:format]}_writer"
22
+ require writer_file
23
+ writer_class = Kernel.const_get([
24
+ "TRecs::",
25
+ opts[:format].split(/[-_\s]/).map(&:capitalize),
26
+ "Writer"
27
+ ].join
28
+ )
29
+
30
+
31
+ strategy_file = "recording_strategies/#{opts[:strategy]}_strategy"
32
+ require strategy_file
33
+ strategy_class = Kernel.const_get([
34
+ "TRecs::",
35
+ opts[:strategy].split(/[-_\s]/).map(&:capitalize),
36
+ "Strategy"
37
+ ].join
38
+ )
39
+
40
+
41
+
42
+ puts "Recording ..."
43
+
44
+ if strategy_class == TRecs::TtyrecStrategy
45
+ opts[:height], opts[:width] = `stty size`.split(" ").map(&:to_i)
46
+ system "ttyrec #{opts[:input_file]}" if opts[:terminal]
47
+ end
48
+
49
+ recorder_options = {
50
+ writer: writer_class.new(opts),
51
+ strategy: strategy_class.new(opts),
52
+ step: opts[:step],
53
+ }
54
+
55
+
56
+ RECORDER = TRecs::Recorder.new(recorder_options)
57
+
58
+ trap "SIGINT" do
59
+ RECORDER.stop
60
+ end
61
+
62
+ RECORDER.record
63
+
64
+ puts "Recording finished"
65
+ puts "Play with:"
66
+ puts " bin/trecs #{opts[:trecs_file]}"
@@ -5,7 +5,7 @@ module TRecs
5
5
  attr_reader :file
6
6
 
7
7
  def initialize(options={})
8
- file = options.fetch(:file)
8
+ file = options.fetch(:input_file)
9
9
  @file = File.open(file)
10
10
 
11
11
  @clock = options.fetch(:clock) { Time }
@@ -0,0 +1,76 @@
1
+ module TRecs
2
+ class TtyrecStrategy
3
+ attr_accessor :recorder
4
+
5
+ def initialize(options={})
6
+ file = options.fetch(:input_file)
7
+ @file = File.new(file)
8
+ @frames = []
9
+ @full_output = ""
10
+ @height = options.fetch(:height) { 24 }
11
+ @width = options.fetch(:width) { 80 }
12
+ end
13
+
14
+ def perform
15
+ @prev_timestamp = 0
16
+ @prev_frame = ""
17
+ while !@file.eof?
18
+ sec, usec, len = @file.read(12).unpack('VVV')
19
+ curr_data = @file.read(len)
20
+ @full_output << curr_data
21
+
22
+ #data_array = @full_output.each_line.to_a
23
+ #height = data_array.size > @height ? @height : 0
24
+ #frame = data_array[-height..-1].join
25
+
26
+ frame = @prev_frame + curr_data
27
+
28
+ @first_timestamp ||= [ sec, usec ].join('.').to_f
29
+ curr_timestamp = [ sec, usec ].join('.').to_f
30
+ offset = ((curr_timestamp - @first_timestamp)*1000).to_i
31
+
32
+ if curr_timestamp > @prev_timestamp
33
+ recorder.current_frame(time: offset, content: frame)
34
+ @prev_timestamp = curr_timestamp
35
+ @prev_frame = frame
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+
42
+ # module TRecs
43
+ # class TtyrecStrategy
44
+ # attr_accessor :recorder
45
+
46
+ # def initialize(options={})
47
+ # file = options.fetch(:input_file)
48
+ # @file = File.new(file)
49
+ # @frames = []
50
+ # @full_output = ""
51
+ # @height = options.fetch(:height) { 24 }
52
+ # @width = options.fetch(:width) { 80 }
53
+ # end
54
+
55
+ # def perform
56
+ # @prev_timestamp = 0
57
+ # while !@file.eof?
58
+ # sec, usec, len = @file.read(12).unpack('VVV')
59
+ # @full_output << @file.read(len)
60
+
61
+ # data_array = @full_output.each_line.to_a
62
+ # height = data_array.size > @height ? @height : 0
63
+ # frame = data_array[-height..-1].join
64
+
65
+ # @first_timestamp ||= [ sec, usec ].join('.').to_f
66
+ # curr_timestamp = [ sec, usec ].join('.').to_f
67
+ # offset = ((curr_timestamp - @first_timestamp)*1000).to_i
68
+
69
+ # if curr_timestamp > @prev_timestamp
70
+ # recorder.current_frame(time: offset, content: frame)
71
+ # @prev_timestamp = curr_timestamp
72
+ # end
73
+ # end
74
+ # end
75
+ # end
76
+ # end
data/lib/trecs/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module TRecs
2
- VERSION = "0.0.9"
2
+ VERSION = "0.1.0"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'yaml/store'
2
+ require "fileutils"
2
3
 
3
4
  module TRecs
4
5
  class YamlStoreWriter
Binary file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: trecs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Federico Iachetti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-06-18 00:00:00.000000000 Z
11
+ date: 2014-06-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubyzip
@@ -129,6 +129,7 @@ executables:
129
129
  - trecs
130
130
  - trecs_message
131
131
  - trecs_raw_file
132
+ - trecs_record
132
133
  - trecs_terminal
133
134
  extensions: []
134
135
  extra_rdoc_files: []
@@ -146,6 +147,7 @@ files:
146
147
  - bin/trecs
147
148
  - bin/trecs_message
148
149
  - bin/trecs_raw_file
150
+ - bin/trecs_record
149
151
  - bin/trecs_terminal
150
152
  - doc/steps.org
151
153
  - lib/players/zip_file_player.rb
@@ -162,7 +164,7 @@ files:
162
164
  - lib/trecs/recording_strategies/hash_strategy.rb
163
165
  - lib/trecs/recording_strategies/incremental_strategy.rb
164
166
  - lib/trecs/recording_strategies/raw_file_strategy.rb
165
- - lib/trecs/recording_strategies/ttyrec_recording_strategy.rb
167
+ - lib/trecs/recording_strategies/ttyrec_strategy.rb
166
168
  - lib/trecs/screens/terminal_screen.rb
167
169
  - lib/trecs/tickers/terminal_input_ticker.rb
168
170
  - lib/trecs/tickers/ticker.rb
@@ -186,6 +188,7 @@ files:
186
188
  - pkg/trecs-0.0.6.gem
187
189
  - pkg/trecs-0.0.7.gem
188
190
  - pkg/trecs-0.0.8.gem
191
+ - pkg/trecs-0.0.9.gem
189
192
  - sandbox/create_recording.rb
190
193
  - sandbox/lipsum_end
191
194
  - sandbox/lipsum_start
@@ -1,30 +0,0 @@
1
- require "recording_strategy"
2
- module TRecs
3
- class TtyrecRecordingStrategy < RecordingStrategy
4
- def initialize(file:, height: 24, width: 80, **options)
5
- @file = File.new(file)
6
- @frames = []
7
- @full_output = ""
8
- @height = height
9
- @width = width
10
- super
11
- end
12
-
13
- def perform
14
- while !@file.eof?
15
- sec, usec, len = @file.read(12).unpack('VVV')
16
- @full_output << @file.read(len)
17
-
18
- data_array = @full_output.each_line.to_a
19
- height = data_array.size > @height ? @height : 0
20
- frame = data_array[-height..-1].join
21
-
22
- prev_timestamp ||= [ sec, usec ].join('.').to_f
23
- curr_timestamp = [ sec, usec ].join('.').to_f
24
- offset = ((curr_timestamp - prev_timestamp)*1000).to_i
25
-
26
- recorder.current_frame(time: offset, content: frame)
27
- end
28
- end
29
- end
30
- end