vedeu 0.4.9 → 0.4.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +8 -0
  3. data/lib/vedeu/application.rb +2 -0
  4. data/lib/vedeu/bindings.rb +3 -0
  5. data/lib/vedeu/configuration/configuration.rb +1 -1
  6. data/lib/vedeu/cursor/cursor.rb +1 -1
  7. data/lib/vedeu/cursor/move.rb +1 -1
  8. data/lib/vedeu/cursor/refresh_cursor.rb +2 -0
  9. data/lib/vedeu/cursor/toggle.rb +1 -1
  10. data/lib/vedeu/debug.rb +36 -1
  11. data/lib/vedeu/distributed/client.rb +2 -0
  12. data/lib/vedeu/distributed/subprocess.rb +2 -0
  13. data/lib/vedeu/distributed/test_application.rb +2 -0
  14. data/lib/vedeu/distributed/uri.rb +2 -0
  15. data/lib/vedeu/events/event.rb +1 -1
  16. data/lib/vedeu/events/trigger.rb +2 -0
  17. data/lib/vedeu/geometry/all.rb +0 -1
  18. data/lib/vedeu/geometry/area.rb +22 -0
  19. data/lib/vedeu/geometry/centre.rb +2 -0
  20. data/lib/vedeu/geometry/content.rb +2 -0
  21. data/lib/vedeu/geometry/coordinate.rb +2 -0
  22. data/lib/vedeu/geometry/dimension.rb +2 -0
  23. data/lib/vedeu/geometry/geometry.rb +8 -3
  24. data/lib/vedeu/geometry/grid.rb +2 -0
  25. data/lib/vedeu/geometry/index_position.rb +21 -0
  26. data/lib/vedeu/geometry/limit.rb +2 -0
  27. data/lib/vedeu/geometry/position.rb +1 -1
  28. data/lib/vedeu/geometry/position_index.rb +2 -0
  29. data/lib/vedeu/geometry/position_validator.rb +2 -0
  30. data/lib/vedeu/input/input.rb +1 -1
  31. data/lib/vedeu/input/key.rb +1 -1
  32. data/lib/vedeu/input/keymap.rb +2 -0
  33. data/lib/vedeu/input/mapper.rb +8 -0
  34. data/lib/vedeu/launcher.rb +2 -0
  35. data/lib/vedeu/main_loop.rb +1 -3
  36. data/lib/vedeu/models/cell.rb +2 -0
  37. data/lib/vedeu/models/composition.rb +1 -1
  38. data/lib/vedeu/models/group.rb +1 -1
  39. data/lib/vedeu/models/interface.rb +35 -3
  40. data/lib/vedeu/models/line.rb +6 -1
  41. data/lib/vedeu/models/menu.rb +1 -1
  42. data/lib/vedeu/models/stream.rb +6 -17
  43. data/lib/vedeu/output/all.rb +3 -2
  44. data/lib/vedeu/output/background.rb +26 -0
  45. data/lib/vedeu/output/border.rb +105 -25
  46. data/lib/vedeu/output/clear.rb +17 -10
  47. data/lib/vedeu/output/colour.rb +1 -1
  48. data/lib/vedeu/output/compositor.rb +4 -1
  49. data/lib/vedeu/output/foreground.rb +26 -0
  50. data/lib/vedeu/output/html_char.rb +2 -0
  51. data/lib/vedeu/output/null_border.rb +49 -0
  52. data/lib/vedeu/output/output.rb +8 -44
  53. data/lib/vedeu/output/renderers/all.rb +3 -0
  54. data/lib/vedeu/output/{renderer.rb → renderers/file_renderer.rb} +14 -6
  55. data/lib/vedeu/output/{html_renderer.rb → renderers/html_renderer.rb} +3 -1
  56. data/lib/vedeu/output/renderers/terminal_renderer.rb +50 -0
  57. data/lib/vedeu/output/text.rb +1 -1
  58. data/lib/vedeu/output/translator.rb +21 -2
  59. data/lib/vedeu/output/viewport.rb +17 -50
  60. data/lib/vedeu/output/virtual_terminal.rb +2 -0
  61. data/lib/vedeu/output/wordwrap.rb +2 -0
  62. data/lib/vedeu/repositories/all.rb +82 -0
  63. data/lib/vedeu/repositories/collection.rb +16 -0
  64. data/lib/vedeu/repositories/repository.rb +2 -0
  65. data/lib/vedeu/support/log.rb +3 -0
  66. data/lib/vedeu/support/sentence.rb +2 -0
  67. data/lib/vedeu/support/template.rb +2 -0
  68. data/lib/vedeu/support/terminal.rb +6 -1
  69. data/lib/vedeu/support/trace.rb +2 -0
  70. data/lib/vedeu/support/visible.rb +6 -0
  71. data/test/lib/vedeu/dsl/components/border_test.rb +0 -270
  72. data/test/lib/vedeu/dsl/shared/text_test.rb +19 -0
  73. data/test/lib/vedeu/geometry/area_test.rb +32 -0
  74. data/test/lib/vedeu/geometry/index_position_test.rb +36 -0
  75. data/test/lib/vedeu/models/interface_test.rb +42 -1
  76. data/test/lib/vedeu/models/line_test.rb +15 -1
  77. data/test/lib/vedeu/models/stream_test.rb +15 -1
  78. data/test/lib/vedeu/output/background_test.rb +4 -2
  79. data/test/lib/vedeu/output/border_test.rb +229 -127
  80. data/test/lib/vedeu/output/clear_test.rb +14 -0
  81. data/test/lib/vedeu/output/foreground_test.rb +4 -2
  82. data/test/lib/vedeu/output/null_border_test.rb +53 -0
  83. data/test/lib/vedeu/output/output_test.rb +2 -0
  84. data/test/lib/vedeu/output/{renderer_test.rb → renderers/file_renderer_test.rb} +5 -5
  85. data/test/lib/vedeu/output/renderers/html_renderer_test.rb +71 -0
  86. data/test/lib/vedeu/output/renderers/terminal_renderer_test.rb +24 -0
  87. data/test/lib/vedeu/output/viewport_test.rb +100 -74
  88. data/vedeu.gemspec +1 -1
  89. metadata +15 -11
  90. data/lib/vedeu/geometry/bounding_area.rb +0 -136
  91. data/test/lib/vedeu/geometry/bounding_area_test.rb +0 -123
  92. data/test/lib/vedeu/output/html_renderer_test.rb +0 -42
