vedeu 0.2.11 → 0.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/examples/borders_app.rb +171 -0
  3. data/lib/vedeu.rb +1 -1
  4. data/lib/vedeu/api/interface.rb +12 -0
  5. data/lib/vedeu/api/menu.rb +1 -1
  6. data/lib/vedeu/colours/colour.rb +1 -1
  7. data/lib/vedeu/models/border.rb +238 -0
  8. data/lib/vedeu/models/char.rb +1 -1
  9. data/lib/vedeu/models/composition.rb +1 -1
  10. data/lib/vedeu/models/geometry.rb +1 -1
  11. data/lib/vedeu/models/line.rb +1 -1
  12. data/lib/vedeu/models/stream.rb +1 -1
  13. data/lib/vedeu/output/output.rb +1 -1
  14. data/lib/vedeu/output/viewport.rb +34 -3
  15. data/lib/vedeu/repositories/models/cursor.rb +34 -7
  16. data/lib/vedeu/repositories/models/event.rb +1 -1
  17. data/lib/vedeu/repositories/models/group.rb +1 -1
  18. data/lib/vedeu/repositories/models/interface.rb +14 -6
  19. data/lib/vedeu/repositories/models/keymap.rb +1 -1
  20. data/lib/vedeu/repositories/models/offset.rb +1 -1
  21. data/lib/vedeu/support/trace.rb +1 -1
  22. data/test/integration/views/basic_view_test.rb +19 -0
  23. data/test/lib/vedeu/api/api_test.rb +6 -5
  24. data/test/lib/vedeu/api/helpers_test.rb +2 -6
  25. data/test/lib/vedeu/api/interface_test.rb +53 -45
  26. data/test/lib/vedeu/api/menu_test.rb +6 -0
  27. data/test/lib/vedeu/api/stream_test.rb +1 -3
  28. data/test/lib/vedeu/application_test.rb +6 -12
  29. data/test/lib/vedeu/colours/colour_test.rb +16 -5
  30. data/test/lib/vedeu/colours/translator_test.rb +7 -2
  31. data/test/lib/vedeu/configuration/cli_test.rb +9 -0
  32. data/test/lib/vedeu/input/input_test.rb +5 -5
  33. data/test/lib/vedeu/launcher_test.rb +9 -3
  34. data/test/lib/vedeu/models/border_test.rb +197 -0
  35. data/test/lib/vedeu/models/char_test.rb +18 -15
  36. data/test/lib/vedeu/models/composition_test.rb +6 -7
  37. data/test/lib/vedeu/models/geometry_test.rb +43 -49
  38. data/test/lib/vedeu/models/key_test.rb +7 -5
  39. data/test/lib/vedeu/models/line_test.rb +12 -16
  40. data/test/lib/vedeu/models/stream_test.rb +20 -10
  41. data/test/lib/vedeu/models/style_test.rb +9 -10
  42. data/test/lib/vedeu/output/compositor_test.rb +7 -22
  43. data/test/lib/vedeu/output/output_test.rb +34 -33
  44. data/test/lib/vedeu/output/viewport_test.rb +6 -6
  45. data/test/lib/vedeu/repositories/models/buffer_test.rb +13 -18
  46. data/test/lib/vedeu/repositories/models/cursor_test.rb +21 -21
  47. data/test/lib/vedeu/repositories/models/event_test.rb +10 -4
  48. data/test/lib/vedeu/{models → repositories/models}/group_test.rb +8 -9
  49. data/test/lib/vedeu/repositories/models/interface_test.rb +37 -17
  50. data/test/lib/vedeu/repositories/models/keymap_test.rb +6 -6
  51. data/test/lib/vedeu/repositories/models/menu_test.rb +6 -3
  52. data/test/lib/vedeu/repositories/models/offset_test.rb +6 -3
  53. data/test/lib/vedeu/support/bounding_area_test.rb +28 -36
  54. data/test/lib/vedeu/support/grid_test.rb +8 -0
  55. data/test/lib/vedeu/support/keymap_validator_test.rb +5 -8
  56. data/test/lib/vedeu/support/position_test.rb +3 -3
  57. data/test/lib/vedeu/support/registrar_test.rb +13 -7
  58. data/test/lib/vedeu/support/sentence_test.rb +9 -2
  59. data/test/lib/vedeu/support/trace_test.rb +5 -3
  60. data/test/test_helper.rb +12 -0
  61. data/vedeu.gemspec +1 -1
  62. metadata +8 -7
  63. data/lib/vedeu/output/view.rb +0 -64
  64. data/test/lib/vedeu/output/view_test.rb +0 -21
