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
@@ -1,172 +1,178 @@
1
1
  module Vedeu
2
2
 
3
- # Crudely corrects out of range values.
4
- #
5
- class GenericCoordinate
3
+ module Geometry
6
4
 
7
- # Return a new instance of Vedeu::GenericCoordinate.
5
+ # Crudely corrects out of range values.
8
6
  #
9
- # @param attributes [Hash]
10
- # @option attributes name [String]
11
- # @option attributes type [Symbol]
12
- # @option attributes offset [Fixnum]
13
- # @return [Vedeu::GenericCoordinate]
14
- def initialize(attributes = {})
15
- @attributes = defaults.merge!(attributes)
16
-
17
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
18
- end
19
-
20
- # Returns the maximum coordinate for an area.
21
- #
22
- # @example
23
- # # d = 2
24
- # # d_dn = 4
25
- # dn # => 6
26
- #
27
- # @return [Fixnum]
28
- def dn
29
- if d_dn <= 0
30
- 0
7
+ class GenericCoordinate
8
+
9
+ # Return a new instance of Vedeu::Geometry::GenericCoordinate.
10
+ #
11
+ # @param attributes [Hash]
12
+ # @option attributes name [String]
13
+ # @option attributes type [Symbol]
14
+ # @option attributes offset [Fixnum]
15
+ # @return [Vedeu::Geometry::GenericCoordinate]
16
+ def initialize(attributes = {})
17
+ @attributes = defaults.merge!(attributes)
18
+
19
+ @attributes.each do |key, value|
20
+ instance_variable_set("@#{key}", value)
21
+ end
22
+ end
23
+
24
+ # Returns the maximum coordinate for an area.
25
+ #
26
+ # @example
27
+ # # d = 2
28
+ # # d_dn = 4 # represents width or height
29
+ # dn # => 6
30
+ #
31
+ # @return [Fixnum]
32
+ def dn
33
+ if d_dn <= 0
34
+ 0
35
+
36
+ else
37
+ d + d_dn
38
+
39
+ end
40
+ end
41
+ alias_method :xn, :dn
42
+ alias_method :yn, :dn
43
+
44
+ # Returns the coordinate for a given index.
45
+ #
46
+ # @example
47
+ # # d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
48
+ # position # => 4
49
+ # position(-2) # => 4
50
+ # position(2) # => 6
51
+ # position(15) # => 13
52
+ #
53
+ # @return [Fixnum]
54
+ def position
55
+ pos = case
56
+ when offset <= 0 then d
57
+ when offset > dn_index then dn
58
+ else
59
+ d_range[offset]
60
+ end
61
+
62
+ pos = pos < bd ? bd : pos
63
+ pos = pos > bdn ? bdn : pos
64
+ pos
65
+ end
66
+ alias_method :x_position, :position
67
+ alias_method :y_position, :position
68
+
69
+ protected
70
+
71
+ # @!attribute [r] name
72
+ # @return [String]
73
+ attr_reader :name
31
74
 
32
- else
33
- d + d_dn
75
+ # @!attribute [r] offset
76
+ # @return [Fixnum]
77
+ attr_reader :offset
34
78
 
79
+ # @!attribute [r] type
80
+ # @return [Symbol]
81
+ attr_reader :type
82
+
83
+ private
84
+
85
+ # @see Vedeu::Borders::Repository#by_name
86
+ def border
87
+ @border ||= Vedeu.borders.by_name(name)
35
88
  end
36
- end
37
- alias_method :xn, :dn
38
- alias_method :yn, :dn
39
89
 
