vedeu 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -0,0 +1,24 @@
1
+ module Vedeu
2
+
3
+ module Buffers
4
+
5
+ # Allows the storing of view buffers.
6
+ #
7
+ class Repository < Vedeu::Repository
8
+
9
+ singleton_class.send(:alias_method, :buffers, :repository)
10
+
11
+ null Vedeu::Buffers::Null
12
+ real Vedeu::Buffers::Buffer
13
+
14
+ end # Buffers
15
+
16
+ class Buffer
17
+
18
+ repo Vedeu::Buffers::Repository.repository
19
+
20
+ end # Buffer
21
+
22
+ end # Buffers
23
+
24
+ end # Vedeu
@@ -55,7 +55,7 @@ module Vedeu
55
55
  # @param x [Fixnum] The column/character coordinate.
56
56
  # @return [Vedeu::Views::Char]
57
57
  def read(y, x)
58
- cy, cx = Vedeu::Position[y, x].as_indices
58
+ cy, cx = Vedeu::Geometry::Position[y, x].as_indices
59
59
 
60
60
  row = fetch(cells, cy)
61
61
  cell = fetch(row, cx)
@@ -103,7 +103,7 @@ module Vedeu
103
103
  def write(y, x, data)
104
104
  return false unless read(y, x).is_a?(Vedeu::Cell)
105
105
 
106
- cy, cx = Vedeu::Position[y, x].as_indices
106
+ cy, cx = Vedeu::Geometry::Position[y, x].as_indices
107
107
  cells[cy][cx] = data
108
108
 
109
109
  true