@@ -27,6 +27,8 @@ module Vedeu
27
27
  new(key, name).valid?
28
28
  end
29
29
 
30
+ # Returns a new instance of Vedeu::Mapper.
31
+ #
30
32
  # @param key [NilClass|String|Symbol]
31
33
  # @param name [NilClass|String]
32
34
  # @param repository [NilClass|Repository]
@@ -37,6 +39,9 @@ module Vedeu
37
39
  @repository = repository || Vedeu.keymaps
38
40
  end
39
41
 
42
+ # Returns a boolean indicating that the key is registered to the current
43
+ # keymap or the global or system keymap.
44
+ #
40
45
  # @return [Boolean]
41
46
  def keypress
42
47
  return false unless key
@@ -50,6 +55,9 @@ module Vedeu
50
55
  false
51
56
  end
52
57
 
58
+ # Returns a boolean indicating that the key is not registered to the current
59
+ # keymap, the global keymap or the system keymap.
60
+ #
53
61
  # @return [Boolean]
54
62
  def valid?
55
63
  return false unless key
@@ -27,6 +27,8 @@ module Vedeu
27
27
  kernel = Kernel).debug_execute!
28
28
  end
29
29
 
30
+ # Returns a new instance of Vedeu::Launcher.
31
+ #
30
32
  # @param argv [Array]
