vedeu 0.6.4 → 0.6.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +40 -0
- data/README.md +1 -0
- data/docs/dsl.md +24 -24
- data/lib/vedeu/all.rb +21 -44
- data/lib/vedeu/api.rb +13 -13
- data/lib/vedeu/application/application_controller.rb +2 -0
- data/lib/vedeu/bindings/movement.rb +53 -18
- data/lib/vedeu/bindings/refresh.rb +1 -1
- data/lib/vedeu/bindings/system.rb +2 -2
- data/lib/vedeu/bindings/visibility.rb +3 -3
- data/lib/vedeu/borders/all.rb +13 -0
- data/lib/vedeu/borders/border.rb +209 -202
- data/lib/vedeu/{dsl/border.rb → borders/dsl.rb} +15 -15
- data/lib/vedeu/{null/border.rb → borders/null.rb} +9 -9
- data/lib/vedeu/borders/render.rb +347 -0
- data/lib/vedeu/borders/repository.rb +19 -0
- data/lib/vedeu/buffers/all.rb +13 -0
- data/lib/vedeu/buffers/buffer.rb +182 -176
- data/lib/vedeu/{null/buffer.rb → buffers/null.rb} +8 -8
- data/lib/vedeu/buffers/repository.rb +24 -0
- data/lib/vedeu/buffers/virtual_buffer.rb +2 -2
- data/lib/vedeu/cursors/all.rb +11 -0
- data/lib/vedeu/cursors/cursor.rb +276 -0
- data/lib/vedeu/cursors/refresh.rb +84 -0
- data/lib/vedeu/cursors/repository.rb +34 -0
- data/lib/vedeu/dsl/interface.rb +9 -9
- data/lib/vedeu/dsl/shared.rb +11 -11
- data/lib/vedeu/{exceptions.rb → error.rb} +2 -2
- data/lib/vedeu/esc/esc.rb +1 -1
- data/lib/vedeu/geometry/all.rb +18 -0
- data/lib/vedeu/geometry/area.rb +170 -160
- data/lib/vedeu/geometry/coordinate.rb +61 -39
- data/lib/vedeu/geometry/dimension.rb +139 -132
- data/lib/vedeu/{dsl/geometry.rb → geometry/dsl.rb} +11 -11
- data/lib/vedeu/geometry/generic_coordinate.rb +159 -153
- data/lib/vedeu/geometry/geometry.rb +310 -212
- data/lib/vedeu/geometry/grid.rb +73 -69
- data/lib/vedeu/{null/geometry.rb → geometry/null.rb} +10 -10
- data/lib/vedeu/geometry/position.rb +124 -120
- data/lib/vedeu/geometry/repository.rb +19 -0
- data/lib/vedeu/input/editor/document.rb +2 -2
- data/lib/vedeu/internal_api.rb +8 -8
- data/lib/vedeu/models/escape.rb +2 -2
- data/lib/vedeu/models/interface.rb +1 -1
- data/lib/vedeu/models/page.rb +89 -0
- data/lib/vedeu/models/row.rb +66 -0
- data/lib/vedeu/models/toggleable.rb +1 -1
- data/lib/vedeu/models/views/char.rb +7 -6
- data/lib/vedeu/models/views/line.rb +1 -1
- data/lib/vedeu/models/views/view.rb +2 -2
- data/lib/vedeu/options.rb +19 -0
- data/lib/vedeu/output/clear/named_interface.rb +1 -1
- data/lib/vedeu/output/direct.rb +1 -1
- data/lib/vedeu/output/presentation.rb +2 -1
- data/lib/vedeu/output/viewport.rb +3 -3
- data/lib/vedeu/repositories/model.rb +9 -1
- data/lib/vedeu/repositories/repository.rb +5 -0
- data/lib/vedeu/terminal/terminal.rb +3 -3
- data/lib/vedeu/version.rb +1 -1
- data/test/lib/vedeu/borders/border_test.rb +299 -291
- data/test/lib/vedeu/{dsl/border_test.rb → borders/dsl_test.rb} +6 -6
- data/test/lib/vedeu/{null/border_test.rb → borders/null_test.rb} +6 -6
- data/test/lib/vedeu/borders/render_test.rb +125 -0
- data/test/lib/vedeu/borders/repository_test.rb +17 -0
- data/test/lib/vedeu/buffers/buffer_test.rb +116 -112
- data/test/lib/vedeu/{null/buffer_test.rb → buffers/null_test.rb} +5 -5
- data/test/lib/vedeu/buffers/repository_test.rb +18 -0
- data/test/lib/vedeu/cursors/cursor_test.rb +370 -0
- data/test/lib/vedeu/cursors/refresh_test.rb +69 -0
- data/test/lib/vedeu/cursors/repository_test.rb +41 -0
- data/test/lib/vedeu/dsl/interface_test.rb +5 -5
- data/test/lib/vedeu/{exceptions_test.rb → error_test.rb} +0 -0
- data/test/lib/vedeu/geometry/area_test.rb +141 -137
- data/test/lib/vedeu/geometry/coordinate_test.rb +93 -89
- data/test/lib/vedeu/geometry/dimension_test.rb +137 -133
- data/test/lib/vedeu/{dsl/geometry_test.rb → geometry/dsl_test.rb} +17 -17
- data/test/lib/vedeu/geometry/generic_coordinate_test.rb +32 -28
- data/test/lib/vedeu/geometry/geometry_test.rb +282 -157
- data/test/lib/vedeu/geometry/grid_test.rb +35 -31
- data/test/lib/vedeu/{null/geometry_test.rb → geometry/null_test.rb} +5 -5
- data/test/lib/vedeu/geometry/position_test.rb +146 -142
- data/test/lib/vedeu/geometry/repository_test.rb +19 -0
- data/test/lib/vedeu/input/editor/document_test.rb +1 -1
- data/test/lib/vedeu/models/escape_test.rb +1 -1
- data/test/lib/vedeu/models/interface_test.rb +2 -2
- data/test/lib/vedeu/models/page_test.rb +235 -0
- data/test/lib/vedeu/models/row_test.rb +111 -0
- data/test/lib/vedeu/models/views/char_test.rb +3 -3
- data/test/lib/vedeu/options_test.rb +57 -0
- data/test/lib/vedeu/output/clear/named_interface_test.rb +1 -1
- data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
- data/test/lib/vedeu/output/viewport_test.rb +15 -9
- data/test/lib/vedeu/refresh/refresh_buffer_test.rb +12 -12
- data/test/lib/vedeu/repositories/repositories_test.rb +1 -1
- data/test/lib/vedeu/repositories/repository_test.rb +7 -0
- data/test/lib/vedeu/terminal/terminal_test.rb +1 -1
- data/test/test_helper.rb +1 -1
- data/vedeu.gemspec +2 -2
- metadata +57 -63
- data/lib/vedeu/borders/borders.rb +0 -15
- data/lib/vedeu/borders/render_border.rb +0 -331
- data/lib/vedeu/buffers/buffers.rb +0 -20
- data/lib/vedeu/cursor/cursor.rb +0 -174
- data/lib/vedeu/cursor/cursors.rb +0 -30
- data/lib/vedeu/cursor/move.rb +0 -239
- data/lib/vedeu/cursor/reposition.rb +0 -78
- data/lib/vedeu/geometry/geometries.rb +0 -15
- data/lib/vedeu/refresh/refresh_cursor.rb +0 -92
- data/test/lib/vedeu/borders/borders_test.rb +0 -13
- data/test/lib/vedeu/borders/render_border_test.rb +0 -121
- data/test/lib/vedeu/buffers/buffers_test.rb +0 -14
- data/test/lib/vedeu/cursor/cursor_test.rb +0 -246
- data/test/lib/vedeu/cursor/cursors_test.rb +0 -37
- data/test/lib/vedeu/cursor/move_test.rb +0 -301
- data/test/lib/vedeu/cursor/reposition_test.rb +0 -63
- data/test/lib/vedeu/geometry/geometries_test.rb +0 -15
- data/test/lib/vedeu/refresh/refresh_cursor_test.rb +0 -65
@@ -1,172 +1,178 @@
|
|
1
1
|
module Vedeu
|
2
2
|
|
3
|
-
|
4
|
-
#
|
5
|
-
class GenericCoordinate
|
3
|
+
module Geometry
|
6
4
|
|
7
|
-
#
|
5
|
+
# Crudely corrects out of range values.
|
8
6
|
#
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
@attributes
|
16
|
-
|
17
|
-
@
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
-
|
33
|
-
|
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
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
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
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
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
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
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
|
-
|
141
|
-
|
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
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
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
|
-
#
|
160
|
-
|
161
|
-
|
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
|
-
|
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
|
-
|
134
|
-
|
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
|
-
#
|
176
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
|