40
- # Returns the coordinate for a given index.
41
- #
42
- # @example
43
- # # d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
44
- # position # => 4
45
- # position(-2) # => 4
46
- # position(2) # => 6
47
- # position(15) # => 13
48
- #
49
- # @return [Fixnum]
50
- def position
51
- pos = case
52
- when offset <= 0 then d
53
- when offset > dn_index then dn
54
- else
55
- d_range[offset]
56
- end
57
-
58
- pos = pos < bd ? bd : pos
59
- pos = pos > bdn ? bdn : pos
60
- pos
61
- end
62
- alias_method :x_position, :position
63
- alias_method :y_position, :position
64
-
65
- protected
66
-
67
- # @!attribute [r] name
68
- # @return [String]
69
- attr_reader :name
70
-
71
- # @!attribute [r] offset
72
- # @return [Fixnum]
73
- attr_reader :offset
74
-
75
- # @!attribute [r] type
76
- # @return [Symbol]
77
- attr_reader :type
78
-
79
- private
80
-
81
- # @see Vedeu::Borders#by_name
82
- def border
83
- @border ||= Vedeu.borders.by_name(name)
84
- end
85
-
86
- # Return the :x or :y value from the border.
87
- #
88
- # @return [Fixnum]
89
- def d
90
- border.send(coordinate_type[0])
91
- end
90
+ # Return the :x or :y value from the border.
91
+ #
92
+ # @return [Fixnum]
93
+ def d
94
+ border.send(coordinate_type[0])
95
+ end
92
96
 
93
- # Return the :bx or :by value from the border.
94
- #
95
- # @return [Fixnum]
96
- def bd
97
- border.send(coordinate_type[1])
98
- end
97
+ # Return the :bx or :by value from the border.
98
+ #
99
+ # @return [Fixnum]
100
+ def bd
101
+ border.send(coordinate_type[1])
102
+ end
99
103
 
100
- # Return the :bxn or :byn value from the border.
101
- #
102
- # @return [Fixnum]
103
- def bdn
104
- border.send(coordinate_type[2])
105
- end
104
+ # Return the :bxn or :byn value from the border.
105
+ #
106
+ # @return [Fixnum]
107
+ def bdn
108
+ border.send(coordinate_type[2])
109
+ end
106
110
 
107
- # Return the :width or :height value from the border.
108
- #
109
- # @return [Fixnum]
110
- def d_dn
111
- border.send(coordinate_type[3])
112
- end
111
+ # Return the :width or :height value from the border.
112
+ #
113
+ # @return [Fixnum]
114
+ def d_dn
115
+ border.send(coordinate_type[3])
116
+ end
113
117
 
114
- # Ascertain the correct methods to use for determining the coordinates.
115
- #
116
- # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type is not
117
- # given.
118
- # @return [Fixnum]
119
- def coordinate_type
120
- @_type ||= case type
121
- when :x then [:x, :bx, :bxn, :width]
122
- when :y then [:y, :by, :byn, :height]
123
- else
124
- fail Vedeu::Error::InvalidSyntax,
125
- 'Coordinate type not given, cannot continue.'
126
- end
127
- end
128
-
129
- # Returns the maximum index for an area.
130
- #
131
- # @example
132
- # # d_dn = 3
133
- # dn_index # => 2
134
- #
135
- # @return [Fixnum]
136
- def dn_index
137
- if d_dn < 1
138
- 0
118
+ # Ascertain the correct methods to use for determining the coordinates.
119
+ #
120
+ # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type is not
121
+ # given.
122
+ # @return [Fixnum]
123
+ def coordinate_type
124
+ @_type ||= case type
125
+ when :x then [:x, :bx, :bxn, :width]
126
+ when :y then [:y, :by, :byn, :height]
127
+ else
128
+ fail Vedeu::Error::InvalidSyntax,
129
+ 'Coordinate type not given, cannot continue.'
130
+ end
131
+ end
139
132
 
140
- else
141
- d_dn - 1
133
+ # Returns the maximum index for an area.
134
+ #
135
+ # @example
136
+ # # d_dn = 3
137
+ # dn_index # => 2
138
+ #
139
+ # @return [Fixnum]
140
+ def dn_index
141
+ if d_dn < 1
142
+ 0
143
+
144
+ else
145
+ d_dn - 1
146
+
147
+ end
148
+ end
142
149
 
150
+ # Returns an array with all coordinates from d to dn.
151
+ #
152
+ # @example
153
+ # # d_dn = 10
154
+ # # d = 4
155
+ # # dn = 14
156
+ # d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
157
+ #
158
+ # @return [Array]
159
+ def d_range
160
+ (d...dn).to_a
143
161
  end
144
- end
145
162
 
