vedeu 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +43 -17
  3. data/lib/vedeu/api/api.rb +21 -0
  4. data/lib/vedeu/api/base.rb +7 -15
  5. data/lib/vedeu/api/events.rb +5 -10
  6. data/lib/vedeu/api/grid.rb +0 -2
  7. data/lib/vedeu/api/interface.rb +15 -37
  8. data/lib/vedeu/api/line.rb +0 -3
  9. data/lib/vedeu/{instrumentation.rb → api/log.rb} +2 -5
  10. data/lib/vedeu/api/store.rb +3 -9
  11. data/lib/vedeu/api/stream.rb +0 -2
  12. data/lib/vedeu/api/view.rb +4 -15
  13. data/lib/vedeu/application.rb +1 -5
  14. data/lib/vedeu/configuration.rb +0 -2
  15. data/lib/vedeu/launcher.rb +0 -3
  16. data/lib/vedeu/models/attributes/background.rb +0 -4
  17. data/lib/vedeu/models/attributes/foreground.rb +0 -4
  18. data/lib/vedeu/models/attributes/interface_collection.rb +3 -8
  19. data/lib/vedeu/models/attributes/line_collection.rb +0 -5
  20. data/lib/vedeu/models/attributes/stream_collection.rb +0 -5
  21. data/lib/vedeu/models/colour.rb +0 -5
  22. data/lib/vedeu/models/composition.rb +0 -15
  23. data/lib/vedeu/models/geometry.rb +0 -5
  24. data/lib/vedeu/models/interface.rb +0 -14
  25. data/lib/vedeu/models/line.rb +0 -6
  26. data/lib/vedeu/models/stream.rb +0 -5
  27. data/lib/vedeu/models/style.rb +0 -4
  28. data/lib/vedeu/output/buffers.rb +13 -4
  29. data/lib/vedeu/output/render.rb +1 -4
  30. data/lib/vedeu/output/view.rb +7 -3
  31. data/lib/vedeu/support/input.rb +0 -3
  32. data/lib/vedeu/support/menu.rb +0 -5
  33. data/lib/vedeu/support/terminal.rb +0 -4
  34. data/test/lib/vedeu/api/events_test.rb +0 -1
  35. data/test/lib/vedeu/api/grid_test.rb +0 -2
  36. data/test/lib/vedeu/api/interface_test.rb +0 -1
  37. data/test/lib/vedeu/api/store_test.rb +0 -1
  38. data/test/lib/vedeu/api/view_test.rb +1 -4
  39. data/test/lib/vedeu/configuration_test.rb +0 -1
  40. data/test/lib/vedeu/models/attributes/collection_test.rb +0 -1
  41. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +0 -5
  42. data/test/lib/vedeu/models/attributes/line_collection_test.rb +0 -2
  43. data/test/lib/vedeu/models/attributes/stream_collection_test.rb +0 -2
  44. data/test/lib/vedeu/models/colour_test.rb +0 -1
  45. data/test/lib/vedeu/models/composition_test.rb +14 -34
  46. data/test/lib/vedeu/models/geometry_test.rb +0 -1
  47. data/test/lib/vedeu/models/interface_test.rb +0 -1
  48. data/test/lib/vedeu/models/line_test.rb +0 -1
  49. data/test/lib/vedeu/models/stream_test.rb +0 -1
  50. data/test/lib/vedeu/models/style_test.rb +0 -1
  51. data/test/lib/vedeu/output/buffers_test.rb +0 -2
  52. data/test/lib/vedeu/output/clear_test.rb +0 -3
  53. data/test/lib/vedeu/output/render_test.rb +0 -3
  54. data/test/lib/vedeu/support/esc_test.rb +0 -1
  55. data/test/lib/vedeu/support/input_test.rb +0 -1
  56. data/test/lib/vedeu/support/menu_test.rb +0 -1
  57. data/test/lib/vedeu/support/terminal_test.rb +0 -1
  58. data/test/support/model_test_data.json +437 -0
  59. data/test/test_helper.rb +4 -2
  60. data/vedeu.gemspec +1 -1
  61. metadata +6 -44
  62. data/lib/vedeu/support/wordwrap.rb +0 -88
  63. data/test/lib/vedeu/api/base_test.rb +0 -12
  64. data/test/lib/vedeu/api/line_test.rb +0 -10
  65. data/test/lib/vedeu/api/stream_test.rb +0 -12
  66. data/test/lib/vedeu/application_test.rb +0 -10
  67. data/test/lib/vedeu/launcher_test.rb +0 -7
  68. data/test/lib/vedeu/models/attributes/background_test.rb +0 -8
  69. data/test/lib/vedeu/models/attributes/foreground_test.rb +0 -8
  70. data/test/lib/vedeu/output/view_test.rb +0 -9
  71. data/test/lib/vedeu/support/wordwrap_test.rb +0 -56
  72. data/test/lib/vedeu_test.rb +0 -10
  73. data/test/support/json/int1_lin1_str1.json +0 -10
  74. data/test/support/json/int1_lin1_str3.json +0 -18
  75. data/test/support/json/int1_lin2_str1.json +0 -17
  76. data/test/support/json/int1_lin2_str3.json +0 -33
  77. data/test/support/json/int1_lin2_str3_styles.json +0 -43
  78. data/test/support/json/int2_lin1_str1.json +0 -20
  79. data/test/support/json/int2_lin1_str3.json +0 -36
  80. data/test/support/json/int2_lin2_str1.json +0 -34
  81. data/test/support/json/int2_lin2_str3.json +0 -66
  82. data/test/support/json/int2_lin2_str3_styles.json +0 -158