31
33
  # @param stdin [IO]
32
34
  # @param stdout [IO]
@@ -22,8 +22,6 @@ module Vedeu
22
22
  @loop = true
23
23
 
24
24
  while(@loop) do
25
- Vedeu.trigger(:tick)
26
-
27
25
  yield
28
26
 
29
27
  safe_exit_point!
@@ -51,7 +49,7 @@ module Vedeu
51
49
  fail VedeuInterrupt
52
50
 
53
51
  else
54
- Vedeu.trigger(:tock)
52
+ Vedeu.trigger(:tock, Time.now.to_f)
55
53
 
56
54
  end
57
55
  end
@@ -28,6 +28,8 @@ module Vedeu
28
28
  # @return [NilClass|Fixnum]
29
29
  attr_reader :y
30
30
 
31
+ # Returns a new instance of Vedeu::Cell.
32
+ #
31
33
  # @param attributes [Hash<Symbol => Array<Symbol|String>, Fixnum, String, Symbol]
32
34
  # @option attributes background [NilClass|String]
33
35
  # @option attributes foreground [NilClass|String]
@@ -15,7 +15,7 @@ module Vedeu
15
15
  collection Vedeu::Interfaces
16
16
  member Vedeu::Interface
17
17
 
18
- # Returns a new instance of Composition.
18
+ # Returns a new instance of Vedeu::Composition.
19
19
  #
20
20
  # @param attributes [Hash]
21
21
  # @option attributes colour [Vedeu::Colour]
@@ -13,7 +13,7 @@ module Vedeu
13
13
  # @return [String]
14
14
  attr_accessor :name
15
15
 
16
- # Return a new instance of Group.
16
+ # Return a new instance of Vedeu::Group.
17
17
  #
18
18
  # @param attributes [Hash]
19
19
  # @option attributes members [Array] A collection of names of interfaces
@@ -1,5 +1,6 @@
1
1
  require 'vedeu/geometry/content'
2
2
  require 'vedeu/models/all'
3
+ require 'vedeu/output/null_border'
3
4
  require 'vedeu/output/presentation'
4
5
  require 'vedeu/buffers/display_buffer'
5
6
  require 'vedeu/buffers/buffer'
@@ -58,10 +59,18 @@ module Vedeu
58
59
  :right,
59
60
  :bottom,
60
61
  :left,
62
+ :y,
63
+ :yn,
64
+ :x,
65
+ :xn,
61
66
  :width,
62
- :height
67
+ :height,
68
+ :top_left,
69
+ :top_right,
70
+ :bottom_left,
71
+ :bottom_right
63
72
 
64
- # Return a new instance of Interface.
73
+ # Return a new instance of Vedeu::Interface.
65
74
  #
66
75
  # @param attributes [Hash]
67
76
  # @option attributes colour [Vedeu::Colour]
@@ -117,11 +126,20 @@ module Vedeu
117
126
  #
118
127
  # @return [Vedeu::Border|NilClass]
119
128
  def border
120
- if border?
129
+ @border ||= if border?
121
130
  Vedeu.borders.find(name)
131
+
132
+ else
133
+ Vedeu::NullBorder.new(self)
134
+
122
135
  end
123
136
  end
124
137
 
138
+ # @return [Array<Array<Vedeu::Char>>]
139
+ def clear
140
+ Vedeu::Clear.render(self)
141
+ end
142
+
125
143
  # Fetch the cursor belonging to this interface (by name), if one does not
126
144
  # exist, it will be created, stored and returned.
127
145
  #
@@ -151,6 +169,15 @@ module Vedeu
151
169
  alias_method :content?, :lines?
152
170
  alias_method :value?, :lines?
153
171
 
172
+ # @return [Array<Array<Vedeu::Char>>]
173
+ def render
174
+ [
175
+ clear,
176
+ border.render,
177
+ viewport
178
+ ]
179
+ end
180
+
154
181
  # @return [Interface]