146
- # Returns an array with all coordinates from d to dn.
147
- #
148
- # @example
149
- # # d_dn = 10
150
- # # d = 4
151
- # # dn = 14
152
- # d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
153
- #
154
- # @return [Array]
155
- def d_range
156
- (d...dn).to_a
157
- end
163
+ # The default values for a new instance of this class.
164
+ #
165
+ # @return [Hash]
166
+ def defaults
167
+ {
168
+ name: '',
169
+ offset: nil,
170
+ type: :x,
171
+ }
172
+ end
158
173
 
159
- # The default values for a new instance of this class.
160
- #
161
- # @return [Hash]
162
- def defaults
163
- {
164
- name: '',
165
- offset: nil,
166
- type: :x,
167
- }
168
- end
169
-
170
- end # GenericCoordinate
174
+ end # GenericCoordinate
175
+
176
+ end # Geometry
171
177
 
172
178
  end # Vedeu
@@ -1,220 +1,318 @@
1
1
  module Vedeu
2
2
 
3
- # @todo Consider storing the Terminal size at the time of first creation,
4
- # this allows us to return the interface to its original dimensions if
5
- # the terminal resizes back to normal size.
6
- #
7
- # Calculates and provides interface geometry determined by both the client's
8
- # requirements and the terminal's current viewing area.
9
- #
10
- class Geometry
11
-
12
- extend Forwardable
13
- include Vedeu::Model
14
-
15
- def_delegators :area,
16
- :north,
17
- :east,
18
- :south,
19
- :west,
20
- :top,
21
- :right,
22
- :bottom,
23
- :left,
24
- :y,
25
- :xn,
26
- :yn,
27
- :x,
28
- :height,
29
- :width
30
-
31
- # @!attribute [rw] centred
32
- # @return [Boolean]
33
- attr_accessor :centred
34
-
35
- # @!attribute [rw] name
36
- # @return [String]
37
- attr_accessor :name
38
-
39
- # @!attribute [r] attributes
40
- # @return [Hash]
41
- attr_reader :attributes
42
-
43
- # @!attribute [w] height
44
- # @return [Fixnum]
45
- attr_writer :height
46
-
47
- # @!attribute [rw] maximised
48
- # @return [Boolean]
49
- attr_accessor :maximised
50
- alias_method :maximised?, :maximised
51
-
52
- # @!attribute [w] width
53
- # @return [Fixnum]
54
- attr_writer :width
55
-
56
- # @!attribute [w] x
57
- # @return [Fixnum]
58
- attr_writer :x
59
-
60
- # @!attribute [w] xn
61
- # @return [Fixnum]
62
- attr_writer :xn
63
-
64
- # @!attribute [w] y
65
- # @return [Fixnum]
66
- attr_writer :y
67
-
68
- # @!attribute [w] yn
69
- # @return [Fixnum]
70
- attr_writer :yn
71
-
72
- # Returns a new instance of Vedeu::Geometry.
73
- #
74
- # @param attributes [Hash]
75
- # @option attributes centred [Boolean]
76
- # @option attributes maximised [Boolean]
77
- # @option attributes height [Fixnum]
78
- # @option attributes name [String]
79
- # @option attributes repository [Vedeu::Geometries]
80
- # @option attributes width [Fixnum]
81
- # @option attributes x [Fixnum]
82
- # @option attributes xn [Fixnum]
83
- # @option attributes y [Fixnum]
84
- # @option attributes yn [Fixnum]
85
- # @return [Vedeu::Geometry]
86
- def initialize(attributes = {})
87
- @attributes = defaults.merge!(attributes)
88
-
89
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
90
- end
91
-
92
- # Will maximise the named interface geometry. This means it will occupy all
93
- # of the available space on the terminal window.
94
- #
95
- # @example
96
- # Vedeu.trigger(:_maximise_, name)
97
- #
98
- # @return [Vedeu::Geometry|NilClass]
99
- def maximise
100
- return self if maximised?
101
-
102
- Vedeu.trigger(:_clear_)
103
-
104
- @maximised = true
105
-
106
- work = store
107
-
108
- Vedeu.trigger(:_refresh_, name)
109
-
110
- work
111
- end
112
-
113
- # Will unmaximise the named interface geometry. Previously, when a geometry
114
- # was maximised, then triggering the unmaximise event will return it to its
115
- # usual defined size (terminal size permitting: when the terminal has been
116
- # resized, then the new geometry size should adapt).
117
- #
118
- # @example
119
- # Vedeu.trigger(:_unmaximise_, name)
120
- #
121
- # @return [Vedeu::Geometry|NilClass]
122
- def unmaximise
123
- return self unless maximised?
124
-
125
- Vedeu.trigger(:_clear_)
126
-
127
- @maximised = false
128
-
129
- work = store
130
-
131
- Vedeu.trigger(:_refresh_)
3
+ module Geometry
132
4
 
