vedeu 0.6.4 → 0.6.5

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 (118) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +40 -0
  3. data/README.md +1 -0
  4. data/docs/dsl.md +24 -24
  5. data/lib/vedeu/all.rb +21 -44
  6. data/lib/vedeu/api.rb +13 -13
  7. data/lib/vedeu/application/application_controller.rb +2 -0
  8. data/lib/vedeu/bindings/movement.rb +53 -18
  9. data/lib/vedeu/bindings/refresh.rb +1 -1
  10. data/lib/vedeu/bindings/system.rb +2 -2
  11. data/lib/vedeu/bindings/visibility.rb +3 -3
  12. data/lib/vedeu/borders/all.rb +13 -0
  13. data/lib/vedeu/borders/border.rb +209 -202
  14. data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
  15. data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
  16. data/lib/vedeu/borders/render.rb +347 -0
  17. data/lib/vedeu/borders/repository.rb +19 -0
  18. data/lib/vedeu/buffers/all.rb +13 -0
  19. data/lib/vedeu/buffers/buffer.rb +182 -176
  20. data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
  21. data/lib/vedeu/buffers/repository.rb +24 -0
  22. data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
  23. data/lib/vedeu/cursors/all.rb +11 -0
  24. data/lib/vedeu/cursors/cursor.rb +276 -0
  25. data/lib/vedeu/cursors/refresh.rb +84 -0
  26. data/lib/vedeu/cursors/repository.rb +34 -0
  27. data/lib/vedeu/dsl/interface.rb +9 -9
  28. data/lib/vedeu/dsl/shared.rb +11 -11
  29. data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
  30. data/lib/vedeu/esc/esc.rb +1 -1
  31. data/lib/vedeu/geometry/all.rb +18 -0
  32. data/lib/vedeu/geometry/area.rb +170 -160
  33. data/lib/vedeu/geometry/coordinate.rb +61 -39
  34. data/lib/vedeu/geometry/dimension.rb +139 -132
  35. data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
  36. data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
  37. data/lib/vedeu/geometry/geometry.rb +310 -212
  38. data/lib/vedeu/geometry/grid.rb +73 -69
  39. data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
  40. data/lib/vedeu/geometry/position.rb +124 -120
  41. data/lib/vedeu/geometry/repository.rb +19 -0
  42. data/lib/vedeu/input/editor/document.rb +2 -2
  43. data/lib/vedeu/internal_api.rb +8 -8
  44. data/lib/vedeu/models/escape.rb +2 -2
  45. data/lib/vedeu/models/interface.rb +1 -1
  46. data/lib/vedeu/models/page.rb +89 -0
  47. data/lib/vedeu/models/row.rb +66 -0
  48. data/lib/vedeu/models/toggleable.rb +1 -1
  49. data/lib/vedeu/models/views/char.rb +7 -6
  50. data/lib/vedeu/models/views/line.rb +1 -1
  51. data/lib/vedeu/models/views/view.rb +2 -2
  52. data/lib/vedeu/options.rb +19 -0
  53. data/lib/vedeu/output/clear/named_interface.rb +1 -1
  54. data/lib/vedeu/output/direct.rb +1 -1
  55. data/lib/vedeu/output/presentation.rb +2 -1
  56. data/lib/vedeu/output/viewport.rb +3 -3
  57. data/lib/vedeu/repositories/model.rb +9 -1
  58. data/lib/vedeu/repositories/repository.rb +5 -0
  59. data/lib/vedeu/terminal/terminal.rb +3 -3
  60. data/lib/vedeu/version.rb +1 -1
  61. data/test/lib/vedeu/borders/border_test.rb +299 -291
  62. data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
  63. data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
  64. data/test/lib/vedeu/borders/render_test.rb +125 -0
  65. data/test/lib/vedeu/borders/repository_test.rb +17 -0
  66. data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
  67. data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
  68. data/test/lib/vedeu/buffers/repository_test.rb +18 -0
  69. data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
  70. data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
  71. data/test/lib/vedeu/cursors/repository_test.rb +41 -0
  72. data/test/lib/vedeu/dsl/interface_test.rb +5 -5
  73. data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
  74. data/test/lib/vedeu/geometry/area_test.rb +141 -137
  75. data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
  76. data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
  77. data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
  78. data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
  79. data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
  80. data/test/lib/vedeu/geometry/grid_test.rb +35 -31
  81. data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
  82. data/test/lib/vedeu/geometry/position_test.rb +146 -142
  83. data/test/lib/vedeu/geometry/repository_test.rb +19 -0
  84. data/test/lib/vedeu/input/editor/document_test.rb +1 -1
  85. data/test/lib/vedeu/models/escape_test.rb +1 -1
  86. data/test/lib/vedeu/models/interface_test.rb +2 -2
  87. data/test/lib/vedeu/models/page_test.rb +235 -0
  88. data/test/lib/vedeu/models/row_test.rb +111 -0
  89. data/test/lib/vedeu/models/views/char_test.rb +3 -3
  90. data/test/lib/vedeu/options_test.rb +57 -0
  91. data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
  92. data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
  93. data/test/lib/vedeu/output/viewport_test.rb +15 -9
  94. data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
  95. data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
  96. data/test/lib/vedeu/repositories/repository_test.rb +7 -0
  97. data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
  98. data/test/test_helper.rb +1 -1
  99. data/vedeu.gemspec +2 -2
  100. metadata +57 -63
  101. data/lib/vedeu/borders/borders.rb +0 -15
  102. data/lib/vedeu/borders/render_border.rb +0 -331
  103. data/lib/vedeu/buffers/buffers.rb +0 -20
  104. data/lib/vedeu/cursor/cursor.rb +0 -174
  105. data/lib/vedeu/cursor/cursors.rb +0 -30
  106. data/lib/vedeu/cursor/move.rb +0 -239
  107. data/lib/vedeu/cursor/reposition.rb +0 -78
  108. data/lib/vedeu/geometry/geometries.rb +0 -15
  109. data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
  110. data/test/lib/vedeu/borders/borders_test.rb +0 -13
  111. data/test/lib/vedeu/borders/render_border_test.rb +0 -121
  112. data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
  113. data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
  114. data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
  115. data/test/lib/vedeu/cursor/move_test.rb +0 -301
  116. data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
  117. data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
  118. data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -1,15 +0,0 @@
