vedeu 0.4.16 → 0.4.17

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +7 -21
  3. data/lib/vedeu/bindings.rb +2 -6
  4. data/lib/vedeu/buffers/buffer.rb +29 -34
  5. data/lib/vedeu/cursor/cursor.rb +5 -2
  6. data/lib/vedeu/distributed/all.rb +5 -5
  7. data/lib/vedeu/distributed/server.rb +1 -1
  8. data/lib/vedeu/dsl/components/border.rb +1 -2
  9. data/lib/vedeu/dsl/components/geometry.rb +0 -47
  10. data/lib/vedeu/dsl/interface.rb +4 -11
  11. data/lib/vedeu/dsl/line.rb +1 -2
  12. data/lib/vedeu/dsl/shared/all.rb +1 -2
  13. data/lib/vedeu/dsl/shared/{colour.rb → presentation.rb} +27 -4
  14. data/lib/vedeu/dsl/shared/use.rb +50 -29
  15. data/lib/vedeu/dsl/stream.rb +1 -2
  16. data/lib/vedeu/geometry/geometry.rb +22 -11
  17. data/lib/vedeu/geometry/index_position.rb +0 -19
  18. data/lib/vedeu/geometry/position_validator.rb +8 -8
  19. data/lib/vedeu/models/interface.rb +34 -76
  20. data/lib/vedeu/models/null_interface.rb +5 -0
  21. data/lib/vedeu/models/stream.rb +1 -1
  22. data/lib/vedeu/output/border.rb +25 -41
  23. data/lib/vedeu/output/clear.rb +1 -7
  24. data/lib/vedeu/output/esc.rb +10 -10
  25. data/lib/vedeu/output/presentation.rb +2 -0
  26. data/lib/vedeu/output/renderers/escape_sequence_renderer.rb +3 -0
  27. data/lib/vedeu/repositories/model.rb +6 -0
  28. data/lib/vedeu/repositories/repositories/groups.rb +12 -0
  29. data/lib/vedeu/repositories/repository.rb +11 -8
  30. data/lib/vedeu/storage/all.rb +4 -4
  31. data/lib/vedeu/support/visibility.rb +8 -0
  32. data/test/lib/vedeu/buffers/buffer_test.rb +0 -2
  33. data/test/lib/vedeu/cursor/cursor_test.rb +14 -0
  34. data/test/lib/vedeu/dsl/components/border_test.rb +2 -2
  35. data/test/lib/vedeu/dsl/components/geometry_test.rb +63 -82
  36. data/test/lib/vedeu/dsl/components/keymap_test.rb +3 -3
  37. data/test/lib/vedeu/dsl/components/menu_test.rb +8 -8
  38. data/test/lib/vedeu/dsl/interface_test.rb +14 -22
  39. data/test/lib/vedeu/dsl/line_test.rb +4 -4
  40. data/test/lib/vedeu/dsl/shared/{colour_test.rb → presentation_test.rb} +19 -11
  41. data/test/lib/vedeu/dsl/shared/text_test.rb +15 -15
  42. data/test/lib/vedeu/dsl/shared/use_test.rb +24 -7
  43. data/test/lib/vedeu/geometry/geometry_test.rb +22 -19
  44. data/test/lib/vedeu/geometry/grid_test.rb +3 -3
  45. data/test/lib/vedeu/geometry/index_position_test.rb +0 -45
  46. data/test/lib/vedeu/geometry/position_test.rb +5 -5
  47. data/test/lib/vedeu/models/cell_test.rb +3 -3
  48. data/test/lib/vedeu/models/char_test.rb +5 -5
  49. data/test/lib/vedeu/models/interface_test.rb +7 -53
  50. data/test/lib/vedeu/models/null_test.rb +2 -2
  51. data/test/lib/vedeu/models/stream_test.rb +5 -5
  52. data/test/lib/vedeu/output/border_test.rb +1 -0
  53. data/test/lib/vedeu/output/colour_test.rb +16 -16
  54. data/test/lib/vedeu/output/esc_test.rb +15 -1
  55. data/test/lib/vedeu/output/html_char_test.rb +4 -4
  56. data/test/lib/vedeu/output/style_test.rb +15 -13
  57. data/test/lib/vedeu/output/text_test.rb +3 -3
  58. data/test/lib/vedeu/repositories/collection_test.rb +2 -2
  59. data/test/lib/vedeu/repositories/model_test.rb +19 -0
  60. data/test/lib/vedeu/repositories/repositories/groups_test.rb +22 -0
  61. data/test/lib/vedeu/repositories/repository_test.rb +50 -16
  62. data/test/lib/vedeu/support/common_test.rb +5 -5
  63. data/test/lib/vedeu/support/terminal_test.rb +3 -3
  64. data/test/lib/vedeu/support/visibility_test.rb +8 -0
  65. data/test/support/helpers/model_test_class.rb +18 -0
  66. data/test/test_helper.rb +1 -1
  67. data/vedeu.gemspec +2 -2
  68. metadata +7 -20
  69. data/lib/vedeu/dsl/shared/style.rb +0 -39
  70. data/test/lib/vedeu/dsl/shared/style_test.rb +0 -25
  71. data/test/support/helpers/all.rb +0 -5
  72. data/test/support/helpers/dsl_model_test_class.rb +0 -25
  73. data/test/support/helpers/helpers.rb +0 -17
  74. data/test/support/helpers/repositories.rb +0 -26
  75. data/test/support/helpers/repository_test_module.rb +0 -21