133
- work
134
- end
135
-
136
- private
137
-
138
- # @return [Vedeu::Area]
139
- def area
140
- @area = Vedeu::Area.from_attributes(area_attributes)
141
- end
142
-
143
- # @return [Hash<Symbol => Fixnum, Boolean>]
144
- def area_attributes
145
- {
146
- y: _y,
147
- yn: _yn,
148
- y_yn: _height,
149
- y_default: Vedeu.height,
150
- x: _x,
151
- xn: _xn,
152
- x_xn: _width,
153
- x_default: Vedeu.width,
154
- centred: centred,
155
- maximised: maximised,
156
- }
157
- end
158
-
159
- # Returns the row/line start position for the interface.
160
- #
161
- # @return [Fixnum]
162
- def _y
163
- @y.is_a?(Proc) ? @y.call : @y
164
- end
165
-
166
- # Returns the row/line end position for the interface.
167
- #
168
- # @return [Fixnum]
169
- def _yn
170
- @yn.is_a?(Proc) ? @yn.call : @yn
171
- end
172
-
173
- # Returns the column/character start position for the interface.
5
+ # @todo Consider storing the Terminal size at the time of first creation,
6
+ # this allows us to return the interface to its original dimensions if
7
+ # the terminal resizes back to normal size.
174
8
  #
175
- # @return [Fixnum]
176
- def _x
177
- @x.is_a?(Proc) ? @x.call : @x
178
- end
179
-
180
- # Returns the column/character end position for the interface.
181
- #
182
- # @return [Fixnum]
183
- def _xn
184
- @xn.is_a?(Proc) ? @xn.call : @xn
185
- end
186
-
187
- # Returns the width of the interface.
188
- #
189
- # @return [Fixnum]
190
- def _width
191
- @width.is_a?(Proc) ? @width.call : @width
192
- end
193
-
194
- # Returns the height of the interface.
195
- #
196
- # @return [Fixnum]
197
- def _height
198
- @height.is_a?(Proc) ? @height.call : @height
199
- end
200
-
201
- # Returns the default options/attributes for this class.
9
+ # Calculates and provides interface geometry determined by both the client's
10
+ # requirements and the terminal's current viewing area.
202
11
  #