@@ -1,8 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/collection'
4
- require 'vedeu/models/line'
5
-
6
1
  module Vedeu
7
2
  class LineCollection < Virtus::Attribute
8
3
  include Collection
@@ -1,8 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/collection'
4
- require 'vedeu/models/stream'
5
-
6
1
  module Vedeu
7
2
  class StreamCollection < Virtus::Attribute
8
3
  include Collection
@@ -1,8 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/background'
4
- require 'vedeu/models/attributes/foreground'
5
-
6
1
  module Vedeu
7
2
  class Colour
8
3
  include Virtus.model
@@ -1,24 +1,9 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/interface_collection'
4
- require 'vedeu/output/buffers'
5
-
6
1
  module Vedeu
7
2
  class Composition
8
3
  include Virtus.model
9
4
 
10
5
  attribute :interfaces, InterfaceCollection
11
6
 
12
- def self.enqueue(attributes)
13
- new(attributes).enqueue
14
- end
15
-
16
- def enqueue
17
- interfaces.map do |interface|
18
- Buffers.enqueue(interface.name, interface.to_s)
19
- end
20
- end
21
-
22
7
  def to_s
23
8
  interfaces.map(&:to_s).join
24
9
  end
@@ -1,8 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/support/esc'
4
- require 'vedeu/support/terminal'
5
-
6
1
  module Vedeu
7
2
  class Geometry
8
3
  include Virtus.model
@@ -1,13 +1,3 @@
1
- require 'forwardable'
2
- require 'virtus'
3
-
4
- require 'vedeu/models/attributes/line_collection'
5
- require 'vedeu/models/colour'
6
- require 'vedeu/models/style'
7
- require 'vedeu/output/clear'
8
- require 'vedeu/output/render'
9
- require 'vedeu/models/geometry'
10
-
11
1
  module Vedeu
12
2
  class Interface
13
3
  extend Forwardable
@@ -26,10 +16,6 @@ module Vedeu
26
16
  :top, :right, :bottom, :left,
27
17
  :width, :height, :origin
28
18
 
29
- def clear
30
- @_clear ||= Clear.call(self)
31
- end
32
-
33
19
  def to_s
34
20
  Render.call(self)
35
21
  end
@@ -1,9 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/stream_collection'
4
- require 'vedeu/models/colour'
5
- require 'vedeu/models/style'
6
-
7
1
  module Vedeu
8
2
  class Line