@@ -19,7 +19,7 @@ module Vedeu
19
19
  # @param attributes [Hash]
20
20
  # @return [Char]
21
21
  def initialize(attributes = {})
22
- @attributes = defaults.merge!(attributes)
22
+ @attributes = defaults.merge(attributes)
23
23
  @parent = @attributes[:parent]
24
24
  @value = @attributes[:value]
25
25
  end
@@ -22,7 +22,7 @@ module Vedeu
22
22
  # @param block [Proc]
23
23
  # @return [Composition]
24
24
  def initialize(attributes = {}, &block)
25
- @attributes = defaults.merge!(attributes)
25
+ @attributes = defaults.merge(attributes)
26
26
 
27
27
  if block_given?
28
28
  @self_before_instance_eval = eval('self', block.binding)
@@ -16,7 +16,7 @@ module Vedeu
16
16
  # @param attributes [Hash]
17
17
  # @return [Geometry]
18
18
  def initialize(attributes = {})
19
- @attributes = defaults.merge!(attributes)
19
+ @attributes = defaults.merge(attributes)
20
20
 
21
21
  @centred = @attributes[:centred]
22
22
  @height = @attributes[:height]
@@ -27,7 +27,7 @@ module Vedeu
27
27
  # @param block [Proc]
28
28
  # @return [Line]
29
29
  def initialize(attributes = {}, &block)
30
- @attributes = defaults.merge!(attributes)
30
+ @attributes = defaults.merge(attributes)
31
31
  @parent = @attributes[:parent]
32
32
 
33
33
  if block_given?
@@ -27,7 +27,7 @@ module Vedeu
27
27
  # @param block [Proc]
28
28
  # @return [Stream]
29
29
  def initialize(attributes = {}, &block)
30
- @attributes = defaults.merge!(attributes)
30
+ @attributes = defaults.merge(attributes)
31
31
  @align = @attributes[:align]
32
32
  @text = @attributes[:text]
33
33
  @width = @attributes[:width]
@@ -62,7 +62,7 @@ module Vedeu
62
62
 
63
63
  Vedeu.log("Rendering view: '#{interface.name}'")
64
64
 
65
- interface.viewport.each_with_index do |line, index|
65
+ interface.border.to_viewport.each_with_index do |line, index|
66
66
  out << interface.origin(index)
67
67
  out << line.join
68
68
  end
@@ -37,15 +37,46 @@ module Vedeu
37
37
 
38
38
  return [] unless content?
39
39
 
40
- (content[lines] || []).map do |line|
41
- line.chars[columns] || [" "]
42
- end.compact
40
+ line_pad.map { |line| column_pad(line) }.compact
43
41
  end
44
42
 
45
43
  private
46
44
 
47
45
  attr_reader :interface
48
46
 
47
+ # Pad the number of rows so that we always return an Array of the same
48
+ # length for each viewport.
49
+ #
50
+ # @return [Array<Array<String>>]
51
+ def line_pad
52
+ cl = content[lines] || []
53
+
54
+ if cl.size < (height + 1)
55
+ cl + [" "] * ((height + 1) - cl.size)
56
+
57
+ else
58
+ cl
59
+
60
+ end
61
+ end
62
+
63
+ # Pads the number of columns so that we always return an Array of the same
64
+ # length for each line.
65
+ #
66
+ # @param line [Array<String>]
67
+ # @return [Array<String>]
68
+ def column_pad(line)
69
+ chars = line.chars[columns] || [" "]
70
+
71
+ if chars.size < width
72
+ chars + [" "] * (width - chars.size)
73
+
74
+ else
75
+ chars
76
+
77
+ end
78
+ end
79
+
49
80
  # Scrolls the content vertically when the stored y offset for the interface
