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
@@ -16,6 +16,8 @@ module Vedeu
16
16
  # @return [Fixnum]
17
17
  attr_reader :width
18
18
 
19
+ # Returns a new instance of Vedeu::VirtualTerminal.
20
+ #
19
21
  # @param height [Fixnum]
20
22
  # @param width [Fixnum]
21
23
  # @param renderer [Object|HTMLRenderer] An object responding to .render.
@@ -9,6 +9,8 @@ module Vedeu
9
9
  new(text, options).content
10
10
  end
11
11
 
12
+ # Returns a new instance of Vedeu::Wordwrap.
13
+ #
12
14
  # @param text [String]
13
15
  # @param options [Hash]
14
16
  # @option options ellipsis [String] For when using mode `:prune`.
@@ -28,6 +28,88 @@ module Vedeu
28
28
 
29
29
  end # Buffers
30
30
 
31
+ # Allows the storing of HTML/CSS colours and their respective escape
32
+ # sequences.
33
+ #
34
+ class Colours
35
+
36
+ # @!attribute [r] storage
37
+ # @return [Hash<String => String>]
38
+ attr_reader :storage
39
+
40
+ # Returns a new instance of Vedeu::Colours.
41
+ #
42
+ # @return [Vedeu::Colours]
43
+ def initialize
44
+ @storage = {}
45
+ end
46
+
47
+ # Registers a colour with respective escape sequence.
48
+ #
49
+ # @return [String]
50
+ def register(colour, escape_sequence)
51
+ storage.store(colour, escape_sequence)
52
+ end
53
+
54
+ # Returns a boolean indicating whether the colour has been registered.
55
+ #
56
+ # @return [Boolean]
57
+ def registered?(colour)
58
+ storage.key?(colour)
59
+ end
60
+
61
+ # Removes all stored colours.
62
+ #
63
+ # @return [Hash]
64
+ def reset!
65
+ storage.clear
66
+ end
67
+
68
+ # Retrieves a registered colour.
69
+ #
70
+ # @return [String]
71
+ def retrieve(colour)
72
+ storage.fetch(colour, '')
73
+ end
74
+
75
+ # Retrieves a registered colour, or registers the colour with its respective
76
+ # escape sequence.
77
+ #
78
+ # @return [String]
79
+ def retrieve_or_register(colour, escape_sequence)
80
+ if registered?(colour)
81
+ retrieve(colour)
82
+
83
+ else
84
+ register(colour, escape_sequence)
85
+
86
+ end
87
+ end
88
+
89
+ end # Colours
90
+
91
+ # Store background colour escape sequences by HTML/CSS code.
92
+ #
93
+ class BackgroundColours < Colours
94
+
95
+ # @return [Vedeu::BackgroundColours]
96
+ def self.background_colours
97
+ @background_colours ||= new
98
+ end
99
+
100
+ end # BackgroundColours
101
+
102
+ # Store foreground colour escape sequences by HTML/CSS code.
103
+ #
104
+ class ForegroundColours < Colours
105
+
106
+ # @return [Vedeu::ForegroundColours]
107
+ def self.foreground_colours
108
+ @foreground_colours ||= new
109
+ end
110
+
111
+ end # ForegroundColours
112
+
31
113
  # Allows the storing of each interface's cursor.
32
114
  #
33
115
  class Cursors < Repository
@@ -29,6 +29,8 @@ module Vedeu
29
29
  end
30
30
  end
31
31
 
32
+ # Returns a new instance of Vedeu::Collection.
33
+ #
32
34
  # @param collection []
33
35
  # @param parent [void]
34
36
  # @param name [String|NilClass]
@@ -39,12 +41,16 @@ module Vedeu
39
41
  @name = name
40
42
  end
41
43
 
44
+ # Fetch an entry from the collection via index.
45
+ #
42
46
  # @param value [Fixnum]
43
47
  # @return [void]
44
48
  def [](value)
45
49
  @collection[value]
46
50
  end
47
51
 
52
+ # Adds an entry to the collection.
53
+ #
48
54
  # @param other [Vedeu::Collection]
49
55
  # @return [Vedeu::Collection]
50
56
  def add(*other)
@@ -52,27 +58,37 @@ module Vedeu
52
58
  end
53
59
  alias_method :<<, :add
54
60
 
61
+ # Returns the whole collection.
62
+ #
55
63
  # @return [Array]
56
64
  def all
57
65
  @collection
58
66
  end
59
67
 
68
+ # Provides iteration over the collection.
69
+ #
60
70
  # @param block [Proc]