155
182
  def store
156
183
  super
@@ -161,6 +188,11 @@ module Vedeu
161
188
  store_group
162
189
  end
163
190
 
191
+ # @return [Array<Array<Vedeu::Char>>]
192
+ def viewport
193
+ Vedeu::Viewport.render(self)
194
+ end
195
+
164
196
  private
165
197
 
166
198
  # The default values for a new instance of this class.
@@ -25,7 +25,7 @@ module Vedeu
25
25
 
26
26
  alias_method :value, :streams
27
27
 
28
- # Returns a new instance of Line.
28
+ # Returns a new instance of Vedeu::Line.
29
29
  #
30
30
  # @param attributes [Hash]
31
31
  # @option attributes streams [Vedeu::Streams]
@@ -64,6 +64,11 @@ module Vedeu
64
64
  streams.empty?
65
65
  end
66
66
 
67
+ # @return [NilClass|String]
68
+ def name
69
+ parent.name if parent
70
+ end
71
+
67
72
  # Returns the size of the content in characters without formatting.
68
73
  #
69
74
  # @return [Fixnum]
@@ -57,7 +57,7 @@ module Vedeu
57
57
  build({ name: name }, &block).store
58
58
  end
59
59
 
60
- # Returns a new instance of Menu.
60
+ # Returns a new instance of Vedeu::Menu.
61
61
  #
62
62
  # @param attributes [Hash]
63
63
  # @option attributes collection [Array]
@@ -27,7 +27,7 @@ module Vedeu
27
27
  alias_method :data, :value
28
28
  alias_method :text, :value
29
29
 
30
- # Returns a new instance of Stream.
30
+ # Returns a new instance of Vedeu::Stream.
31
31
  #
32
32
  # @param attributes [Hash]
33
33
  # @option attributes value [String]
@@ -74,6 +74,11 @@ module Vedeu
74
74
  value.empty?
75
75
  end
76
76
 
77
+ # @return [NilClass|String]
78
+ def name
79
+ parent.name if parent
80
+ end
81
+
77
82
  # Returns the size of the content in characters without formatting.
78
83
  #
79
84
  # @return [Fixnum]
@@ -81,22 +86,6 @@ module Vedeu
81
86
  value.size
82
87
  end
83
88
 
84
- # @return [String]
85
- def value
86
- # Vedeu::Char.coerce(@value, parent, colour, style)
87
- # @value ||= if @value.size > 1
88
- # @value.chars.map do |char|
89
- # Vedeu::Char.new(char, parent, colour, style)
90
- # end
91
- # elsif @value.size == 1
92
- # Vedeu::Char.new(@value, parent, colour, style)
93
- # else
94
- # # ???
95
- # end
96
-
97
- @value
98
- end
99
-
100
89
  # Delegate to Vedeu::Line#width if available.
101
90
  #
102
91
  # @return [Fixnum]
@@ -5,6 +5,7 @@ require 'vedeu/output/background'
5
5
  require 'vedeu/output/foreground'
6
6
 
7
7
  require 'vedeu/output/border'
8
+ require 'vedeu/output/null_border'
8
9
  require 'vedeu/output/colour'
9
10
  require 'vedeu/output/compositor'
10
11
 
@@ -15,10 +16,10 @@ require 'vedeu/output/style'
15
16
  require 'vedeu/output/text'
16
17
  require 'vedeu/output/virtual_buffer'
17
18
  require 'vedeu/output/html_char'
18
- require 'vedeu/output/html_renderer'
19
19
  require 'vedeu/output/refresh'
20
20
 
21
- require 'vedeu/output/renderer'
21
+ require 'vedeu/output/renderers/all'
22
+
22
23
  require 'vedeu/output/output'
23
24
 
24
25
  require 'vedeu/output/viewport'
