vedeu 0.6.67 → 0.6.68

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: f0621e21742d8ad220683b0170dde12c52244fe6
4
- data.tar.gz: f66881ddd805fd68c13877553422736c74ac482c
3
+ metadata.gz: 850ce1133d6018ed381e4ddbb4ee9bdff12e4bbb
4
+ data.tar.gz: bb06f89c8568103c095e448fab6a2fc3eef3dfb8
5
5
  SHA512:
6
- metadata.gz: 2414b55833736a3e19e7f779bbe833721666bce2888d4280d9ef2c4a6161214dfae722525186e59ac0e0e0022907893b7014fc1945cc3819906323102e594a26
7
- data.tar.gz: 174b57ce52b732d279e9c5f9fdbf20a031c2574b2ea01f5a9852e5cc9f872c9a829f9b4b0cb6f06ec8f97e0f5618c8714dac868f3eeee23ccb473bbf065c1b3e
6
+ metadata.gz: 2cdb5a8f19a21d62dd57faead71646070464ac3072e3945d08b534a642be3ad52004e53bf8af4614c870cf18f332888595805e280f6863b8a18c36d8f07bc347
7
+ data.tar.gz: e045c49ba37aaf20676442a648f8e5c84bc99181835c3fd09f00b349aa21dd15926a5a76216cf6618bdf1af4e51dc60ffc3c422ab32cc869cec4281986a30e59
data/docs/api.md CHANGED
@@ -409,6 +409,10 @@ Returns the last keypress entered into Vedeu.
409
409
 
410
410
  @todo Add more documentation.
411
411
 
412
+ ### Vedeu.log_timestamp
413
+
414
+ @todo Add more documentation.
415
+
412
416
  ### Vedeu.menu
413
417
 
414
418
  @todo Add more documentation.
@@ -26,7 +26,7 @@ class EditorApp
26
26
 
27
27
  Vedeu.interface :help_view do
28
28
  geometry do
29
- height use(:editor_view).height
29
+ height 4
30
30
  width use(:editor_view).width
31
31
  x use(:editor_view).left
32
32
  y use(:editor_view).south
@@ -91,9 +91,11 @@ module Vedeu
91
91
 
92
92
  # See {file:docs/events/system.md#\_editor_}
93
93
  Vedeu.bind(:_editor_) do |key|
94
- Vedeu.trigger(:key, key)
94
+ Vedeu.timer('Executing editor keypress') do
95
+ Vedeu.trigger(:key, key)
95
96
 
96
- Vedeu::Editor::Editor.keypress(name: Vedeu.focus, input: key)
97
+ Vedeu::Editor::Editor.keypress(name: Vedeu.focus, input: key)
98
+ end
97
99
  end
98
100
 
99
101
  # :nocov:
@@ -88,7 +88,9 @@ module Vedeu
88
88
  return [] unless registered?(alias_name)
89
89
 
90
90
  find(alias_name).map do |event_name|
91
- Vedeu.log(type: :debug, message: "#{event_name}".freeze)
91
+ Vedeu.log(type: :event,
92
+ message: "Triggering: '#{event_name}' from alias " \
93
+ "'#{alias_name}'".freeze)
92
94
  Vedeu::Events::Trigger.trigger(event_name, *args)
93
95
  end
94
96
  end
@@ -157,11 +157,13 @@ module Vedeu
157
157
 
158
158
  # See {file:docs/events/system.md#\_keypress_}
159
159
  Vedeu.bind(:_keypress_) do |key, name|
160
- Vedeu.trigger(:key, key)
160
+ Vedeu.timer('Executing keypress') do
161
+ Vedeu.trigger(:key, key)
161
162
 
162
- Vedeu.add_keypress(key)
163
+ Vedeu.add_keypress(key)
163
164
 
164
- Vedeu.keypress(key, name)
165
+ Vedeu.keypress(key, name)
166
+ end
165
167
  end
166
168
 
167
169
  # See {file:docs/events/drb.md#\_drb_input_}
@@ -177,9 +179,11 @@ module Vedeu
177
179
 
178
180
  # See {file:docs/events/system.md#\_command_}
179
181
  Vedeu.bind(:_command_) do |command|
180
- Vedeu.add_command(command)
182
+ Vedeu.timer('Executing command') do
183
+ Vedeu.add_command(command)
181
184
 
182
- Vedeu.trigger(:command, command)
185
+ Vedeu.trigger(:command, command)
186
+ end
183
187
  end
184
188
 
185
189
  # :nocov:
@@ -196,6 +196,8 @@ module Vedeu
196
196
  # @see Vedeu::Logging::Log.log_stdout
197
197
  # @!method log_stderr
198
198
  # @see Vedeu::Logging::Log.log_stderr
199
+ # @!method log_timestamp
200
+ # @see Vedeu::Logging::Log.log_timestamp
199
201
  def_delegators Vedeu::Logging::Log,
200
202
  :log,
201
203
  :log_stdout,
@@ -48,7 +48,7 @@ module Vedeu
48
48
 
49
49
  # @return [Array<void>]
50
50
  def content
51
- cells.flatten << reset_character
51
+ (cells.flatten << reset_character).reject(&:cell?)
52
52
  end
53
53
 
54
54
  # Provides iteration over the collection.
@@ -96,7 +96,7 @@ module Vedeu
96
96
 
97
97
  # @return [Vedeu::Geometries::Position]
98
98
  def position
99
- @position = Vedeu::Geometries::Position.coerce(@attributes[:position])
99
+ @position ||= Vedeu::Geometries::Position.coerce(@attributes[:position])
100
100
  end
101
101
 
102
102
  # Sets the position of the Vedeu::Views::Char.
@@ -6,6 +6,7 @@ module Vedeu
6
6
 
7
7
  end # Vedeu
8
8
 
9
+ require 'vedeu/output/compressor_cache'
9
10
  require 'vedeu/output/compressor'
10
11
  require 'vedeu/output/text'
11
12
  require 'vedeu/output/output'
@@ -33,10 +33,11 @@ module Vedeu
33
33
  end
34
34
 
35
35
  # @note
36
- # Takes approximately ~25ms for 2100 chars. (2015-07-25)
36
+ # - Takes approximately ~6ms for 2100 chars. (2015-11-25)
37
+ # - Takes approximately ~25ms for 2100 chars. (2015-07-25)
37
38
  # @return [String]
38
39
  def render
39
- return compress if Vedeu::Configuration.compression?
40
+ return cached if Vedeu::Configuration.compression?
40
41
 
41
42
  uncompress
42
43
  end
@@ -60,9 +61,26 @@ module Vedeu
60
61
  end
61
62
  end
62
63
 
64
+ def cached
65
+ cached_original = Vedeu::Output::CompressorCache.read(:original)
66
+ cached_compressed = Vedeu::Output::CompressorCache.read(:compressed)
67
+
68
+ if content.size == cached_original.size && content == cached_original
69
+ cached_compressed
70
+
71
+ else
72
+ Vedeu::Output::CompressorCache.write(:original, content)
73
+ Vedeu::Output::CompressorCache.write(:compressed, compress)
74
+ compress
75
+
76
+ end
77
+ end
78
+
63
79
  # @return [String]
64
80
  def compress
65
- Vedeu.timer("Compression for #{content.size} objects".freeze) do
81
+ message = "Compression for #{content.size} objects".freeze
82
+
83
+ @compress ||= Vedeu.timer(message) do
66
84
  out = content.map do |cell|
67
85
  [
68
86
  # position_for(cell),
@@ -73,9 +91,9 @@ module Vedeu
73
91
  ].join
74
92
  end.join
75
93
 
94
+
76
95
  Vedeu.log(type: :compress,
77
- message: "Compression: #{content.size} objects -> " \
78
- "#{out.size} characters".freeze)
96
+ message: "#{message} -> #{out.size} characters".freeze)
79
97
 
80
98
  out
81
99
  end
@@ -0,0 +1,61 @@
1
+ module Vedeu
2
+
3
+ module Output
4
+
5
+ module CompressorCache
6
+
7
+ extend self
8
+
9
+ # @param key [NilClass|Symbol]
10
+ # @return [Array<void>]
11
+ def read(key)
12
+ storage.fetch(key, [])
13
+ end
14
+
15
+ # @return [Hash<Symbol => Array<void>>]
16
+ def reset!
17
+ @storage = in_memory
18
+ end
19
+ alias_method :reset, :reset!
20
+
21
+ # @return [Hash<Symbol => Array<void>>]
22
+ def storage
23
+ @storage ||= in_memory
24
+ end
25
+
26
+ # @param key [NilClass|Symbol]
27
+ # @param value [Array|NilClass]
28
+ # @return [Hash<Symbol => Array<void>>]
29
+ def write(key, value)
30
+ return storage if invalid_key?(key) || invalid_value?(value)
31
+
32
+ storage.merge!(key => value)
33
+ end
34
+
35
+ private
36
+
37
+ # @return [Hash<Symbol => Array<void>>]
38
+ def in_memory
39
+ {
40
+ compressed: '',
41
+ original: [],
42
+ }
43
+ end
44
+
45
+ # @param key [NilClass|Symbol]
46
+ # @return [Boolean]
47
+ def invalid_key?(key)
48
+ key.nil? || !in_memory.keys.include?(key)
49
+ end
50
+
51
+ # @param value [Array|NilClass]
52
+ # @return [Boolean]
53
+ def invalid_value?(value)
54
+ value.nil? || value.empty?
55
+ end
56
+
57
+ end # CompressorCache
58
+
59
+ end # Output
60
+
61
+ end # Vedeu
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.67'.freeze
4
+ VERSION = '0.6.68'.freeze
5
5
 