61
71
  # @return [Enumerator]
62
72
  def each(&block)
63
73
  @collection.each(&block)
64
74
  end
65
75
 
76
+ # Returns a boolean indicating whether the collection is empty.
77
+ #
66
78
  # @return [Boolean]
67
79
  def empty?
68
80
  @collection.empty?
69
81
  end
70
82
 
83
+ # Returns the size of the collection.
84
+ #
71
85
  # @return [Fixnum]
72
86
  def size
73
87
  @collection.size
74
88
  end
75
89
 
90
+ # Returns the collection as a String.
91
+ #
76
92
  # @return [String]
77
93
  def to_s
78
94
  @collection.map(&:to_s).join
@@ -24,6 +24,8 @@ module Vedeu
24
24
  # @return [void]
25
25
  attr_reader :storage
26
26
 
27
+ # Returns a new instance of Vedeu::Repository.
28
+ #
27
29
  # @param model [Class]
28
30
  # @param storage [Class|Hash]
29
31
  # @return [Vedeu::Repository]
@@ -31,8 +31,11 @@ module Vedeu
31
31
 
32
32
  # Ensures we can always write to the log file by creating a lock-less
33
33
  # log device.
34
+ #
34
35
  class LocklessLogDevice < LogDevice
35
36
 
37
+ # Returns a new instance of Vedeu::LocklessLogDevice.
38
+ #
36
39
  # @param log []
37
40
  # @return []
38
41
  def initialize(log = nil)
@@ -15,6 +15,8 @@ module Vedeu
15
15
  new(elements, label).construct
16
16
  end
17
17
 
18
+ # Returns a new instance of Vedeu::Sentence.
19
+ #
18
20
  # @param elements [Array]
19
21
  # @param label [String]
20
22
  # @return [Vedeu::Sentence]
@@ -13,6 +13,8 @@ module Vedeu
13
13
  new(object, path).parse
14
14
  end
15
15
 
16
+ # Returns a new instance of Vedeu::Template.
17
+ #
16
18
  # @param object [Class]
17
19
  # @param path [String]
18
20
  # @return [Template]
@@ -41,7 +41,7 @@ module Vedeu
41
41
  #
42
42
  # @return [String]
43
43
  def input
44
- if raw_mode?
44
+ keys_or_cmd = if raw_mode?
45
45
  keys = console.getch
46
46
  if keys.ord == 27
47
47
  keys << console.read_nonblock(3) rescue nil
@@ -53,6 +53,10 @@ module Vedeu
53
53
  console.gets.chomp
54
54
 
55
55
  end
56
+
57
+ Vedeu.trigger(:tick, Time.now.to_f)
58
+
59
+ keys_or_cmd
56
60
  end
57
61
  alias_method :read, :input
58
62
 
@@ -62,6 +66,7 @@ module Vedeu
62
66
  # @return [Array]
63
67
  def output(*streams)
64
68
  streams.each do |stream|
69
+ # Write the stream to the log file.
65
70
  # Vedeu.log(Esc.escape(stream))
66
71
 
67
72
  console.print(stream)
@@ -32,6 +32,8 @@ module Vedeu
32
32
  new(options).trace
33
33
  end
34
34
 
35
+ # Returns a new instance of Vedeu::Trace
36
+ #
35
37
  # @param options [Hash]
36
38
  # @return [Trace]
37
39
  def initialize(options = {})
@@ -18,6 +18,8 @@ module Vedeu
18
18
  end
19
19
  end
20
20
 
21
+ # Returns a new instance of Vedeu::Visible
22
+ #
21
23
  # @param visible [Boolean|Symbol]
22
24
  # @return [Visible]
23
25
  def initialize(visible = nil)
@@ -49,11 +51,15 @@ module Vedeu
49
51
  end
50
52
  end
51
53
 
54
+ # Returns a boolean indicating whether the instance is visible.
55
+ #
52
56
  # @return [Boolean]
53
57
  def visible?
54
58
  @visible
55
59
  end
56
60
 
61
+ # Returns a boolean indicating whether the instance is invisible.
62
+ #
57
63
  # @return [Boolean]
58
64
  def invisible?
59
65
  !@visible
@@ -48,33 +48,6 @@ module Vedeu
48
48
 
49
49
  it { subject.must_be_instance_of(String) }
50
50
  it { subject.must_equal('C') }