50
81
  # is outside of the visible area.
51
82
  #
@@ -25,7 +25,7 @@ module Vedeu
25
25
  #
26
26
  # @return [Cursor]
27
27
  def initialize(attributes = {})
28
- @attributes = defaults.merge!(attributes)
28
+ @attributes = defaults.merge(attributes)
29
29
 
30
30
  @name = @attributes[:name]
31
31
  @state = @attributes[:state]
@@ -49,18 +49,26 @@ module Vedeu
49
49
 
50
50
  # Returns the x coordinate (column/character) of the cursor. Attempts to
51
51
  # sensibly reposition the cursor if it is currently outside the interface,
52
- # or outside the visible area of the terminal.
52
+ # or outside the visible area of the terminal. If the interface has either a
53
+ # left or right border, then the cursor will be repositioned to be inside
54
+ # the border not on it.
53
55
  #
54
56
  # @return [Fixnum]
55
57
  def x
56
58
  @x = 1 if @x <= 1
57
59
  @x = Terminal.width if @x >= Terminal.width
58
60
 
59
- if @x <= left
61
+ if border? && border.left? && @x <= (left + 1)
62
+ @x = (left + 1)
63
+
64
+ elsif @x <= left
60
65
  @x = left
61
66
 
67
+ elsif border? && border.right? && @x >= (right - 1)
68
+ @x = (right - 2)
69
+
62
70
  elsif @x >= right
63
- @x = right - 1
71
+ @x = right
64
72
 
65
73
  else
66
74
  @x
@@ -70,18 +78,26 @@ module Vedeu
70
78
 
71
79
  # Returns the y coordinate (row/line) of the cursor. Attempts to sensibly
72
80
  # reposition the cursor if it is currently outside the interface, or outside
73
- # the visible area of the terminal.
81
+ # the visible area of the terminal. If the interface has either a top or
82
+ # bottom border, then the cursor will be repositioned to be inside the
83
+ # border not on it.
74
84
  #
75
85
  # @return [Fixnum]
76
86
  def y
77
87
  @y = 1 if @y <= 1
78
88
  @y = Terminal.height if @y >= Terminal.height
79
89
 
80
- if @y <= top
90
+ if border? && border.top? && @y <= (top + 1)
91
+ @y = (top + 1)
92
+
93
+ elsif @y <= top
81
94
  @y = top
82
95
 
96
+ elsif border? && border.bottom? && @y >= (bottom - 1)
97
+ @y = (bottom - 2)
98
+
83
99
  elsif @y >= bottom
84
- @y = bottom - 1
100
+ @y = bottom
85
101
 
86
102
  else
87
103
  @y
@@ -153,6 +169,17 @@ module Vedeu
153
169
  Esc.string('hide_cursor')
154
170
  end
155
171
 
172
+ # Returns a boolean indicating whether the interface has a border.
173
+ #
174
+ # @return [Boolean]
175
+ def border?
176
+ border.enabled?
177
+ end
178
+
179
+ def border
180
+ interface.border
181
+ end
182
+
156
183
  # Returns an instance of the associated interface for this cursor, used to
157
184
  # ensure that {x} and {y} are still 'inside' the interface. A cursor could
158
185
  # be 'outside' the interface if the terminal has resized, causing the
@@ -159,7 +159,7 @@ module Vedeu
159
159
  #
160
160
  # @return [Hash]
161
161
  def options
162
- defaults.merge!(@options)
162
+ defaults.merge(@options)
163
163
  end
164
164
 
165
165
  # The default values for a new instance of Event.
@@ -13,8 +13,8 @@ module Vedeu
13
13
  # @param members [String]
14
14
  # @return [Group]
15
15
  def initialize(name, *members)
16
- @members = members.to_set
17
16
  @name = name
17
+ @members = members.to_set
18
18
  end
19
19
 
20
20
  # Add a member to the group by name.