6
6
  end
@@ -8,7 +8,13 @@ module Vedeu
8
8
 
9
9
  let(:described) { Vedeu::Models::Row }
10
10
  let(:instance) { described.new(cells) }
11
- let(:cells) { [:hydrogen, :helium, :lithium] }
11
+ let(:cells) {
12
+ [
13
+ Vedeu::Views::Char.new(value: 'A'),
14
+ Vedeu::Models::Cell.new(value: 'B'),
15
+ Vedeu::Views::Char.new(value: 'C'),
16
+ ]
17
+ }
12
18
 
13
19
  describe '#initialize' do
14
20
  it { instance.must_be_instance_of(described) }
@@ -69,9 +75,11 @@ module Vedeu
69
75
 
70
76
  context 'when the index is not nil' do
71
77
  context 'and the index is in range' do
72
- let(:index) { 1 }
78
+ let(:expected) { Vedeu::Views::Char.new(value: 'C') }
73
79
 
74
- it { subject.must_equal(:helium) }
80
+ let(:index) { 2 }
81
+
82
+ it { subject.must_equal(expected) }
75
83
  end
76
84
 
77
85
  context 'and the index is out of range' do
@@ -88,11 +96,19 @@ module Vedeu
88
96
  end
89
97
  end
90
98
 
91
- # describe '#content' do
92
- # subject { instance.content }
99
+ describe '#content' do
100
+ let(:expected) {
101
+ [
102
+ Vedeu::Views::Char.new(value: 'A'),
103
+ Vedeu::Views::Char.new(value: 'C'),
104
+ Vedeu::Views::Char.new(value: "\e[0m"),
105
+ ]
106
+ }
107
+
108
+ subject { instance.content }
93
109
 
94
- # it { subject.must_equal() }
95
- # end
110
+ it { subject.must_equal(expected) }
111
+ end
96
112
 
97
113
  describe '#each' do
98
114
  subject { instance.each }