@@ -7,6 +7,32 @@ module Vedeu
7
7
 
8
8
  private
9
9
 
10
+ # Registers a HTML/CSS colour code and escape sequence to reduce processing.
11
+ #
12
+ # @param colour [String] A HTML/CSS colour code.
13
+ # @param escape_sequence [String] The HTML/CSS colour code as an escape
14
+ # sequence.
15
+ # @return [String]
16
+ def register(colour, escape_sequence)
17
+ Vedeu.background_colours.register(colour, escape_sequence)
18
+ end
19
+
20
+ # Returns a boolean indicating the HTML/CSS colour code has been registered.
21
+ #
22
+ # @param colour [String]
23
+ # @return [Boolean]
24
+ def registered?(colour)
25
+ Vedeu.background_colours.registered?(colour)
26
+ end
27
+
28
+ # Retrieves the escape sequence for the HTML/CSS colour code.
29
+ #
30
+ # @param colour [String]
31
+ # @return [String]
32
+ def retrieve(colour)
33
+ Vedeu.background_colours.retrieve(colour)
34
+ end
35
+
10
36
  # @return [String]
11
37
  def named_codes
12
38
  Vedeu::Esc.background_codes[colour]
@@ -80,7 +80,7 @@ module Vedeu
80
80
  # @return [Style]
81
81
  attr_reader :style
82
82
 
83
- # Returns a new instance of Border.
83
+ # Returns a new instance of Vedeu::Border.
84
84
  #
85
85
  # @param attributes [Hash]
86
86
  # @option attributes bottom_left [String] The bottom left border character.
@@ -123,6 +123,50 @@ module Vedeu
123
123
  @style = @attributes[:style]
124
124
  end
125
125
 
126
+ # @return [Fixnum]
127
+ def bx
128
+ if enabled? && left?
129
+ interface.x + 1
130
+
131
+ else
132
+ interface.x
133
+
134
+ end
135
+ end
136
+
137
+ # @return [Fixnum]
138
+ def bxn
139
+ if enabled? && right?
140
+ interface.xn - 1
141
+
142
+ else
143
+ interface.xn
144
+
145
+ end
146
+ end
147
+
148
+ # @return [Fixnum]
149
+ def by
150
+ if enabled? && top?
151
+ interface.y + 1
152
+
153
+ else
154
+ interface.y
155
+
156
+ end
157
+ end
158
+
159
+ # @return [Fixnum]
160
+ def byn
161
+ if enabled? && bottom?
162
+ interface.yn - 1
163
+
164
+ else
165
+ interface.yn
166
+
167
+ end
168
+ end
169
+
126
170
  # Returns the width of the interface determined by whether a left, right,
127
171
  # both or neither borders are shown.
128
172
  #
@@ -173,6 +217,19 @@ module Vedeu
173
217
  @colour = Vedeu::Colour.coerce(value)
174
218
  end
175
219
 
220
+ # @return [Array<Array<Vedeu::Char>>]
221
+ def render
222
+ return [] unless enabled?
223
+
224
+ out = [top, bottom]
225
+
226
+ height.times do |y|
227
+ out << [left(y), right(y)]
228
+ end
229
+
230
+ out.flatten
231
+ end
232
+
176
233
  # @return [Vedeu::Style]
177
234
  def style
178
235
  Vedeu::Style.coerce(@style)
@@ -185,15 +242,6 @@ module Vedeu
185
242
  @style = Vedeu::Style.coerce(value)
186
243
  end
187
244
 
188
- # Returns a string representation of the border for the interface without
189
- # content.
190
- #
191
- # @return [Boolean]
192
- def to_s
193
- render = Vedeu::Viewport.new(interface).render
194
- render.map { |line| line.flatten.join }.join("\n")
195
- end
196
-
197
245
  # Renders the bottom border for the interface.
198
246
  #
199
247
  # @return [String]
