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,49 +1,71 @@
1
1
  module Vedeu
2
2
 
3
- # Crudely corrects out of range values.
4
- #
5
- class Coordinate
3
+ module Geometry
6
4
 
7
- extend Forwardable
5
+ # Crudely corrects out of range values.
6
+ #
7
+ class Coordinate
8
8
 
9
- def_delegators :x,
10
- :x_position,
11
- :xn
9
+ extend Forwardable
12
10
 
13
- def_delegators :y,
14
- :y_position,
15
- :yn
11
+ def_delegators :x,
12
+ :x_position,
13
+ :xn
16
14
 
17
- # Returns a new instance of Vedeu::Coordinate.
18
- #
19
- # @param name [String]
20
- # @param oy [Fixnum]
21
- # @param ox [Fixnum]
22
- # @return [Vedeu::Coordinate]
23
- def initialize(name, oy, ox)
24
- @name = name
25
- @ox = ox
26
- @oy = oy
27
- end
28
-
29
- private
30
-
31
- # Provide an instance of Vedeu::GenericCoordinate to determine correct x
32
- # related coordinates.
33
- #
34
- # @return [Vedeu::GenericCoordinate]
35
- def x
36
- @x ||= Vedeu::GenericCoordinate.new(name: @name, offset: @ox, type: :x)
37
- end
15
+ def_delegators :y,
16
+ :y_position,
17
+ :yn
38
18
 
39
- # Provide an instance of Vedeu::GenericCoordinate to determine correct y
40
- # related coordinates.
41
- #
42
- # @return [Vedeu::GenericCoordinate]
43
- def y
44
- @y ||= Vedeu::GenericCoordinate.new(name: @name, offset: @oy, type: :y)
45
- end
19
+ # Returns a new instance of Vedeu::Geometry::Coordinate.
20
+ #
21
+ # @param name [String]
22
+ # @param oy [Fixnum]
23
+ # @param ox [Fixnum]
24
+ # @return [Vedeu::Geometry::Coordinate]
25
+ def initialize(name, oy, ox)
26
+ @name = name
27
+ @ox = ox
28
+ @oy = oy
29
+ end
30
+
31
+ protected
32
+
33
+ # @!attribute [r] name
34
+ # @return [String]
35
+ attr_reader :name
36
+
37
+ # @!attribute [rw] ox
38
+ # @return [Fixnum]
39
+ attr_accessor :ox
40
+
41
+ # @!attribute [rw] oy
42
+ # @return [Fixnum]
43
+ attr_accessor :oy
44
+
45
+ private
46
+
47
+ # Provide an instance of Vedeu::Geometry::GenericCoordinate to determine
48
+ # correct x related coordinates.
49
+ #
50
+ # @return [Vedeu::Geometry::GenericCoordinate]
51
+ def x
52
+ @x ||= Vedeu::Geometry::GenericCoordinate.new(name: name,
53
+ offset: ox,
54
+ type: :x)
55
+ end
56
+
57
+ # Provide an instance of Vedeu::Geometry::GenericCoordinate to determine
58
+ # correct y related coordinates.
59
+ #
60
+ # @return [Vedeu::Geometry::GenericCoordinate]
61
+ def y
62
+ @y ||= Vedeu::Geometry::GenericCoordinate.new(name: name,
63
+ offset: oy,
64
+ type: :y)
65
+ end
66
+
67
+ end # Coordinate
46
68
 
47
- end # Coordinate
69
+ end # Geometry
48
70
 
49
71
  end # Vedeu
@@ -1,168 +1,175 @@
1
1
  module Vedeu
2
2
 
3
- # A Dimension is either the height or width of an entity.
4
- #
5
- class Dimension
3
+ module Geometry
6
4
 
7
- # @param (see #initialize)
8
- # @return [Array<Fixnum>]
9
- def self.pair(attributes = {})
10
- new(attributes).pair
11
- end
12
-
13
- # Returns a new instance of Vedeu::Dimension.
14
- #
15
- # @param attributes [Hash<Symbol => Fixnum, NilClass>]
16
- # @option attributes d [Fixnum|NilClass] The starting value (y or x).
17
- # @option attributes dn [Fixnum|NilClass] The ending value (yn or xn).
18
- # @option attributes d_dn [Fixnum|NilClass] A width or a height.
19
- # @option attributes default [Fixnum|NilClass] The terminal width or height.
20
- # @option attributes options [Hash]
21
- # @return [Vedeu::Dimension]
22
- def initialize(attributes = {})
23
- @attributes = defaults.merge!(attributes)
24
-
25
- @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
26
- end
27
-
28
- # Fetch the starting coordinate.
5
+ # A Dimension is either the height or width of an entity.
29
6
  #
30
- # @return [Fixnum]
31
- def d1
32
- dimension[0] < 1 ? 1 : dimension[0]
33
- end
7
+ class Dimension
34
8
 
35
- # Fetch the ending coordinate.
36
- #
37
- # @return [Fixnum]
38
- def d2
39
- dimension[-1]
40
- end
9
+ # @param (see #initialize)
10
+ # @return [Array<Fixnum>]
11
+ def self.pair(attributes = {})
12
+ new(attributes).pair
13
+ end
41
14
 