@@ -0,0 +1,148 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Output
6
+
7
+ # class CompressorCacheTestClass
8
+ # end
9
+
10
+ describe CompressorCache do
11
+
12
+ let(:described) { Vedeu::Output::CompressorCache }
13
+ let(:empty) {
14
+ {
15
+ compressed: '',
16
+ original: [],
17
+ }
18
+ }
19
+
20
+ before { described.reset! }
21
+
22
+ describe '#read' do
23
+ let(:key) {}
24
+
25
+ subject { described.read(key) }
26
+
27
+ context 'when the key is nil' do
28
+ it { subject.must_equal([]) }
29
+ end
30
+
31
+ context 'when the key is not :compressed or :original' do
32
+ let(:key) { :invalid }
33
+
34
+ it { subject.must_equal([]) }
35
+ end
36
+
37
+ context 'when the key is :compressed' do
38
+ let(:key) { :compressed }
39
+
40
+ context 'when there is no compressed data stored' do
41
+ it { subject.must_equal('') }
42
+ end
43
+
44
+ context 'when there is compressed data stored' do
45
+ before { described.write(:compressed, 'compressed_data') }
46
+
47
+ it { subject.must_equal('compressed_data') }
48
+ end
49
+ end
50
+
51
+ context 'when the key is :original' do
52
+ let(:key) { :original }
53
+
54
+ context 'when there is no original data stored' do
55
+ it { subject.must_equal([]) }
56
+ end
57
+
58
+ context 'when there is original data stored' do
59
+ before { described.write(:original, [:original_data]) }
60
+
61
+ it { subject.must_equal([:original_data]) }
62
+ end
63
+ end
64
+ end
65
+
66
+ describe '#reset!' do
67
+ before { described.write(:original, [:original_data]) }
68
+
69
+ subject { described.reset! }
70
+
71
+ it { described.must_respond_to(:reset) }
72
+ it { subject.must_equal(empty) }
73
+ end
74
+
75
+ describe '#storage' do
76
+ subject { described.storage }
77
+
78
+ context 'when the storage is empty' do
79
+ it { subject.must_equal(empty) }
80
+ end
81
+
82
+ context 'when the storage is not empty' do
83
+ let(:expected) {
84
+ {
85
+ compressed: 'compressed_data',
86
+ original: [:original_data],
87
+ }
88
+ }
89
+
90
+ before {
91
+ described.write(:original, [:original_data])
92
+ described.write(:compressed, 'compressed_data')
93
+ }
94
+
95
+ it { subject.must_equal(expected) }
96
+ end
97
+ end
98
+
99
+ describe '#write' do
100
+ let(:key) {}
101
+ let(:_value) {}
102
+
103
+ subject { described.write(key, _value) }
104
+
105
+ context 'when the key is invalid' do
106
+ context 'when the key is nil' do
107
+ it { subject.must_equal(empty) }
108
+ end
109
+
110
+ context 'when the key is invalid' do
111
+ let(:key) { :invalid }
112
+
113
+ it { subject.must_equal(empty) }
114
+ end
115
+ end
116
+
117
+ context 'when the key is valid' do
118
+ let(:key) { :compressed }
119
+
120
+ context 'when the value is nil' do
121
+ it { subject.must_equal(empty) }
122
+ end
123
+
124
+ context 'when the value is empty' do
125
+ let(:_value) { [] }
126
+
127
+ it { subject.must_equal(empty) }
128
+ end
129
+
130
+ context 'when the value is not nil or empty' do
131
+ let(:_value) { 'compressed_data' }
132
+ let(:expected) {
133
+ {
134
+ compressed: 'compressed_data',
135
+ original: [],
136
+ }
137
+ }
138
+
139
+ it { subject.must_equal(expected) }
140
+ end
141
+ end
142
+ end
143
+
144
+ end # CompressorCache
145
+
146
+ end # Output
147
+
148
+ end # Vedeu
data/vedeu.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'guard-minitest', '2.4.4'
25
25
  spec.add_development_dependency 'guard-rubocop', '1.2.0'
26
26
  spec.add_development_dependency 'minitest', '5.8.3'
27
- spec.add_development_dependency 'minitest-reporters', '1.1.5'
27
+ spec.add_development_dependency 'minitest-reporters', '1.1.6'
28
28
  spec.add_development_dependency 'mocha', '1.1.0'
29
29
  spec.add_development_dependency 'pry', '0.10.3'
30
30
  spec.add_development_dependency 'rubocop', '0.35.1'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.67
4
+ version: 0.6.68
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-24 00:00:00.000000000 Z
11
+ date: 2015-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -72,14 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - '='
74
74
  - !ruby/object:Gem::Version
75
- version: 1.1.5
75
+ version: 1.1.6
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - '='
81
81
  - !ruby/object:Gem::Version
82
- version: 1.1.5
82
+ version: 1.1.6
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: mocha
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -482,6 +482,7 @@ files:
482
482
  - lib/vedeu/null/view.rb
483
483
  - lib/vedeu/output/all.rb
484
484
  - lib/vedeu/output/compressor.rb
485
+ - lib/vedeu/output/compressor_cache.rb
485
486
  - lib/vedeu/output/output.rb
486
487
  - lib/vedeu/output/presentation/all.rb
487
488
  - lib/vedeu/output/presentation/colour.rb
@@ -660,6 +661,7 @@ files:
660
661
  - test/lib/vedeu/models/views/view_test.rb
661
662
  - test/lib/vedeu/null/generic_test.rb
662
663
  - test/lib/vedeu/null/view_test.rb
664
+ - test/lib/vedeu/output/compressor_cache_test.rb
663
665
  - test/lib/vedeu/output/compressor_test.rb
664
666
  - test/lib/vedeu/output/output_test.rb
665
667
  - test/lib/vedeu/output/presentation/colour_test.rb
@@ -875,6 +877,7 @@ test_files:
875
877
  - test/lib/vedeu/models/views/view_test.rb
876
878
  - test/lib/vedeu/null/generic_test.rb
877
879
  - test/lib/vedeu/null/view_test.rb
880
+ - test/lib/vedeu/output/compressor_cache_test.rb
878
881
  - test/lib/vedeu/output/compressor_test.rb
879
882
  - test/lib/vedeu/output/output_test.rb
880
883
  - test/lib/vedeu/output/presentation/colour_test.rb