@@ -42,13 +42,13 @@ module Vedeu
42
42
  # @param block [Proc]
43
43
  # @return [Interface]
44
44
  def initialize(attributes = {}, &block)
45
- @attributes = defaults.merge!(attributes)
45
+ @attributes = defaults.merge(attributes)
46
46
 
47
- @cursor = @attributes[:cursor]
48
- @delay = @attributes[:delay]
49
- @group = @attributes[:group]
50
- @name = @attributes[:name]
51
- @parent = @attributes[:parent]
47
+ @cursor = @attributes[:cursor]
48
+ @delay = @attributes[:delay]
49
+ @group = @attributes[:group]
50
+ @name = @attributes[:name]
51
+ @parent = @attributes[:parent]
52
52
 
53
53
  if block_given?
54
54
  @self_before_instance_eval = eval('self', block.binding)
@@ -68,6 +68,13 @@ module Vedeu
68
68
  self
69
69
  end
70
70
 
71
+ # Returns an instance of Border.
72
+ #
73
+ # @return [Border]
74
+ def border
75
+ @_border ||= Border.new(self, attributes[:border])
76
+ end
77
+
71
78
  # Returns an instance of Cursor.
72
79
  #
73
80
  # @return [Cursor]
@@ -128,6 +135,7 @@ module Vedeu
128
135
  # @return [Hash]
129
136
  def defaults