51
-
52
- context 'DSL #bottom_left' do
53
- subject {
54
- Vedeu.interface 'borders' do
55
- border do
56
- bottom_left '<'
57
- end
58
- geometry do
59
- height 3
60
- width 3
61
- end
62
- lines do
63
- line ''
64
- end
65
- end
66
- }
67
-
68
- it { subject.must_be_instance_of(Vedeu::Interface) }
69
-
70
- it 'allows the use of bottom_left within border' do
71
- subject.border.to_s.must_equal(
72
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
73
- "\e(0x\e(B \e(0x\e(B\n" \
74
- "\e(0<\e(B\e(0q\e(B\e(0j\e(B"
75
- )
76
- end
77
- end
78
51
  end
79
52
 
80
53
  describe '#bottom_right' do
@@ -84,33 +57,6 @@ module Vedeu
84
57
 
85
58
  it { subject.must_be_instance_of(String) }
86
59
  it { subject.must_equal('D') }
87
-
88
- context 'DSL #bottom_right' do
89
- subject {
90
- Vedeu.interface 'borders' do
91
- border do
92
- bottom_right '>'
93
- end
94
- geometry do
95
- height 3
96
- width 3
97
- end
98
- lines do
99
- line ''
100
- end
101
- end
102
- }
103
-
104
- it { subject.must_be_instance_of(Vedeu::Interface) }
105
-
106
- it 'allows the use of bottom_right within border' do
107
- subject.border.to_s.must_equal(
108
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
109
- "\e(0x\e(B \e(0x\e(B\n" \
110
- "\e(0m\e(B\e(0q\e(B\e(0>\e(B"
111
- )
112
- end
113
- end
114
60
  end
115
61
 
116
62
  describe '#horizontal' do
@@ -120,33 +66,6 @@ module Vedeu
120
66
 
121
67
  it { subject.must_be_instance_of(String) }
122
68
  it { subject.must_equal('H') }
123
-
124
- context 'DSL #horizontal' do
125
- subject {
126
- Vedeu.interface 'borders' do
127
- border do
128
- horizontal '~'
129
- end
130
- geometry do
131
- height 3
132
- width 3
133
- end
134
- lines do
135
- line ''
136
- end
137
- end
138
- }
139
-
140
- it { subject.must_be_instance_of(Vedeu::Interface) }
141
-
142
- it 'allows the use of horizontal within border' do
143
- subject.border.to_s.must_equal(
144
- "\e(0l\e(B\e(0~\e(B\e(0k\e(B\n" \
145
- "\e(0x\e(B \e(0x\e(B\n" \
146
- "\e(0m\e(B\e(0~\e(B\e(0j\e(B"
147
- )
148
- end
149
- end
150
69
  end
151
70
 
152
71
  describe '#show_bottom' do
@@ -160,33 +79,6 @@ module Vedeu
160
79
  it { subject.must_be_instance_of(FalseClass) }
161
80
  end
162
81
 
163
- context 'DSL #show_bottom' do
164
- subject {
165
- Vedeu.interface 'borders' do
166
- border do
167
- show_bottom ''
168
- end
169
- geometry do
170
- height 3
171
- width 3
172
- end
173
- lines do
174
- line ''
175
- end
176
- end
177
- }
178
-
179
- it { subject.must_be_instance_of(Vedeu::Interface) }
180
-
181
- it 'allows the use of show_bottom within border' do
182
- subject.border.to_s.must_equal(
183
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
184
- "\e(0x\e(B \e(0x\e(B\n" \
185
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
186
- )
187
- end
188
- end
189
-
190
82
  it { instance.must_respond_to(:bottom) }
191
83
  end
192
84
 
@@ -214,33 +106,6 @@ module Vedeu
214
106
 
215
107
  it { subject.must_be_instance_of(FalseClass) }
216
108
  end
217
-
218
- context 'DSL #show_left' do
219
- subject {
220
- Vedeu.interface 'borders' do
221
- border do
222
- show_left!
223
- end
224
- geometry do
225
- height 3
226
- width 3
227
- end
228
- lines do
229
- line ''
230
- end
231
- end
232
- }
233
-
234
- it { subject.must_be_instance_of(Vedeu::Interface) }
235
-
236
- it 'allows the use of show_left within border' do
237
- subject.border.to_s.must_equal(
238
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
239
- "\e(0x\e(B \e(0x\e(B\n" \
240
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
241
- )
242
- end
243
- end
244
109
  end
245
110
 
246
111
  describe '#hide_left!' do
@@ -267,33 +132,6 @@ module Vedeu
267
132
 