42
- # Fetch the coordinates.
43
- #
44
- # @return [Array<Fixnum>]
45
- def pair
46
- dimension
47
- end
15
+ # Returns a new instance of Vedeu::Geometry::Dimension.
16
+ #
17
+ # @param attributes [Hash<Symbol => Fixnum, NilClass>]
18
+ # @option attributes d [Fixnum|NilClass] The starting value (y or x).
19
+ # @option attributes dn [Fixnum|NilClass] The ending value (yn or xn).
20
+ # @option attributes d_dn [Fixnum|NilClass] A width or a height.
21
+ # @option attributes default [Fixnum|NilClass] The terminal width or
22
+ # height.
23
+ # @option attributes options [Hash]
24
+ # @return [Vedeu::Geometry::Dimension]
25
+ def initialize(attributes = {})
26
+ @attributes = defaults.merge!(attributes)
27
+
28
+ @attributes.each do |key, value|
29
+ instance_variable_set("@#{key}", value)
30
+ end
31
+ end
48
32
 
49
- protected
33
+ # Fetch the starting coordinate.
34
+ #
35
+ # @return [Fixnum]
36
+ def d1
37
+ dimension[0] < 1 ? 1 : dimension[0]
38
+ end
50
39
 
51
- # @!attribute [r] d
52
- # @return [Fixnum|NilClass]
53
- attr_reader :d
40
+ # Fetch the ending coordinate.
41
+ #
42
+ # @return [Fixnum]
43
+ def d2
44
+ dimension[-1]
45
+ end
46
+
47
+ # Fetch the coordinates.
48
+ #
49
+ # @return [Array<Fixnum>]
50
+ def pair
51
+ dimension
52
+ end
54
53
 
55
- # @!attribute [r] dn
56
- # @return [Fixnum|NilClass]
57
- attr_reader :dn
54
+ protected
58
55
 
59
- # @!attribute [r] d_dn
60
- # @return [Fixnum|NilClass]
61
- attr_reader :d_dn
56
+ # @!attribute [r] d
57
+ # @return [Fixnum|NilClass]
58
+ attr_reader :d
62
59
 
63
- # @!attribute [r] default
64
- # @return [Fixnum|NilClass]
65
- attr_reader :default
60
+ # @!attribute [r] dn
61
+ # @return [Fixnum|NilClass]
62
+ attr_reader :dn
66
63
 
67
- # @!attribute [r] maximised
68
- # @return [Boolean]
69
- attr_reader :maximised
70
- alias_method :maximised?, :maximised
64
+ # @!attribute [r] d_dn
65
+ # @return [Fixnum|NilClass]
66
+ attr_reader :d_dn
71
67
 
72
- # @!attribute [r] centred
73
- # @return [Boolean]
74
- attr_reader :centred
75
- alias_method :centred?, :centred
68
+ # @!attribute [r] default
69
+ # @return [Fixnum|NilClass]
70
+ attr_reader :default
76
71
 
77
- private
72
+ # @!attribute [r] maximised
73
+ # @return [Boolean]
74
+ attr_reader :maximised
75
+ alias_method :maximised?, :maximised
78
76
 
79
- # @return [Array<Fixnum>]
80
- def dimension
81
- @dimension = if maximised?
82
- [1, default]
77
+ # @!attribute [r] centred
78
+ # @return [Boolean]
79
+ attr_reader :centred
80
+ alias_method :centred?, :centred
83
81
 
84
- elsif centred? && length?
85
- [centred_d, centred_dn]
82
+ private
86
83
 
87
- else
88
- [_d, _dn]
84
+ # @return [Array<Fixnum>]
85
+ def dimension
86
+ @dimension = if maximised?
87
+ [1, default]
89
88
 
90
- end
91
- end
89
+ elsif centred? && length?
90
+ [centred_d, centred_dn]
92
91
 
93
- # @return [Boolean]
94
- def length?
95
- default && length
96
- end
92
+ else
93
+ [_d, _dn]
97
94
 
98
- # @return [Fixnum|NilClass]
99
- def length
100
- if d && dn
101
- (d..dn).size
95
+ end
96
+ end
97
+
98
+ # @return [Boolean]
99
+ def length?
100
+ default && length
101
+ end
102
102
 
103
- elsif d_dn
104
- d_dn
103
+ # @return [Fixnum|NilClass]
104
+ def length
105
+ if d && dn
106
+ (d..dn).size
105
107
 
106
- elsif default
107
- default
108
+ elsif d_dn
109
+ d_dn
108
110
 
111
+ elsif default
112
+ default
113
+
114
+ end
109
115
  end
110
- end
111
116
 
112
- # Ascertains the centred starting coordinate.
113
- #
114
- # @return [Fixnum]
115
- def centred_d
116
- (default / 2) - (length / 2)
117
- end
117
+ # Ascertains the centred starting coordinate.
118
+ #
119
+ # @return [Fixnum]
120
+ def centred_d
121
+ (default / 2) - (length / 2)
122
+ end
118
123
 