@@ -0,0 +1,11 @@
1
+ module Vedeu
2
+
3
+ module Cursors
4
+
5
+ end # Cursors
6
+
7
+ end # Vedeu
8
+
9
+ require 'vedeu/cursors/cursor'
10
+ require 'vedeu/cursors/refresh'
11
+ require 'vedeu/cursors/repository'
@@ -0,0 +1,276 @@
1
+ module Vedeu
2
+
3
+ module Cursors
4
+
5
+ # Each interface has its own Cursor which maintains the position and
6
+ # visibility of the cursor within that interface.
7
+ #
8
+ class Cursor
9
+
10
+ include Vedeu::Model
11
+ include Vedeu::Toggleable
12
+ extend Forwardable
13
+
14
+ def_delegators :border,
15
+ :bx,
16
+ :bxn,
17
+ :by,
18
+ :byn
19
+
20
+ # @!attribute [r] attributes
21
+ # @return [Hash]
22
+ attr_reader :attributes
23
+
24
+ # @!attribute [r] name
25
+ # @return [String]
26
+ attr_reader :name
27
+
28
+ # @!attribute [w] ox
29
+ # @return [Fixnum]
30
+ attr_writer :ox
31
+
32
+ # @!attribute [w] oy
33
+ # @return [Fixnum]
34
+ attr_writer :oy
35
+
36
+ # @!attribute [r] state
37
+ # @return [Boolean|Symbol]
38
+ attr_reader :state
39
+
40
+ # @!attribute [w] x
41
+ # @return [Fixnum]
42
+ attr_writer :x
43
+
44
+ # @!attribute [w] y
45
+ # @return [Fixnum]
46
+ attr_writer :y
47
+
48
+ # Returns a new instance of Vedeu::Cursors::Cursor.
49
+ #
50
+ # @param attributes [Hash]
51
+ # @option attributes name [String] The name of the interface this cursor
52
+ # belongs to.
53
+ # @option attributes ox [Fixnum] The offset x coordinate.
54
+ # @option attributes oy [Fixnum] The offset y coordinate.
55
+ # @option attributes repository [Vedeu::Repository]
56
+ # @option attributes visible [Boolean] The visibility of the cursor.
57
+ # @option attributes x [Fixnum] The terminal x coordinate for the cursor.
58
+ # @option attributes y [Fixnum] The terminal y coordinate for the cursor.
59
+ #
60
+ # @return [Vedeu::Cursors::Cursor]
61
+ def initialize(attributes = {})
62
+ @attributes = defaults.merge!(attributes)
63
+
64
+ @attributes.each do |key, value|
65
+ instance_variable_set("@#{key}", value)
66
+ end
67
+ end
68
+
69
+ # Moves the cursor down by one row.
70
+ #
71
+ # @return [Vedeu::Cursors::Cursor]
72
+ def move_down
73
+ @oy = @oy + 1
74
+
75
+ @attributes = attributes.merge!(x: x,
76
+ y: coordinate.y_position,
77
+ ox: ox,
78
+ oy: oy)
79
+
80
+ Vedeu::Cursors::Cursor.new(@attributes).store
81
+ end
82
+
83
+ # Moves the cursor left by one column.
84
+ #
85
+ # @return [Vedeu::Cursors::Cursor]
86
+ def move_left
87
+ @ox = @ox - 1
88
+
89
+ @attributes = attributes.merge!(x: coordinate.x_position,
90
+ y: y,
91
+ ox: ox,
92
+ oy: oy)
93
+
94
+ Vedeu::Cursors::Cursor.new(@attributes).store
95
+ end
96
+
97
+ # Moves the cursor to the top left of the named interface.
98
+ #
99
+ # @return [Vedeu::Cursors::Cursor]
100
+ def move_origin
101
+ @attributes = attributes.merge!(x: bx, y: by, ox: 0, oy: 0)
102
+
103
+ Vedeu::Cursors::Cursor.new(@attributes).store
104
+ end
105
+
106
+ # Moves the cursor right by one column.
107
+ #
108
+ # @return [Vedeu::Cursors::Cursor]
109
+ def move_right
110
+ @ox = @ox + 1
111
+
112
+ @attributes = attributes.merge!(x: coordinate.x_position,
113
+ y: y,
114
+ ox: ox,
115
+ oy: oy)
116
+
117
+ Vedeu::Cursors::Cursor.new(@attributes).store
118
+ end
119
+
120
+ # Moves the cursor up by one row.
121
+ #
122
+ # @return [Vedeu::Cursors::Cursor]
123
+ def move_up
124
+ @oy = @oy - 1
125
+
126
+ @attributes = attributes.merge!(x: x,
127
+ y: coordinate.y_position,
128
+ ox: ox,
129
+ oy: oy)
130
+
131
+ Vedeu::Cursors::Cursor.new(@attributes).store
132
+ end
133
+
134
+ # Renders the cursor.
135
+ #
136
+ # @return [Array<Vedeu::Escape>]
137
+ def render
138
+ Vedeu::Output.render(visibility)
139
+ end
140
+
141
+ # Arbitrarily move the cursor to a given position.
142
+ #
143
+ # @param new_y [Fixnum] The row/line position.
144
+ # @param new_x [Fixnum] The column/character position.
145
+ # @return [Vedeu::Cursors::Cursor]
146
+ def reposition(new_y, new_x)
147
+ @attributes = attributes.merge!(x: coordinate.x_position,
148
+ y: coordinate.y_position,
149
+ ox: new_x,
150
+ oy: new_y)
151
+
152
+ Vedeu::Cursors::Cursor.new(@attributes).store
153
+ end
154
+
155
+ # Returns an escape sequence to position the cursor and set its
156
+ # visibility. When passed a block, will position the cursor, yield and
157
+ # return the original position.
158
+ #
159
+ # @return [String]
160
+ def to_s
161
+ if block_given?
162
+ "#{position}#{yield}#{visibility}"
163
+
164
+ else
165
+ "#{visibility}"
166
+
167
+ end
168
+ end
169
+ alias_method :to_str, :to_s
170
+
171
+ # Hide a named cursor, or without a name, the cursor of the currently
172
+ # focussed interface.
173
+ #
174
+ # @example
175
+ # Vedeu.hide_cursor(name)
176
+ #
177
+ # @return [Vedeu::Escape]
178
+ def hide
179
+ super
180
+
181
+ render
182
+ end
183
+
184
+ # @return [Fixnum]
185
+ def ox
186
+ @ox = 0 if @ox < 0
187
+ @ox
188
+ end
189
+
190
+ # @return [Fixnum]
191
+ def oy
192
+ @oy = 0 if @oy < 0
193
+ @oy
194
+ end
195
+
196
+ # Return the position of this cursor.
197
+ #
198
+ # @return [Vedeu::Geometry::Position]
199
+ def position
200
+ @position = Vedeu::Geometry::Position[y, x]
201
+ end
202
+
203
+ # Show a named cursor, or without a name, the cursor of the currently
204
+ # focussed interface.
205
+ #
206
+ # @example
207
+ # Vedeu.show_cursor(name)
208
+ #
209
+ # @return [Vedeu::Escape]
210
+ def show
211
+ super
212
+
213
+ render
214
+ end
215
+
216
+ # @return [Fixnum] The column/character coordinate.
217
+ def x
218
+ @x = bx if @x < bx
219
+ @x = bxn if @x > bxn
220
+
221
+ @attributes[:x] = @x
222
+
223
+ @x
224
+ end
225
+
226
+ # @return [Fixnum] The row/line coordinate.
227
+ def y
228
+ @y = by if @y < by
229
+ @y = byn if @y > byn
230
+
231
+ @attributes[:y] = @y
232
+
233
+ @y
234
+ end
235
+
236
+ private
237
+
238
+ # @see Vedeu::Borders::Repository#by_name
239
+ def border
240
+ @border ||= Vedeu.borders.by_name(name)
241
+ end
242
+
243
+ # @return [Vedeu::Geometry::Coordinate]
244
+ def coordinate
245
+ @coordinate ||= Vedeu::Geometry::Coordinate.new(name, oy, ox)
246
+ end
247
+
248
+ # The default values for a new instance of this class.
249
+ #
250
+ # @return [Hash]
251
+ def defaults
252
+ {
253
+ name: '',
254
+ ox: 0,
255
+ oy: 0,
256
+ repository: Vedeu.cursors,
257
+ visible: false,
258
+ x: 1,
259
+ y: 1,
260
+ }
261
+ end
262
+
263
+ # Returns the escape sequence for setting the visibility of the cursor.
264
+ #
265
+ # @return [String]
266
+ def visibility
267
+ value = visible? ? Vedeu::Esc.show_cursor : Vedeu::Esc.hide_cursor
268
+
269
+ Vedeu::Escape.new(position: position, value: value)
270
+ end
271
+
272
+ end # Cursor
273
+
274
+ end # Cursors
275
+
276
+ end # Vedeu
@@ -0,0 +1,84 @@
1
+ module Vedeu
2
+
3
+ module Cursors
4
+
5
+ # Handle the refreshing (redrawing) of a cursor, without redrawing the whole
6
+ # interface; unless the cursor's offset has caused the view to change.
7
+ #
8
+ class Refresh
9
+
10
+ extend Forwardable
11
+
12
+ def_delegators :border,
13
+ :height,
14
+ :width
15
+
16
+ # @param (see #initialize)
17
+ def self.by_name(name = Vedeu.focus)
18
+ new(name).by_name
19
+ end
20
+
21
+ # Returns a new instance of Vedeu::Cursors::Refresh.
22
+ #
23
+ # @param name [String] The name of the cursor.
24
+ # @return [Vedeu::Cursors::Refresh]
25
+ def initialize(name)
26
+ @name = name
27
+ end
28
+
29
+ # Renders the cursor in the terminal. If the cursor's x or y offsets are
30
+ # greater or equal to the interface's width or height respectively, then
31
+ # the view is also refreshed, causing the content to be offset also.
32
+ #
33
+ # @return [Array]
34
+ def by_name
35
+ Vedeu.log(type: :info, message: "Refreshing cursor: '#{name}'")
36
+
37
+ Vedeu.trigger(:_refresh_, name) if refresh_view?
38
+
39
+ Vedeu::Terminal.output(cursor.to_s)
40
+ end
41
+
42
+ protected
43
+
44
+ # @!attribute [r] name
45
+ # @return [String]
46
+ attr_reader :name
47
+
48
+ private
49
+
50
+ # Returns true when the view should be refreshed. This is determined by
51
+ # checking that the offsets for x and y are outside the width and height
52
+ # of the named interface.
53
+ #
54
+ # @return [Boolean]
55
+ def refresh_view?
56
+ cursor.ox >= width || cursor.oy >= height
57
+ end
58
+
59
+ # @return [Vedeu::Cursors::Cursor]
60
+ # @see Vedeu::Cursors::Repository#by_name
61
+ def cursor
62
+ @cursor ||= Vedeu.cursors.by_name(name)
63
+ end
64
+
65
+ # Fetch the border by name.
66
+ #
67
+ # @note
68
+ # Vedeu::Borders::Border is used in this way because when there is not a
69
+ # border defined, it will fallback to a Vedeu::Borders::Null which uses
70
+ # Vedeu::Geometry::Geometry to determine it's dimensions based on the
71
+ # name also. When a Vedeu::Geometry::Geometry cannot be found, this
72
+ # falls back to a Vedeu::Geometry::Null which uses the dimensions of the
73
+ # current terminal.
74
+ #
75
+ # @return (see Vedeu::Borders::Repository#by_name)
76
+ def border
77
+ @border ||= Vedeu.borders.by_name(name)
78
+ end
79
+
80
+ end # Refresh
81
+
82
+ end # Cursors
83
+
84
+ end # Vedeu
@@ -0,0 +1,34 @@
1
+ module Vedeu
2
+
3
+ module Cursors
4
+
5
+ # Allows the storing of each interface's cursor.
6
+ #
7
+ class Repository < Vedeu::Repository
8
+
9
+ singleton_class.send(:alias_method, :cursors, :repository)
10
+
11
+ class << self
12
+
13
+ # @return [Vedeu::Cursors::Cursor]
14
+ # @see Vedeu::API.cursor
15
+ def cursor
16
+ cursors.by_name(Vedeu.focus) if Vedeu.focus
17
+ end
18
+
19
+ end # Eigenclass
20
+
21
+ null Vedeu::Cursors::Cursor
22
+ real Vedeu::Cursors::Cursor
23
+
24
+ end # Repository
25
+
26
+ class Cursor
27
+
28
+ repo Vedeu::Cursors::Repository.repository
29
+
30
+ end # Cursor
31
+
32
+ end # Cursors
33
+
34
+ end # Vedeu