9
3
  include Virtus.model
@@ -1,8 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/colour'
4
- require 'vedeu/models/style'
5
-
6
1
  module Vedeu
7
2
  class Stream
8
3
  include Virtus.model
@@ -1,7 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/support/esc'
4
-
5
1
  module Vedeu
6
2
  class Style < Virtus::Attribute
7
3
  def coerce(value_or_values)
@@ -1,13 +1,22 @@
1
- require 'vedeu/support/terminal'
2
-
3
1
  module Vedeu
4
2
  RefreshFailed = Class.new(StandardError)
5
3
 
6
4
  module Buffers
7
5
  extend self
8
6
 
9
- def create(name, sequence)
10
- buffers[name][:clear] = sequence
7
+ def create(interface)
8
+ buffers[interface.name][:clear] = Clear.call(interface)
9
+
10
+ Vedeu.events.on("_refresh_#{interface.name}_".to_sym, interface.delay) do
11
+ refresh(interface.name)
12
+ end
13
+
14
+ # TODO: cannot refresh group since no logic to fetch group from buffer
15
+ # unless interface.group.nil? || interface.group.empty?
16
+ # Vedeu.events.on("_refresh_#{interface.group}_".to_sym, interface.delay) do
17
+ # refresh_group(interface.group)
18
+ # end
19
+ # end
11
20
  end
12
21
 
13
22
  def enqueue(name, sequence)
@@ -1,6 +1,3 @@
1
- require 'vedeu/models/line'
2
- require 'vedeu/models/stream'
3
-
4
1
  module Vedeu
5
2
  class Render
6
3
  def self.call(interface)
@@ -12,7 +9,7 @@ module Vedeu
12
9
  end
13
10
 
14
11
  def render
15
- out = [interface.clear]
12
+ out = [ Clear.call(interface) ]
16
13
  processed_lines.each_with_index do |line, index|
17
14
  if index + 1 <= height
18
15
  out << interface.origin(index)
@@ -1,5 +1,3 @@
1
- require 'vedeu/models/composition'
2
-
3
1
  module Vedeu
4
2
  NotImplemented = Class.new(StandardError)
5
3
 
@@ -15,7 +13,9 @@ module Vedeu
15
13
  end
16
14
 
17
15
  def render
18
- Composition.enqueue(interfaces)
16
+ composition.interfaces.map do |interface|
17
+ Buffers.enqueue(interface.name, interface.to_s)
18
+ end
19
19
  end
20
20
 
21
21
  def output
@@ -26,6 +26,10 @@ module Vedeu
26
26
 
27
27
  attr_reader :object
28
28
 
29
+ def composition
30
+ @_composition ||= Composition.new(interfaces)
31
+ end
32
+
29
33
  def interfaces