@@ -11,8 +11,7 @@ module Vedeu
11
11
  class Stream
12
12
 
13
13
  include Vedeu::DSL
14
- include Vedeu::DSL::Colour
15
- include Vedeu::DSL::Style
14
+ include Vedeu::DSL::Presentation
16
15
  include Vedeu::DSL::Text
17
16
 
18
17
  # Returns an instance of DSL::Stream.
@@ -94,23 +94,19 @@ module Vedeu
94
94
  # @option attributes centred [Boolean]
95
95
  # @option attributes height [Fixnum]
96
96
  # @option attributes name [String]
97
+ # @option attributes repository [Vedeu::Geometries]
97
98
  # @option attributes width [Fixnum]
98
99
  # @option attributes x [Fixnum]
99
100
  # @option attributes xn [Fixnum]
100
101
  # @option attributes y [Fixnum]
101
102
  # @option attributes yn [Fixnum]
102
- # @return [Geometry]
103
+ # @return [Vedeu::Geometry]
103
104
  def initialize(attributes = {})
104
- @attributes = attributes
105
- @centred = @attributes[:centred]
106
- @height = @attributes[:height]
107
- @name = @attributes[:name]
108
- @width = @attributes[:width]
109
- @x = @attributes[:x]
110
- @xn = @attributes[:xn]
111
- @y = @attributes[:y]
112
- @yn = @attributes[:yn]
113
- @repository = Vedeu.geometries
105
+ @attributes = defaults.merge!(attributes)
106
+
107
+ @attributes.each do |key, value|
108
+ instance_variable_set("@#{key}", value)
109
+ end
114
110
  end
115
111
 
116
112
  private
@@ -166,6 +162,21 @@ module Vedeu
166
162
  @xn.is_a?(Proc) ? @xn.call : @xn
167
163
  end
168
164
 
165
+ # @return [Hash]
166
+ def defaults
167
+ {
168
+ centred: nil,
169
+ height: nil,
170
+ name: nil,
171
+ repository: Vedeu.geometries,
172
+ width: nil,
173
+ x: nil,
174
+ xn: nil,
175
+ y: nil,
176
+ yn: nil,
177
+ }
178
+ end
179
+
169
180
  end # Geometry
170
181
 
171
182
  end # Vedeu
@@ -13,25 +13,6 @@ module Vedeu
13
13
  new(iy, ix, oy, ox).[]
14
14
  end
15
15
 
16
- # @param name [String] The name of the interface.
17
- # @param iy [Fixnum]
18
- # @param ix [Fixnum]
19
- # @return [Vedeu::Position]
20
- def self.from_interface(name, iy, ix)
21
- if Vedeu.interfaces.registered?(name)
22
- interface = Vedeu.interfaces.find(name)
23
- oy = interface.border.by
24
- ox = interface.border.bx
25
-
26
- else
27
- oy = 1
28
- ox = 1
29
-
30
- end
31
-
32
- new(iy, ix, oy, ox).[]
33
- end
34
-
35
16
  # Returns a new instance of Vedeu::IndexPosition.
36
17
  #