119
- # Ascertains the centred ending coordinate.
120
- #
121
- # @return [Fixnum]
122
- def centred_dn
123
- (default / 2) + (length / 2)
124
- end
124
+ # Ascertains the centred ending coordinate.
125
+ #
126
+ # @return [Fixnum]
127
+ def centred_dn
128
+ (default / 2) + (length / 2)
129
+ end
125
130
 
126
- # Fetch the starting coordinate, or use 1 when not set.
127
- #
128
- # @return [Fixnum]
129
- def _d
130
- d || 1
131
- end
131
+ # Fetch the starting coordinate, or use 1 when not set.
132
+ #
133
+ # @return [Fixnum]
134
+ def _d
135
+ d || 1
136
+ end
132
137
 
133
- # Fetch the ending coordinate.
134
- #
135
- # @return [Fixnum]
136
- def _dn
137
- if dn
138
- dn
138
+ # Fetch the ending coordinate.
139
+ #
140
+ # @return [Fixnum]
141
+ def _dn
142
+ if dn
143
+ dn
139
144
 
140
- elsif d.nil? && d_dn
141
- d_dn
145
+ elsif d.nil? && d_dn
146
+ d_dn
142
147
 
143
- elsif d && d_dn
144
- (d + d_dn) - 1
148
+ elsif d && d_dn
149
+ (d + d_dn) - 1
145
150
 
146
- else
147
- default
151
+ else
152
+ default
148
153
 
154
+ end
149
155
  end
150
- end
151
156
 
152
- # Returns the default options/attributes for this class.
153
- #
154
- # @return [Hash<Symbol => NilClass,Boolean>]
155
- def defaults
156
- {
157
- d: nil,
158
- dn: nil,
159
- d_dn: nil,
160
- default: nil,
161
- centred: false,
162
- maximised: false,
163
- }
164
- end
165
-
166
- end # Dimension
157
+ # Returns the default options/attributes for this class.
158
+ #
159
+ # @return [Hash<Symbol => NilClass,Boolean>]
160
+ def defaults
161
+ {
162
+ d: nil,
163
+ dn: nil,
164
+ d_dn: nil,
165
+ default: nil,
166
+ centred: false,
167
+ maximised: false,
168
+ }
169
+ end
170
+
171
+ end # Dimension
172
+
173
+ end # Geometry
167
174
 
168
175
  end # Vedeu
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
- module DSL
3
+ module Geometry
4
4
 
5
5
  # Geometry allows the configuration of the position and size of an
6
6
  # interface. Within Vedeu, as the same for ANSI terminals, has the origin at
@@ -68,7 +68,7 @@ module Vedeu
68
68
  # yn +--------------+ # south: yn + 1
69
69
  # south
70
70
  #
71
- class Geometry
71
+ class DSL
72
72
 
73
73
  include Vedeu::DSL
74
74
  include Vedeu::DSL::Use
@@ -83,18 +83,18 @@ module Vedeu
83
83
  # geometry belongs.
84
84
  # @param block [Proc]
85
85
  # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
86
- # @return [Vedeu::Geometry]
86
+ # @return [Vedeu::Geometry::Geometry]
87
87
  def self.geometry(name, &block)
88
88
  fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
89
89
 
90
- Vedeu::Geometry.build(name: name, &block).store
90
+ Vedeu::Geometry::Geometry.build(name: name, &block).store
91
91
  end
92
92
 
93
- # Returns an instance of DSL::Geometry.
93
+ # Returns an instance of Vedeu::Geometry::DSL.
94
94
  #
95
- # @param model [Vedeu::Geometry]
95
+ # @param model [Vedeu::Geometry::Geometry]
96
96
  # @param client [Object]
97
- # @return [Vedeu::DSL::Geometry]
97
+ # @return [Vedeu::Geometry::DSL]
98
98
  def initialize(model, client = nil)
99
99
  @model = model
100
100
  @client = client
@@ -137,7 +137,7 @@ module Vedeu
137
137
  # between 1 and 12 inclusive.
138
138
  # @return [Fixnum|Vedeu::Error::OutOfRange]
139
139
  def columns(value)
140
- Vedeu::Grid.columns(value)
140
+ Vedeu::Geometry::Grid.columns(value)
141
141
  end
142
142
 
143
143
  # Specify the number of characters/rows/lines tall the interface will be.
@@ -170,7 +170,7 @@ module Vedeu
170
170
  # between 1 and 12 inclusive.
171
171
  # @return [Fixnum]
172
172
  def rows(value)
173
- Vedeu::Grid.rows(value)
173
+ Vedeu::Geometry::Grid.rows(value)
174
174
  end
175
175
 
176
176
  # Specify the number of characters/columns wide the interface will be.
@@ -269,8 +269,8 @@ module Vedeu
269
269
  end
270
270
  alias_method :yn=, :yn
271
271
 
272
- end # Geometry
272
+ end # DSL
273
273
 
274
- end # DSL
274
+ end # Geometry
275
275
 
276
276
  end # Vedeu