@@ -203,8 +251,8 @@ module Vedeu
203
251
  out = []
204
252
 
205
253
  out << border(bottom_left, :bottom_left) if left?
206
- width.times do
207
- out << border(horizontal, :bottom_horizontal)
254
+ width.times do |ix|
255
+ out << border(horizontal, :bottom_horizontal, nil, ix)
208
256
  end
209
257
  out << border(bottom_right, :bottom_right) if right?
210
258
 
@@ -213,20 +261,22 @@ module Vedeu
213
261
 
214
262
  # Renders the left border for the interface.
215
263
  #
264
+ # @param iy [Fixnum]
216
265
  # @return [String]
217
- def left
266
+ def left(iy = 0)
218
267
  return [] unless left?
219
268
 
220
- border(vertical, :left_vertical)
269
+ border(vertical, :left_vertical, iy)
221
270
  end
222
271
 
223
272
  # Renders the right border for the interface.
224
273
  #
274
+ # @param iy [Fixnum]
225
275
  # @return [String]
226
- def right
276
+ def right(iy = 0)
227
277
  return [] unless right?
228
278
 
229
- border(vertical, :right_vertical)
279
+ border(vertical, :right_vertical, iy)
230
280
  end
231
281
 
232
282
  # Renders the top border for the interface.
@@ -237,8 +287,8 @@ module Vedeu
237
287
 
238
288
  out = []
239
289
  out << border(top_left, :top_left) if left?
240
- width.times do
241
- out << border(horizontal, :top_horizontal)
290
+ width.times do |ix|
291
+ out << border(horizontal, :top_horizontal, nil, ix)
242
292
  end
243
293
  out << border(top_right, :top_right) if right?
244
294
 
@@ -249,21 +299,18 @@ module Vedeu
249
299
 
250
300
  # @param value [String]
251
301
  # @param type [Symbol|NilClass]
302
+ # @param iy [Fixnum]
303
+ # @param ix [Fixnum]
252
304
  # @return [Vedeu::Char]
253
- def border(value, type = :border)
305
+ def border(value, type = :border, iy = 0, ix = 0)
254
306
  Vedeu::Char.new({ value: value,
255
307
  parent: interface,
256
308
  colour: colour,
257
309
  style: style,
258
- position: nil,
310
+ position: position(type, iy, ix),
259
311
  border: type })
260
312
  end
261
313
 
262
- # @return [Vedeu::Interface]
263
- def interface
264
- @interface ||= Vedeu.interfaces.find(name)
265
- end
266
-
267
314
  # The default values for a new instance of this class.
268
315
  #
269
316
  # @return [Hash]
@@ -287,6 +334,39 @@ module Vedeu
287
334
  }
288
335
  end
289
336
 
337
+ # @return [Vedeu::Interface]
338
+ def interface
339
+ @interface ||= Vedeu.interfaces.find(name)
340
+ end
341
+
342
+ # @param name [Symbol]
343
+ # @param iy [Fixnum]
344
+ # @param ix [Fixnum]
345
+ # @return [Vedeu::Position]
346
+ def position(name, iy = 0, ix = 0)
347
+ case name
348
+ when :top_horizontal
349
+ Vedeu::Position[interface.y, (bx + ix)]
350
+
351
+ when :bottom_horizontal
352
+ Vedeu::Position[interface.yn, (bx + ix)]
353
+
354
+ when :left_vertical
355
+ Vedeu::Position[(by + iy), interface.x]
356
+
357
+ when :right_vertical
358
+ Vedeu::Position[(by + iy), interface.xn]
359
+
360
+ when :bottom_left then interface.bottom_left
361
+ when :bottom_right then interface.bottom_right
362
+ when :top_left then interface.top_left
363
+ when :top_right then interface.top_right
364
+ else
365
+ nil
366
+
367
+ end
368
+ end
369
+
290
370
  end # Border
291
371
 
292
372
  end # Vedeu