130
137
  {
138
+ border: {},
131
139
  colour: {},
132
140
  cursor: :hide,
133
141
  delay: 0.0,
@@ -60,7 +60,7 @@ module Vedeu
60
60
  # @param attributes [Hash]
61
61
  # @return [Keymap]
62
62
  def initialize(attributes = {})
63
- @attributes = defaults.merge!(attributes)
63
+ @attributes = defaults.merge(attributes)
64
64
  end
65
65
 
66
66
  # Adds the attributes to the Keymaps repository.
@@ -20,7 +20,7 @@ module Vedeu
20
20
  # @param attributes [Hash]
21
21
  # @return [Offset]
22
22
  def initialize(attributes = {})
23
- @attributes = defaults.merge!(attributes)
23
+ @attributes = defaults.merge(attributes)
24
24
  @name = @attributes[:name]
25
25
  @y = @attributes[:y]
26
26
  @x = @attributes[:x]
@@ -93,7 +93,7 @@ module Vedeu
93
93
 
94
94
  # @return [Hash]
95
95
  def options
96
- defaults.merge!(@options)
96
+ defaults.merge(@options)
97
97
  end
98
98
 
99
99
  # @return [Hash]
@@ -21,6 +21,7 @@ module Vedeu
21
21
  end
22
22
  end.must_equal(
23
23
  { interfaces: [{
24
+ border: {},
24
25
  name: 'testing_view',
25
26
  cursor: :hide,
26
27
  group: '',
@@ -54,6 +55,7 @@ module Vedeu
54
55
  end
55
56
  end.must_equal(
56
57
  { interfaces: [{
58
+ border: {},
57
59
  name: 'testing_view',
58
60
  cursor: :hide,
59
61
  group: '',
@@ -82,6 +84,7 @@ module Vedeu
82
84
  end
83
85
  end.must_equal(
84
86
  { interfaces: [{
87
+ border: {},
85
88
  name: 'testing_view',
86
89
  cursor: :hide,
87
90
  group: '',
@@ -110,6 +113,7 @@ module Vedeu
110
113
  end
111
114
  end.must_equal(
112
115
  { interfaces: [{
116
+ border: {},
113
117
  name: 'testing_view',
114
118
  cursor: :hide,
115
119
  group: '',
@@ -139,6 +143,7 @@ module Vedeu
139
143
  end
140
144
  end.must_equal(
141
145
  { interfaces: [{
146
+ border: {},
142
147
  name: 'testing_view',
143
148
  cursor: :hide,
144
149
  group: '',
@@ -175,6 +180,7 @@ module Vedeu
175
180
  end
176
181
  end.must_equal(
177
182
  { interfaces: [{
183
+ border: {},
178
184
  name: 'testing_view',
179
185
  cursor: :hide,
180
186
  group: '',
@@ -210,6 +216,7 @@ module Vedeu
210
216
  end
211
217
  end.must_equal(
212
218
  { interfaces: [{
219
+ border: {},
213
220
  name: 'testing_view',
214
221
  cursor: :hide,
215
222
  group: '',
@@ -240,6 +247,7 @@ module Vedeu
240
247
  end
241
248
  end.must_equal(
242
249
  { interfaces: [{
250
+ border: {},
243
251
  name: 'testing_view',
244
252
  cursor: :hide,
245
253
  group: '',
@@ -271,6 +279,7 @@ module Vedeu
271
279
  end
272
280
  end.must_equal(
273
281
  { interfaces: [{
282
+ border: {},
274
283
  name: 'testing_view',
275
284
  cursor: :hide,
276
285
  group: '',
@@ -307,6 +316,7 @@ module Vedeu
307
316
  end
308
317
  end.must_equal(
309
318
  { interfaces: [{
319
+ border: {},
310
320
  name: 'testing_view',
311
321
  cursor: :hide,
312
322
  group: '',
@@ -343,6 +353,7 @@ module Vedeu
343
353
  end
344
354
  end.must_equal(
345
355
  { interfaces: [{
356
+ border: {},
346
357
  name: 'testing_view',
347
358
  cursor: :hide,
348
359
  group: '',
@@ -387,6 +398,7 @@ module Vedeu
387
398
  end
388
399
  end.must_equal(
389
400
  { interfaces: [{
401
+ border: {},
390
402
  name: 'testing_view',
391
403
  cursor: :hide,
392
404
  group: '',
@@ -437,6 +449,7 @@ module Vedeu
437
449
  end
438
450
  end.must_equal(
439
451
  { interfaces: [{
452
+ border: {},
440
453
  name: 'testing_view',
441
454
  cursor: :hide,
442
455
  group: '',
@@ -490,6 +503,7 @@ module Vedeu
490
503
  end
491
504
  end.must_equal(
492
505
  { interfaces: [{
506
+ border: {},
493
507
  name: 'testing_view',
494
508
  cursor: :hide,
495
509
  group: '',
@@ -536,6 +550,7 @@ module Vedeu
536
550
  end
537
551
  end.must_equal(
538
552
  { interfaces: [{
553
+ border: {},
539
554
  name: 'testing_view',
540
555
  cursor: :hide,
541
556
  group: '',
@@ -572,6 +587,7 @@ module Vedeu
572
587
  end
573
588
  end.must_equal(
574
589
  { interfaces: [{
590
+ border: {},
575
591
  name: 'testing_view',
576
592
  cursor: :hide,
577
593
  group: '',
@@ -608,6 +624,7 @@ module Vedeu
608
624
  end
609
625
  end.must_equal(
610
626
  { interfaces: [{
627
+ border: {},
611
628
  name: 'testing_view',
612
629
  cursor: :hide,
613
630
  group: '',
@@ -644,6 +661,7 @@ module Vedeu
644
661
  end
645
662
  end.must_equal(
646
663
  { interfaces: [{
664
+ border: {},
647
665
  name: 'testing_view',
648
666
  cursor: :hide,
649
667
  group: '',
@@ -689,6 +707,7 @@ module Vedeu
689
707
  end
690
708
  end.must_equal(
691
709
  { interfaces: [{
710
+ border: {},
692
711
  name: 'testing_view',
693
712
  cursor: :hide,
694
713
  group: '',
@@ -156,15 +156,16 @@ module Vedeu
156
156
  let(:composition) {
157
157
  {
158
158
  interfaces: [{
159
- name: "some_interface",
159
+ border: {},
160
+ colour: {},
160
161
  cursor: :hide,
162
+ delay: 0.0,
163
+ geometry: {},
161
164
  group: '',
162
165
  lines: [],
163
- colour: {},
166
+ name: "some_interface",
167
+ parent: {},
164
168
  style: '',
165
- geometry: {},
166
- delay: 0.0,
167
- parent: {}
168
169
  }]
169
170
  }
170
171
  }