37
18
  # @param iy [Fixnum]
@@ -17,10 +17,10 @@ module Vedeu
17
17
 
18
18
  def_delegators :border,
19
19
  :enabled?,
20
- :left?,
21
- :right?,
22
- :top?,
23
- :bottom?
20
+ :bx,
21
+ :bxn,
22
+ :by,
23
+ :byn
24
24
 
25
25
  def_delegators :geometry,
26
26
  :left,
@@ -104,10 +104,10 @@ module Vedeu
104
104
  #
105
105
  # @return [PositionValidator]
106
106
  def border_validation
107
- @x = left + 1 if left? && x < (left + 1)
108
- @x = right - 2 if right? && x > (right - 1)
109
- @y = top + 1 if top? && y < (top + 1)
110
- @y = bottom - 2 if bottom? && y > (bottom - 1)
107
+ @x = bx if x < bx
108
+ @x = bxn if x > bxn
109
+ @y = by if y < by
110
+ @y = byn if y > byn
111
111
 
112
112
  self
113
113
  end
@@ -21,6 +21,10 @@ module Vedeu
21
21
  collection Vedeu::Lines
22
22
  member Vedeu::Line
23
23
 
24
+ # @!attribute [rw] client
25
+ # @return [Fixnum|Float]
26
+ attr_accessor :client
27
+
24
28
  # @!attribute [rw] delay
25
29
  # @return [Fixnum|Float]
26
30
  attr_accessor :delay
@@ -50,81 +54,39 @@ module Vedeu
50
54
  # @return [Array<Vedeu::Line>]
51
55
  attr_writer :lines
52
56
 
53
- def_delegators :geometry,
54
- :north,
55
- :east,
56
- :south,
57
- :west,
58
- :top,
59
- :right,
60
- :bottom,
61
- :left,
62
- :y,
63
- :yn,
64
- :x,
65
- :xn,
66
- :width,
67
- :height,
68
- :top_left,
69
- :top_right,
70
- :bottom_left,
71
- :bottom_right
72
-
73
57
  # Return a new instance of Vedeu::Interface.
74
58
  #
75
59
  # @param attributes [Hash]
60
+ # @option attributes client [Vedeu::Client]
76
61
  # @option attributes colour [Vedeu::Colour]
77
62
  # @option attributes delay [Float]
78
63
  # @option attributes group [String]
79
64
  # @option attributes lines [Vedeu::Lines]
80
65
  # @option attributes name [String]
81
66
  # @option attributes parent [Vedeu::Composition]
67
+ # @option attributes repository [Vedeu::InterfacesRepository]
82
68
  # @option attributes style [Vedeu::Style]
83
69
  # @option attributes visible [Boolean]
84
70
  # @return [Vedeu::Interface]
85
71
  def initialize(attributes = {})
86
72
  @attributes = defaults.merge!(attributes)
87
73
 
74
+ @client = @attributes[:client]
88
75
  @delay = @attributes[:delay]
89
76
  @group = @attributes[:group]
90
77
  @lines = @attributes[:lines]
91
78
  @name = @attributes[:name]
92
79
  @parent = @attributes[:parent]
93
- @repository = Vedeu.interfaces
80
+ @repository = @attributes[:repository]
94
81
  @visible = @attributes[:visible]
95
82
  end
96
83
 
97
- # @param child []
84
+ # @param child [Vedeu::Line]
98
85
  # @return [void]
99
86
  def add(child)
100
87
  @lines = lines.add(child)
101
88
  end
102
89
 
103
- # Returns the border object belonging to the interface.
104
- #
105
- # @return [Vedeu::Border|NilClass]
106
- def border
107
- @border ||= Vedeu.borders.by_name(name)
108
- end
109
-
110
- # @return [Array<Array<Vedeu::Char>>]
111
- def clear
112
- Vedeu::Clear.new(self)
113
- end
114
-
115
- # Fetch the cursor belonging to this interface (by name), if one does not
116
- # exist, it will be created, stored and returned.
117
- #
118
- # @return [Vedeu::Cursor]
119
- def cursor
120
- Vedeu.cursors.by_name(name)
121
- end
122
-
123
- # @return [Vedeu::Geometry]
124
- def geometry
125
- @geometry ||= Vedeu.geometries.by_name(name)
126
- end
127
-
128
90
  # @return [Vedeu::Lines]