30
34
  {
31
35
  interfaces: [ output ]
@@ -1,6 +1,3 @@
1
- require 'vedeu/support/terminal'
2
- require 'vedeu'
3
-
4
1
  module Vedeu
5
2
  class Input
6
3
  def self.capture
@@ -1,8 +1,3 @@
1
- require 'vedeu'
2
- require 'vedeu/api/events'
3
-
4
- # Todo: mutation (events, menu)
5
-
6
1
  module Vedeu
7
2
  class Menu
8
3
  def initialize(collection)
@@ -1,7 +1,3 @@
1
- require 'io/console'
2
-
3
- require 'vedeu/support/esc'
4
-
5
1
  module Vedeu
6
2
  module Terminal
7
3
  extend self
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/api/events'
3
2
 
4
3
  module Vedeu
5
4
  module API
@@ -1,7 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
- require 'vedeu/api/grid'
4
-
5
3
  describe Fixnum do
6
4
  describe '#columns' do
7
5
  it 'returns the width if the value is in range' do
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/api/interface'
3
2
 
4
3
  module Vedeu
5
4
  module API
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/api/store'
3
2
 
4
3
  module Vedeu
5
4
  module API
@@ -1,8 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
- require 'vedeu/api/view'
4
- require 'vedeu'
5
-
6
3
  module Vedeu
7
4
  module API
8
5
  describe View do
@@ -64,7 +61,7 @@ module Vedeu
64
61
  it 'handles coloured lines' do
65
62
  Vedeu.view 'testing_view' do
66
63
  line do
67
- colour '#ff0000', '#ffff00'
64
+ colour background: '#ff0000', foreground: '#ffff00'
68
65
  text '2. Line with colours.'
69
66
  end
70
67
  end.must_equal(
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/configuration'
3
2
 
4
3
  module Vedeu
5
4
  describe Configuration do
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/models/attributes/collection'
3
2
 
4
3
  module Vedeu
5
4
  class TestClass
@@ -1,10 +1,5 @@
1
1
  require 'test_helper'
2
2
 
3
- require 'vedeu'
4
- require 'vedeu/models/composition'
5
- require 'vedeu/models/attributes/interface_collection'
6
- require 'vedeu/api/store'
7
-
8
3
  module Vedeu
9
4
  describe InterfaceCollection do
10
5
  describe '#coerce' do
@@ -1,6 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/models/attributes/line_collection'
3
- require 'vedeu/models/interface'
4
2
 
5
3
  module Vedeu
6
4
  describe LineCollection do
@@ -1,6 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/models/attributes/stream_collection'
3
- require 'vedeu/models/line'
4
2
 
5
3
  module Vedeu
6
4
  describe StreamCollection do
@@ -1,5 +1,4 @@
1
1
  require 'test_helper'
2
- require 'vedeu/models/colour'
3
2
 
4
3
  module Vedeu
5
4
  describe Colour do
@@ -2,12 +2,11 @@ require 'test_helper'
2
2
 
3
3
  require 'json'
4
4
 
5
- require 'vedeu/models/composition'
6
- require 'vedeu/api/store'
7
- require 'vedeu'
8
-
9
5
  module Vedeu
10
6
  describe Composition do
7
+ let(:json) { File.read('test/support/model_test_data.json') }
8
+ let(:attributes) { JSON.load(json, nil, symbolize_names: true) }
9
+
11
10
  before { API::Store.reset }
12
11
 
13
12
  describe '#interfaces' do
@@ -37,10 +36,8 @@ module Vedeu
37
36
  width 15
38
37
  height 3
39
38
  end
40
- json = File.read('test/support/json/int1_lin1_str1.json')
41
- attributes = JSON.load(json, nil, symbolize_names: true)
42
39
 
43
- Composition.new(attributes).to_s.must_equal(
40
+ Composition.new(attributes[:test_0001]).to_s.must_equal(
44
41
  "\e[3;3H \e[3;3H" \
45
42
  "\e[4;3H \e[4;3H" \
46
43
  "\e[5;3H \e[5;3H" \
@@ -55,10 +52,8 @@ module Vedeu
55
52
  width 30
56
53
  height 3
57
54
  end
58
- json = File.read('test/support/json/int1_lin1_str3.json')
59
- attributes = JSON.load(json, nil, symbolize_names: true)
60
55
 
61
- Composition.new(attributes).to_s.must_equal(
56
+ Composition.new(attributes[:test_0002]).to_s.must_equal(
62
57
  "\e[3;3H \e[3;3H" \
63
58
  "\e[4;3H \e[4;3H" \
64
59
  "\e[5;3H \e[5;3H" \
@@ -73,10 +68,8 @@ module Vedeu
73
68
  width 15
74
69
  height 3
75
70
  end
76
- json = File.read('test/support/json/int1_lin2_str1.json')
77
- attributes = JSON.load(json, nil, symbolize_names: true)
78
71
 
79
- Composition.new(attributes).to_s.must_equal(
72
+ Composition.new(attributes[:test_0003]).to_s.must_equal(
80
73
  "\e[3;3H \e[3;3H" \
81
74
  "\e[4;3H \e[4;3H" \
82
75
  "\e[5;3H \e[5;3H" \
@@ -92,10 +85,8 @@ module Vedeu
92
85
  width 30
93
86
  height 3
94
87
  end
95
- json = File.read('test/support/json/int1_lin2_str3.json')
96
- attributes = JSON.load(json, nil, symbolize_names: true)
97
88
 
98
- Composition.new(attributes).to_s.must_equal(
89
+ Composition.new(attributes[:test_0004]).to_s.must_equal(
99
90
  "\e[3;3H \e[3;3H" \
100
91
  "\e[4;3H \e[4;3H" \
101
92
  "\e[5;3H \e[5;3H" \
@@ -111,9 +102,8 @@ module Vedeu
111
102
  width 30
112
103
  height 3
113
104
  end
114
- json = File.read('test/support/json/int1_lin2_str3_styles.json')
115
- attributes = JSON.load(json, nil, symbolize_names: true)
116
- Composition.new(attributes).to_s.must_equal(
105
+
106
+ Composition.new(attributes[:test_0005]).to_s.must_equal(
117
107
  "\e[3;3H \e[3;3H" \
118
108
  "\e[4;3H \e[4;3H" \
119
109
  "\e[5;3H \e[5;3H" \
@@ -134,10 +124,8 @@ module Vedeu
134
124
  width 15
135
125
  height 3
136
126
  end
137
- json = File.read('test/support/json/int2_lin1_str1.json')
138
- attributes = JSON.load(json, nil, symbolize_names: true)
139
127
 
140
- Composition.new(attributes).to_s.must_equal(
128
+ Composition.new(attributes[:test_0006]).to_s.must_equal(
141
129
  "\e[3;3H \e[3;3H" \
142
130
  "\e[4;3H \e[4;3H" \
143
131
  "\e[5;3H \e[5;3H" \
@@ -162,10 +150,8 @@ module Vedeu
162
150
  width 30
163
151
  height 3
164
152
  end
165
- json = File.read('test/support/json/int2_lin1_str3.json')
166
- attributes = JSON.load(json, nil, symbolize_names: true)
167
153
 
168
- Composition.new(attributes).to_s.must_equal(
154
+ Composition.new(attributes[:test_0007]).to_s.must_equal(
169
155
  "\e[3;3H \e[3;3H" \
170
156
  "\e[4;3H \e[4;3H" \
171
157
  "\e[5;3H \e[5;3H" \
@@ -190,10 +176,8 @@ module Vedeu
190
176
  width 15
191
177
  height 3
192
178
  end
193
- json = File.read('test/support/json/int2_lin2_str1.json')
194
- attributes = JSON.load(json, nil, symbolize_names: true)
195
179
 
196
- Composition.new(attributes).to_s.must_equal(
180
+ Composition.new(attributes[:test_0008]).to_s.must_equal(
197
181
  "\e[3;3H \e[3;3H" \
198
182
  "\e[4;3H \e[4;3H" \
199
183
  "\e[5;3H \e[5;3H" \
@@ -220,10 +204,8 @@ module Vedeu
220
204
  width 30
221
205
  height 3
222
206
  end
223
- json = File.read('test/support/json/int2_lin2_str3.json')
224
- attributes = JSON.load(json, nil, symbolize_names: true)
225
207
 
226
- Composition.new(attributes).to_s.must_equal(
208
+ Composition.new(attributes[:test_0009]).to_s.must_equal(
227
209
  "\e[3;3H \e[3;3H" \
228
210
  "\e[4;3H \e[4;3H" \
229
211
  "\e[5;3H \e[5;3H" \
@@ -250,10 +232,8 @@ module Vedeu
250
232
  width 30
251
233
  height 3
252
234
  end
253
- json = File.read('test/support/json/int2_lin2_str3_styles.json')
254
- attributes = JSON.load(json, nil, symbolize_names: true)
255
235
 
256
- Composition.new(attributes).to_s.must_equal(
236
+ Composition.new(attributes[:test_0010]).to_s.must_equal(
257
237
  "\e[3;3H \e[3;3H" \
258
238
  "\e[4;3H \e[4;3H" \
259
239
  "\e[5;3H \e[5;3H" \