268
133
  it { subject.must_be_instance_of(FalseClass) }
269
134
  end
270
-
271
- context 'DSL #show_right' do
272
- subject {
273
- Vedeu.interface 'borders' do
274
- border do
275
- show_right!
276
- end
277
- geometry do
278
- height 3
279
- width 3
280
- end
281
- lines do
282
- line ''
283
- end
284
- end
285
- }
286
-
287
- it { subject.must_be_instance_of(Vedeu::Interface) }
288
-
289
- it 'allows the use of show_right within border' do
290
- subject.border.to_s.must_equal(
291
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
292
- "\e(0x\e(B \e(0x\e(B\n" \
293
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
294
- )
295
- end
296
- end
297
135
  end
298
136
 
299
137
  describe '#hide_right!' do
@@ -320,33 +158,6 @@ module Vedeu
320
158
 
321
159
  it { subject.must_be_instance_of(FalseClass) }
322
160
  end
323
-
324
- context 'DSL #show_top' do
325
- subject {
326
- Vedeu.interface 'borders' do
327
- border do
328
- show_top ''
329
- end
330
- geometry do
331
- height 3
332
- width 3
333
- end
334
- lines do
335
- line ''
336
- end
337
- end
338
- }
339
-
340
- it { subject.must_be_instance_of(Vedeu::Interface) }
341
-
342
- it 'allows the use of show_top within border' do
343
- subject.border.to_s.must_equal(
344
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
345
- "\e(0x\e(B \e(0x\e(B\n" \
346
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
347
- )
348
- end
349
- end
350
161
  end
351
162
 
352
163
  describe '#hide_top!' do
@@ -368,33 +179,6 @@ module Vedeu
368
179
 
369
180
  it { subject.must_be_instance_of(String) }
370
181
  it { subject.must_equal('A') }
371
-
372
- context 'DSL #top_left' do
373
- subject {
374
- Vedeu.interface 'borders' do
375
- border do
376
- top_left '{'
377
- end
378
- geometry do
379
- height 3
380
- width 3
381
- end
382
- lines do
383
- line ''
384
- end
385
- end
386
- }
387
-
388
- it { subject.must_be_instance_of(Vedeu::Interface) }
389
-
390
- it 'allows the use of top_left within border' do
391
- subject.border.to_s.must_equal(
392
- "\e(0{\e(B\e(0q\e(B\e(0k\e(B\n" \
393
- "\e(0x\e(B \e(0x\e(B\n" \
394
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
395
- )
396
- end
397
- end
398
182
  end
399
183
 
400
184
  describe '#top_right' do
@@ -404,33 +188,6 @@ module Vedeu
404
188
 
405
189
  it { subject.must_be_instance_of(String) }
406
190
  it { subject.must_equal('B') }
407
-
408
- context 'DSL #top_right' do
409
- subject {
410
- Vedeu.interface 'borders' do
411
- border do
412
- top_right '}'
413
- end
414
- geometry do
415
- height 3
416
- width 3
417
- end
418
- lines do
419
- line ''
420
- end
421
- end
422
- }
423
-
424
- it { subject.must_be_instance_of(Vedeu::Interface) }
425
-
426
- it 'allows the use of top_right within border' do
427
- subject.border.to_s.must_equal(
428
- "\e(0l\e(B\e(0q\e(B\e(0}\e(B\n" \
429
- "\e(0x\e(B \e(0x\e(B\n" \
430
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
431
- )
432
- end
433
- end
434
191
  end
435
192
 
436
193
  describe '#vertical' do
@@ -440,33 +197,6 @@ module Vedeu
440
197
 
441
198
  it { subject.must_be_instance_of(String) }
442
199
  it { subject.must_equal('V') }
443
-
444
- context 'DSL #vertical' do
445
- subject {
446
- Vedeu.interface 'borders' do
447
- border do
448
- vertical ':'
449
- end
450
- geometry do
451
- height 3
452
- width 3
453
- end
454
- lines do
455
- line ''
456
- end
457
- end
458
- }
459
-
460
- it { subject.must_be_instance_of(Vedeu::Interface) }
461
-
462
- it 'allows the use of vertical within border' do
463
- subject.border.to_s.must_equal(
464
- "\e(0l\e(B\e(0q\e(B\e(0k\e(B\n" \
465
- "\e(0:\e(B \e(0:\e(B\n" \
466
- "\e(0m\e(B\e(0q\e(B\e(0j\e(B"
467
- )
468
- end
469
- end
470
200
  end
471
201
 
472
202
  end # Border