129
91
  def lines
130
92
  collection.coerce(@lines, self)
@@ -143,19 +105,15 @@ module Vedeu
143
105
 
144
106
  # @return [Array<Array<Vedeu::Char>>]
145
107
  def render
146
- if visible?
147
- [
148
- hide_cursor,
149
- clear.render,
150
- border.render,
151
- viewport.render,
152
- show_cursor,
153
- ]
154
-
155
- else
156
- []
157
-
158
- end
108
+ return [] unless visible?
109
+
110
+ [
111
+ hide_cursor,
112
+ Vedeu::Clear.new(self).render,
113
+ Vedeu.borders.by_name(name).render,
114
+ Vedeu::Viewport.new(self).render,
115
+ show_cursor,
116
+ ]
159
117
  end
160
118
 
161
119
  # @return [Interface]
@@ -168,40 +126,40 @@ module Vedeu
168
126
  store_group
169
127
  end
170
128
 
171
- # @return [Array<Array<Vedeu::Char>>]
172
- def viewport
173
- Vedeu::Viewport.new(self)
174
- end
175
-
176
129
  private
177
130
 
131
+ def cursor
132
+ @cursor ||= Vedeu.cursors.by_name(name)
133
+ end
134
+
178
135
  # The default values for a new instance of this class.
179
136
  #
180
137
  # @return [Hash]
181
138
  def defaults
182
139
  {
183
- client: nil,
184
- colour: nil,
185
- delay: 0.0,
186
- group: '',
187
- lines: [],
188
- name: '',
189
- parent: nil,
190
- style: nil,
191
- visible: true,
140
+ client: nil,
141
+ colour: nil,
142
+ delay: 0.0,
143
+ group: '',
144
+ lines: [],
145
+ name: '',
146
+ parent: nil,
147
+ repository: Vedeu.interfaces,
148
+ style: nil,
149
+ visible: true,
192
150
  }
193
151
  end
194
152
 
195
153
  # @return [String]
196
154
  def hide_cursor
197
- return Vedeu::Esc.string(:hide_cursor) if cursor.visible?
155
+ return cursor.hide_cursor if cursor.visible?
198
156
 
199
157
  ''
200
158
  end
201
159
 
202
160
  # @return [String]
203
161
  def show_cursor
204
- return Vedeu::Esc.string(:show_cursor) if cursor.visible?
162
+ return cursor.show_cursor if cursor.visible?
205
163
 
206
164
  ''
207
165
  end
@@ -1,11 +1,16 @@
1
1
  module Vedeu
2
2
 
3
+ # Provides a non-existent Vedeu::Interface that acts like the real thing, but
4
+ # does nothing.
5
+ #
3
6
  class NullInterface
4
7
 
5
8
  # @!attribute [r] attributes
6
9
  # @return [Hash]
7
10
  attr_reader :attributes
8
11
 
12
+ # @param attributes [Hash]
13
+ # @return [Vedeu::NullInterface]
9
14
  def initialize(attributes = {})
10
15
  @attributes = attributes
11
16
  end
@@ -57,7 +57,7 @@ module Vedeu
57
57
  #
58
58
  # @return [Array]
59
59
  def chars
60
- return [] if value.empty?
60
+ return [] if empty?
61
61
 
62
62
  value.chars.map do |char|