203
- # @return [Hash]
204
- def defaults
205
- {
206
- centred: nil,
207
- height: nil,
208
- maximised: false,
209
- name: nil,
210
- repository: Vedeu.geometries,
211
- width: nil,
212
- x: nil,
213
- xn: nil,
214
- y: nil,
215
- yn: nil,
216
- }
217
- end
12
+ class Geometry
13
+
14
+ extend Forwardable
15
+ include Vedeu::Model
16
+
17
+ def_delegators :area,
18
+ :north,
19
+ :east,
20
+ :south,
21
+ :west,
22
+ :top,
23
+ :right,
24
+ :bottom,
25
+ :left,
26
+ :y,
27
+ :xn,
28
+ :yn,
29
+ :x,
30
+ :height,
31
+ :width
32
+
33
+ # @!attribute [rw] centred
34
+ # @return [Boolean]
35
+ attr_accessor :centred
36
+
37
+ # @!attribute [rw] name
38
+ # @return [String]
39
+ attr_accessor :name
40
+
41
+ # @!attribute [r] attributes
42
+ # @return [Hash]
43
+ attr_reader :attributes
44
+
45
+ # @!attribute [w] height
46
+ # @return [Fixnum]
47
+ attr_writer :height
48
+
49
+ # @!attribute [rw] maximised
50
+ # @return [Boolean]
51
+ attr_accessor :maximised
52
+ alias_method :maximised?, :maximised
53
+
54
+ # @!attribute [w] width
55
+ # @return [Fixnum]
56
+ attr_writer :width
57
+
58
+ # @!attribute [w] x
59
+ # @return [Fixnum]
60
+ attr_writer :x
61
+
62
+ # @!attribute [w] xn
63
+ # @return [Fixnum]
64
+ attr_writer :xn
65
+
66
+ # @!attribute [w] y
67
+ # @return [Fixnum]
68
+ attr_writer :y
69
+
70
+ # @!attribute [w] yn
71
+ # @return [Fixnum]
72
+ attr_writer :yn
73
+
74
+ # Returns a new instance of Vedeu::Geometry::Geometry.
75
+ #
76
+ # @param attributes [Hash]
77
+ # @option attributes centred [Boolean]
78
+ # @option attributes maximised [Boolean]
79
+ # @option attributes height [Fixnum]
80
+ # @option attributes name [String]
81
+ # @option attributes repository [Vedeu::Geometry::Repository]
82
+ # @option attributes width [Fixnum]
83
+ # @option attributes x [Fixnum]
84
+ # @option attributes xn [Fixnum]
85
+ # @option attributes y [Fixnum]
86
+ # @option attributes yn [Fixnum]
87
+ # @return [Vedeu::Geometry::Geometry]
88
+ def initialize(attributes = {})
89
+ @attributes = defaults.merge!(attributes)
90
+
91
+ @attributes.each do |key, value|
92
+ instance_variable_set("@#{key}", value)
93
+ end
94
+ end
95
+
96
+ # Will maximise the named interface geometry. This means it will occupy
97
+ # all of the available space on the terminal window.
98
+ #
99
+ # @example
100
+ # Vedeu.trigger(:_maximise_, name)
101
+ #
102
+ # @return [Vedeu::Geometry::Geometry|NilClass]
103
+ def maximise
104
+ return self if maximised?
105
+
106
+ Vedeu.trigger(:_clear_)
107
+
108
+ @maximised = true
109
+
110
+ work = store
111
+
112
+ Vedeu.trigger(:_refresh_, name)
113
+
114
+ work
115
+ end
116
+
117
+ # Moves the geometry down by one row.
118
+ #
119
+ # TODO: Move cursor also.
120
+ # @return [Vedeu::Geometry::Geometry]
121
+ def move_down
122
+ dy = (yn + 1 > Vedeu.height) ? y : y + 1
123
+ dyn = (yn + 1 > Vedeu.height) ? yn : yn + 1
124
+
125
+ @attributes = attributes.merge(
126
+ centred: false,
127
+ maximised: false,
128
+ x: x,
129
+ xn: xn,
130
+ y: dy,
131
+ yn: dyn,
132
+ )
133
+ Vedeu::Geometry::Geometry.new(@attributes).store
134
+ end
135
+
136
+ # Moves the geometry left by one column.
137
+ #
138
+ # TODO: Move cursor also.
139
+ # @return [Vedeu::Geometry::Geometry]
140
+ def move_left
141
+ dx = (x - 1 < 1) ? x : x - 1
142
+ dxn = (x - 1 < 1) ? xn : xn - 1
143
+
144
+ @attributes = attributes.merge(
145
+ centred: false,
146
+ maximised: false,
147
+ x: dx,
148
+ xn: dxn,
149
+ y: y,
150
+ yn: yn,
151
+ )
152
+ Vedeu::Geometry::Geometry.new(@attributes).store
153
+ end
154
+
155
+ # Moves the geometry to the top left of the terminal.
156
+ #
157
+ # TODO: Move cursor also.
158
+ # @return [Vedeu::Geometry::Geometry]
159
+ def move_origin
160
+ @attributes = attributes.merge(
161
+ centred: false,
162
+ maximised: false,
163
+ x: 1,
164
+ xn: xn - x + 1,
165
+ y: 1,
166
+ yn: yn - y + 1,
167
+ )
168
+ Vedeu::Geometry::Geometry.new(@attributes).store
169
+ end
170
+
171
+ # Moves the geometry right by one column.
172
+ #
173
+ # TODO: Move cursor also.
174
+ # @return [Vedeu::Geometry::Geometry]
175
+ def move_right
176
+ dx = (xn + 1 > Vedeu.width) ? x : x + 1
177
+ dxn = (xn + 1 > Vedeu.width) ? xn : xn + 1
178
+
179
+ @attributes = attributes.merge(
180
+ centred: false,
181
+ maximised: false,
182
+ x: dx,
183
+ xn: dxn,
184
+ y: y,
185
+ yn: yn,
186
+ )
187
+ Vedeu::Geometry::Geometry.new(@attributes).store
188
+ end
189
+
190
+ # Moves the geometry up by one column.
191
+ #
192
+ # TODO: Move cursor also.
193
+ # @return [Vedeu::Geometry::Geometry]
194
+ def move_up
195
+ dy = (y - 1 < 1) ? y : y - 1
196
+ dyn = (y - 1 < 1) ? yn : yn - 1
197
+
198
+ @attributes = attributes.merge(
199
+ centred: false,
200
+ maximised: false,
201
+ x: x,
202
+ xn: xn,
203
+ y: dy,
204
+ yn: dyn,
205
+ )
206
+ Vedeu::Geometry::Geometry.new(@attributes).store
207
+ end
208
+
209
+ # Will unmaximise the named interface geometry. Previously, when a
210
+ # geometry was maximised, then triggering the unmaximise event will return
211
+ # it to its usual defined size (terminal size permitting: when the
212
+ # terminal has been resized, then the new geometry size should adapt).
213
+ #
214
+ # @example
215
+ # Vedeu.trigger(:_unmaximise_, name)
216
+ #
217
+ # @return [Vedeu::Geometry::Geometry|NilClass]
218
+ def unmaximise
219
+ return self unless maximised?
220
+
221
+ Vedeu.trigger(:_clear_)
222
+
223
+ @maximised = false
224
+
225
+ work = store
226
+
227
+ Vedeu.trigger(:_refresh_)
228
+
229
+ work
230
+ end
231
+
232
+ private
233
+
234
+ # @return [Vedeu::Geometry::Area]
235
+ def area
236
+ @area = Vedeu::Geometry::Area.from_attributes(area_attributes)
237
+ end
238
+
239
+ # @return [Hash<Symbol => Fixnum, Boolean>]
240
+ def area_attributes
241
+ {
242
+ y: _y,
243
+ yn: _yn,
244
+ y_yn: _height,
245
+ y_default: Vedeu.height,
246
+ x: _x,
247
+ xn: _xn,
248
+ x_xn: _width,
249
+ x_default: Vedeu.width,
250
+ centred: centred,
251
+ maximised: maximised,
252
+ }
253
+ end
254
+
255
+ # Returns the row/line start position for the interface.
256
+ #
257
+ # @return [Fixnum]
258
+ def _y
259
+ @y.is_a?(Proc) ? @y.call : @y
260
+ end
261
+
262
+ # Returns the row/line end position for the interface.
263
+ #
264
+ # @return [Fixnum]
265
+ def _yn
266
+ @yn.is_a?(Proc) ? @yn.call : @yn
267
+ end
268
+
269
+ # Returns the column/character start position for the interface.
270
+ #
271
+ # @return [Fixnum]
272
+ def _x
273
+ @x.is_a?(Proc) ? @x.call : @x
274
+ end
275
+
276
+ # Returns the column/character end position for the interface.
277
+ #
278
+ # @return [Fixnum]
279
+ def _xn
280
+ @xn.is_a?(Proc) ? @xn.call : @xn
281
+ end
282
+
283
+ # Returns the width of the interface.
284
+ #
285
+ # @return [Fixnum]
286
+ def _width
287
+ @width.is_a?(Proc) ? @width.call : @width
288
+ end
289
+
290
+ # Returns the height of the interface.
291
+ #
292
+ # @return [Fixnum]
293
+ def _height
294
+ @height.is_a?(Proc) ? @height.call : @height
295
+ end
296
+
297
+ # Returns the default options/attributes for this class.
298
+ #
299
+ # @return [Hash]
300
+ def defaults
301
+ {
302
+ centred: nil,
303
+ height: nil,
304
+ maximised: false,
305
+ name: nil,
306
+ repository: Vedeu.geometries,
307
+ width: nil,
308
+ x: nil,
309
+ xn: nil,
310
+ y: nil,
311
+ yn: nil,
312
+ }
313
+ end
314
+
315
+ end # Geometry
218
316
 
219
317
  end # Geometry
220
318