1
- module Vedeu
2
-
3
- # Allows the storing of interface/view borders independent of the interface
4
- # instance.
5
- #
6
- class Borders < Vedeu::Repository
7
-
8
- singleton_class.send(:alias_method, :borders, :repository)
9
-
10
- null Vedeu::Null::Border
11
- real Vedeu::Border
12
-
13
- end # Borders
14
-
15
- end # Vedeu
@@ -1,331 +0,0 @@
1
- module Vedeu
2
-
3
- # Renders the provided border.
4
- #
5
- class RenderBorder
6
-
7
- extend Forwardable
8
- include Vedeu::Common
9
-
10
- def_delegators :border,
11
- :bottom?,
12
- :bottom_left,
13
- :bottom_right,
14
- :bx,
15
- :bxn,
16
- :by,
17
- :byn,
18
- :caption,
19
- :colour,
20
- :enabled?,
21
- :height,
22
- :horizontal,
23
- :left?,
24
- :name,
25
- :right?,
26
- :style,
27
- :title,
28
- :top?,
29
- :top_left,
30
- :top_right,
31
- :width,
32
- :vertical
33
-
34
- def_delegators :geometry,
35
- :x,
36
- :xn,
37
- :y,
38
- :yn
39
-
40
- # @return [Array<Array<Vedeu::Views::Char>>]
41
- # @see Vedeu::RenderBorder#initialize
42
- def self.with(border)
43
- new(border).render
44
- end
45
-
46
- # Returns a new instance of Vedeu::RenderBorder.
47
- #
48
- # @param border [Vedeu::Border]
49
- # @return [Vedeu::RenderBorder]
50
- def initialize(border)
51
- @border = border
52
- end
53
-
54
- # @return [Array<Array<Vedeu::Views::Char>>]
55
- def render
56
- return [] unless enabled?
57
-
58
- Vedeu.timer("Bordering: '#{name}'") do
59
- out = [top, bottom]
60
-
61
- height.times { |y| out << [left(y), right(y)] }
62
-
63
- out.flatten
64
- end
65
- end
66
-
67
- protected
68
-
69
- # @!attribute [r] border
70
- # @return [Vedeu::Border]
71
- attr_reader :border
72
-
73
- private
74
-
75
- # @param value [String]
76
- # @param type [Symbol|NilClass]
77
- # @param iy [Fixnum]
78
- # @param ix [Fixnum]
79
- # @return [Vedeu::Views::Char]
80
- def build(value, type = :border, iy = 0, ix = 0)
81
- Vedeu::Views::Char.new(value: value,
82
- parent: interface,
83
- colour: colour,
84
- style: style,
85
- position: [iy, ix],
86
- border: type)
87
- end
88
-
89
- # @return [Vedeu::Views::Char]
90
- def build_bottom_left
91
- build(bottom_left, :bottom_left, yn, x) if left?
92
- end
93
-
94
- # @return [Vedeu::Views::Char]
95
- def build_bottom_right
96
- build(bottom_right, :bottom_right, yn, xn) if right?
97
- end
98
-
99
- # @return [Array<Vedeu::Views::Char>]
100
- def build_top
101
- build_horizontal(:bottom_horizontal, y)
102
- end
103
-
104
- # @return [Array<Vedeu::Views::Char>]
105
- def build_bottom
106
- build_horizontal(:bottom_horizontal, yn)
107
- end
108
-
109
- # @return [Vedeu::Views::Char]
110
- def build_top_left
111
- build(top_left, :top_left, y, x) if left?
112
- end
113
-
114
- # @return [Vedeu::Views::Char]
115
- def build_top_right
116
- build(top_right, :top_right, y, xn) if right?
117
- end
118
-
119
- # Renders the bottom border for the interface.
120
- #
121
- # @note
122
- # If a caption has been specified, then the bottom border will include
123
- # this caption unless the size of the interface is smaller than the padded
124
- # caption length.
125
- #
126
- # @return [String]
127
- def bottom
128
- return [] unless bottom?
129
-
130
- [build_bottom_left, captionbar, build_bottom_right].compact
131
- end
132
-
133
- # @return [Vedeu::Geometry]
134
- def geometry
135
- Vedeu.geometries.by_name(name)
136
- end
137
-
138
- # @param position [Symbol] Either :top_horizontal, or :bottom_horizontal.
139
- # @param y_coordinate [Fixnum] The value of either y or yn.
140
- # @return [Array<Vedeu::Views::Char>]
141
- def build_horizontal(position, y_coordinate)
142
- Array.new(width) do |ix|
143
- build(horizontal, position, y_coordinate, (bx + ix))
144
- end
145
- end
146
-
147
- # The parent of a border is always an interface.
148
- #
149
- # @return [Vedeu::Interface]
150
- def interface
151
- @interface ||= Vedeu.interfaces.by_name(name)
152
- end
153
- alias_method :parent, :interface
154
-
155
- # Renders the left border for the interface.
156
- #
157
- # @param iy [Fixnum]
158
- # @return [String]
159
- def left(iy = 0)
160
- return [] unless left?
161
-
162
- build(vertical, :left_vertical, (by + iy), x)
163
- end
164
-
165
- # Renders the right border for the interface.
166
- #
167
- # @param iy [Fixnum]
168
- # @return [String]
169
- def right(iy = 0)
170
- return [] unless right?
171
-
172
- build(vertical, :right_vertical, (by + iy), xn)
173
- end
174
-
175
- # Renders the top border for the interface.
176
- #
177
- # @note
178
- # If a title has been specified, then the top border will include this
179
- # title unless the size of the interface is smaller than the padded title
180
- # length.
181
- #
182
- # @return [String]
183
- def top
184
- return [] unless top?
185
-
186
- [build_top_left, titlebar, build_top_right].compact
187
- end
188
-
189
- # Overwrite the border from {#build_horizontal} on the bottom border to
190
- # include the caption if given.
191
- #
192
- # @return [Array<Vedeu::Views::Char>]
193
- def captionbar
194
- return build_bottom unless caption? && caption_fits?
195
-
196
- caption_starts_at = (width - caption_characters.size) - 2
197
-
198
- caption_char = 0
199
- build_bottom.each_with_index do |char, index|
200
- next if index <= caption_starts_at || index > (width - 2)
201
-
202
- char.border = nil
203
- char.value = caption_characters[caption_char]
204
- caption_char += 1
205
- end
206
- end
207
-
208
- # Overwrite the border from {#build_horizontal} on the top border to
209
- # include the title if given.
210
- #
211
- # @return [Array<Vedeu::Views::Char>]
212
- def titlebar
213
- return build_top unless title? && title_fits?
214
-
215
- build_top.each_with_index do |char, index|
216
- next if index == 0 || index > title_characters.size
217
-
218
- char.border = nil
219
- char.value = title_characters[(index - 1)]
220
- end
221
- end
222
-
223
- # Return boolean indicating whether this border has a non-empty title.
224
- #
225
- # @return [Boolean]
226
- def title?
227
- present?(title)
228
- end
229
-
230
- # Return boolean indicating whether this border has a non-empty caption.
231
- #
232
- # @return [Boolean]
233
- def caption?
234
- present?(caption)
235
- end
236
-
237
- # Return boolean indicating whether the title fits within the width of the
238
- # top border.
239
- #
240
- # @return [Boolean]
241
- def title_fits?
242
- width > title_characters.size
243
- end
244
-
245
- # Return boolean indicating whether the caption fits within the width of the
246
- # bottom border.
247
- #
248
- # @return [Boolean]
249
- def caption_fits?
250
- width > caption_characters.size
251
- end
252
-
253
- # @return [Array<String>]
254
- def title_characters
255
- @title_characters ||= title_padded.chars
256
- end
257
-
258
- # @return [Array<String>]
259
- def caption_characters
260
- @caption_characters ||= caption_padded.chars
261
- end
262
-
263
- # Pads the title with a single whitespace either side.
264
- #
265
- # @example
266
- # title = 'Truncated!'
267
- # width = 20
268
- # # => ' Truncated! '
269
- #
270
- # width = 10
271
- # # => ' Trunca '
272
- #
273
- # @return [String]
274
- # @see #truncated_title
275
- def title_padded
276
- truncated_title.center(truncated_title.size + 2)
277
- end
278
-
279
- # Pads the caption with a single whitespace either side.
280
- #
281
- # @example
282
- # caption = 'Truncated!'
283
- # width = 20
284
- # # => ' Truncated! '
285
- #
286
- # width = 10
287
- # # => ' Trunca '
288
- #
289
- # @return [String]
290
- # @see #truncated_caption
291
- def caption_padded
292
- truncated_caption.center(truncated_caption.size + 2)
293
- end
294
-
295
- # Truncates the title to the width of the interface, minus characters needed
296
- # to ensure there is at least a single character of horizontal border and a
297
- # whitespace on either side of the title.
298
- #
299
- # @example
300
- # title = 'Truncated!'
301
- # width = 20
302
- # # => 'Truncated!'
303
- #
304
- # width = 10
305
- # # => 'Trunca'
306
- #
307
- # @return [String]
308
- def truncated_title
309
- title.chomp.slice(0..(width - 5))
310
- end
311
-
312
- # Truncates the caption to the width of the interface, minus characters
313
- # needed to ensure there is at least a single character of horizontal border
314
- # and a whitespace on either side of the caption.
315
- #
316
- # @example
317
- # caption = 'Truncated!'
318
- # width = 20
319
- # # => 'Truncated!'
320
- #
321
- # width = 10
322
- # # => 'Trunca'
323
- #
324
- # @return [String]
325
- def truncated_caption
326
- caption.chomp.slice(0..(width - 5))
327
- end
328
-
329
- end # RenderBorder
330
-
331
- end # Vedeu
@@ -1,20 +0,0 @@
1
- module Vedeu
2
-
3
- # Allows the storing of view buffers.
4
- #
5
- class Buffers < Vedeu::Repository
6
-
7
- singleton_class.send(:alias_method, :buffers, :repository)
8
-
9
- null Vedeu::Null::Buffer
10
- real Vedeu::Buffer
11
-
12
- end # Buffers
13
-
14
- class Buffer
15
-
16
- repo Vedeu::Buffers.repository
17
-
18
- end # Buffer
19
-
20
- end # Vedeu
@@ -1,174 +0,0 @@
1
- module Vedeu
2
-
3
- # Each interface has its own Cursor which maintains the position and
4
- # visibility of the cursor within that interface.
5
- #
6
- class Cursor
7
-
8
- include Vedeu::Model
9
- include Vedeu::Toggleable
10
- extend Forwardable
11
-
12
- def_delegators :border,
13
- :bx,
14
- :bxn,
15
- :by,
16
- :byn
17
-
18
- # @!attribute [r] attributes
19
- # @return [Hash]
20
- attr_reader :attributes
21
-
22
- # @!attribute [r] name
23
- # @return [String]
24
- attr_reader :name
25
-
26
- # @!attribute [rw] ox
27
- # @return [Fixnum]
28
- attr_accessor :ox
29
-
30
- # @!attribute [rw] oy
31
- # @return [Fixnum]
32
- attr_accessor :oy
33
-
34
- # @!attribute [r] state
35
- # @return [Boolean|Symbol]
36
- attr_reader :state
37
-
38
- # @!attribute [w] x
39
- # @return [Fixnum]
40
- attr_writer :x
41
-
42
- # @!attribute [sw] y
43
- # @return [Fixnum]
44
- attr_writer :y
45
-
46
- # Returns a new instance of Vedeu::Cursor.
47
- #
48
- # @param attributes [Hash]
49
- # @option attributes name [String] The name of the interface this cursor
50
- # belongs to.
51
- # @option attributes ox [Fixnum] The offset x coordinate.
52
- # @option attributes oy [Fixnum] The offset y coordinate.
53
- # @option attributes repository [Vedeu::Repository]
54
- # @option attributes visible [Boolean] The visibility of the cursor.
55
- # @option attributes x [Fixnum] The terminal x coordinate for the cursor.
56
- # @option attributes y [Fixnum] The terminal y coordinate for the cursor.
57
- #
58
- # @return [Vedeu::Cursor]
59
- def initialize(attributes = {})
60
- @attributes = defaults.merge!(attributes)
61
-
62
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
63
- end
64
-
65
- # Renders the cursor.
66
- #
67
- # @return [Array<Vedeu::Escape>]
68
- def render
69
- Vedeu::Output.render(visibility)
70
- end
71
-
72
- # Returns an escape sequence to position the cursor and set its visibility.
73
- # When passed a block, will position the cursor, yield and return the
74
- # original position.
75
- #
76
- # @return [String]
77
- def to_s
78
- if block_given?
79
- "#{position}#{yield}#{visibility}"
80
-
81
- else
82
- "#{visibility}"
83
-
84
- end
85
- end
86
- alias_method :to_str, :to_s
87
-
88
- # Hide a named cursor, or without a name, the cursor of the currently
89
- # focussed interface.
90
- #
91
- # @example
92
- # Vedeu.hide_cursor(name)
93
- #
94
- # @return [Vedeu::Escape]
95
- def hide
96
- super
97
-
98
- render
99
- end
100
-
101
- # Return the position of this cursor.
102
- #
103
- # @return [Vedeu::Position]
104
- def position
105
- @position = Vedeu::Position[y, x]
106
- end
107
-
108
- # Show a named cursor, or without a name, the cursor of the currently
109
- # focussed interface.
110
- #
111
- # @example
112
- # Vedeu.show_cursor(name)
113
- #
114
- # @return [Vedeu::Escape]
115
- def show
116
- super
117
-
118
- render
119
- end
120
-
121
- # @return [Fixnum] The column/character coordinate.
122
- def x
123
- @x = bx if @x < bx
124
- @x = bxn if @x > bxn
125
-
126
- @attributes[:x] = @x
127
-
128
- @x
129
- end
130
-
131
- # @return [Fixnum] The row/line coordinate.
132
- def y
133
- @y = by if @y < by
134
- @y = byn if @y > byn
135
-
136
- @attributes[:y] = @y
137
-
138
- @y
139
- end
140
-
141
- private
142
-
143
- # @see Vedeu::Borders#by_name
144
- def border
145
- @border ||= Vedeu.borders.by_name(name)
146
- end
147
-
148
- # The default values for a new instance of this class.
149
- #
150
- # @return [Hash]
151
- def defaults
152
- {
153
- name: '',
154
- ox: 0,
155
- oy: 0,
156
- repository: Vedeu.cursors,
157
- visible: false,
158
- x: 1,
159
- y: 1,
160
- }
161
- end
162
-
163
- # Returns the escape sequence for setting the visibility of the cursor.
164
- #
165
- # @return [String]
166
- def visibility
167
- value = visible? ? Vedeu::Esc.show_cursor : Vedeu::Esc.hide_cursor
168
-
169
- Vedeu::Escape.new(position: position, value: value)
170
- end
171
-
172
- end # Cursor
173
-
174
- end # Vedeu