63
63
  member.new(value: char,
@@ -116,20 +116,10 @@ module Vedeu
116
116
  # @return [Border]
117
117
  def initialize(attributes = {})
118
118
  @attributes = defaults.merge!(attributes)
119
- @enabled = @attributes[:enabled]
120
- @bottom_left = @attributes[:bottom_left]
121
- @bottom_right = @attributes[:bottom_right]
122
- @show_bottom = @attributes[:show_bottom]
123
- @show_left = @attributes[:show_left]
124
- @show_right = @attributes[:show_right]
125
- @show_top = @attributes[:show_top]
126
- @title = @attributes[:title]
127
- @top_left = @attributes[:top_left]
128
- @top_right = @attributes[:top_right]
129
- @horizontal = @attributes[:horizontal]
130
- @vertical = @attributes[:vertical]
131
- @name = @attributes[:name]
132
- @repository = Vedeu.borders
119
+
120
+ @attributes.each do |key, value|
121
+ instance_variable_set("@#{key}", value)
122
+ end
133
123
  end
134
124
 
135
125
  # @return [Fixnum]
@@ -191,7 +181,13 @@ module Vedeu
191
181
  #
192
182
  # @return [String]
193
183
  def bottom
194
- top_or_bottom('bottom')
184
+ return [] unless bottom?
185
+
186
+ out = []
187
+ out << border(bottom_left, :bottom_left) if left?
188
+ out << horizontal_border(:bottom_horizontal)
189
+ out << border(bottom_right, :bottom_right) if right?
190
+ out
195
191
  end
196
192
 
197
193
  # Renders the left border for the interface.
@@ -218,7 +214,19 @@ module Vedeu
218
214
  #
219
215
  # @return [String]
220
216
  def top
221
- top_or_bottom('top')
217
+ return [] unless top?
218
+
219
+ out = []
220
+ out << border(top_left, :top_left) if left?
221
+ if title?
222
+ out << titlebar
223
+
224
+ else
225
+ out << horizontal_border(:top_horizontal)
226
+
227
+ end
228
+ out << border(top_right, :top_right) if right?
229
+ out
222
230
  end
223
231
 
224
232
  # The parent of a border is always an interface.
@@ -230,31 +238,6 @@ module Vedeu
230
238
 
231
239
  private
232
240
 
233
- # @param prefix [String]
234
- # @return [String]
235
- def top_or_bottom(prefix)
236
- predicate = (prefix + '?').to_sym
237
- prefix_left = (prefix + '_left').to_sym
238
- prefix_right = (prefix + '_right').to_sym
239
- prefix_horizontal = (prefix + '_horizontal').to_sym
240
-
241
- return [] unless send(predicate)
242
-
243
- out = []
244
- out << border(send(prefix_left), prefix_left) if left?
245
-
246
- if prefix == 'top' && title?
247
- out << titlebar
248
-
249
- else
250
- out << horizontal_border(prefix_horizontal)
251
-
252
- end
253
-
254
- out << border(send(prefix_right), prefix_right) if right?
255
- out
256
- end
257
-
258
241
  # @param position [Symbol] Either :top_horizontal, or :bottom_horizontal.
259
242
  # @return [Array<Vedeu::Char>]
260
243
  def horizontal_border(position)
@@ -362,6 +345,7 @@ module Vedeu
362
345
  enabled: false,
363
346
  horizontal: "\x71", # ─ # \u2500
364
347
  name: '',
348
+ repository: Vedeu.borders,
365
349
  show_bottom: true,
366
350
  show_left: true,
367
351
  show_right: true,
@@ -81,13 +81,7 @@ module Vedeu
81
81
  #
82
82
  # @return [Array]
83
83
  def write
84
- if Vedeu::Configuration.drb?
85
- Vedeu.trigger(:_drb_store_output_, rendered)
86
-
87
- Vedeu::HTMLRenderer.to_file(Vedeu::VirtualBuffer.retrieve)
88
- end
89
-
90
- Vedeu.renderers.render(rendered)
84
+ Vedeu::Output.render(rendered)
91
85
  end
92
86
 
93
87
  private
@@ -101,6 +101,16 @@ module Vedeu
101
101
  stream.gsub(/\e/, '\\e')
102
102
  end
103
103
 
104
+ # @return [String]
105
+ def hide_cursor
106
+ "\e[?25l"
107
+ end
108
+
109
+ # @return [String]
110
+ def show_cursor
111
+ "\e[?25h"
112
+ end
113
+
104
114
  # Return the escape sequence string from the list of recognised sequence
105
115
  # 'commands', or an empty string if the 'command' cannot be found.
106
116
  #
@@ -196,11 +206,6 @@ module Vedeu
196
206
  "\e[39m"
197
207
  end
198
208
 
199
- # @return [String]
200
- def hide_cursor
201
- "\e[?25l"
202
- end
203
-
204
209
  # @return [String]
205
210
  def negative
206
211
  "\e[7m"
@@ -231,11 +236,6 @@ module Vedeu
231
236
  [show_cursor, colour_reset, reset].join
232
237
  end
233
238
 
234
- # @return [String]
235
- def show_cursor
236
- "\e[?25h"
237
- end
238
-
239
239
  # @return [String]
240
240
  def underline
241
241
  "\e[4m"