vedeu 0.6.12 → 0.6.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/bindings/application.rb +4 -0
  3. data/lib/vedeu/bindings/document.rb +4 -0
  4. data/lib/vedeu/bindings/focus.rb +4 -0
  5. data/lib/vedeu/bindings/menus.rb +4 -0
  6. data/lib/vedeu/bindings/movement.rb +4 -0
  7. data/lib/vedeu/bindings/refresh.rb +4 -0
  8. data/lib/vedeu/bindings/system.rb +4 -0
  9. data/lib/vedeu/bindings/visibility.rb +4 -0
  10. data/lib/vedeu/borders/dsl.rb +2 -3
  11. data/lib/vedeu/configuration/api.rb +26 -0
  12. data/lib/vedeu/configuration/configuration.rb +16 -0
  13. data/lib/vedeu/dsl/composition.rb +2 -3
  14. data/lib/vedeu/dsl/group.rb +2 -3
  15. data/lib/vedeu/dsl/interface.rb +2 -4
  16. data/lib/vedeu/dsl/keymap.rb +24 -21
  17. data/lib/vedeu/dsl/line.rb +4 -6
  18. data/lib/vedeu/dsl/presentation.rb +16 -12
  19. data/lib/vedeu/dsl/shared.rb +18 -14
  20. data/lib/vedeu/dsl/stream.rb +2 -3
  21. data/lib/vedeu/dsl/text.rb +6 -4
  22. data/lib/vedeu/dsl/view.rb +6 -8
  23. data/lib/vedeu/error.rb +12 -0
  24. data/lib/vedeu/geometry/area.rb +4 -2
  25. data/lib/vedeu/geometry/coordinate.rb +4 -4
  26. data/lib/vedeu/geometry/dimension.rb +6 -4
  27. data/lib/vedeu/geometry/dsl.rb +55 -43
  28. data/lib/vedeu/geometry/generic_coordinate.rb +4 -3
  29. data/lib/vedeu/geometry/geometry.rb +13 -11
  30. data/lib/vedeu/geometry/grid.rb +6 -5
  31. data/lib/vedeu/geometry/position.rb +12 -10
  32. data/lib/vedeu/input/key.rb +2 -3
  33. data/lib/vedeu/logging/log.rb +1 -1
  34. data/lib/vedeu/menus/menu.rb +2 -3
  35. data/lib/vedeu/models/views/view.rb +0 -2
  36. data/lib/vedeu/output/output.rb +10 -1
  37. data/lib/vedeu/output/renderers/file.rb +3 -3
  38. data/lib/vedeu/output/renderers/json.rb +2 -0
  39. data/lib/vedeu/runtime/main_loop.rb +4 -0
  40. data/lib/vedeu/templating/helpers.rb +4 -7
  41. data/lib/vedeu/terminal/buffer.rb +1 -2
  42. data/lib/vedeu/terminal/terminal.rb +4 -2
  43. data/lib/vedeu/version.rb +1 -1
  44. data/test/lib/vedeu/api/external_test.rb +14 -2
  45. data/test/lib/vedeu/bindings/visibility_test.rb +15 -0
  46. data/test/lib/vedeu/dsl/composition_test.rb +1 -1
  47. data/test/lib/vedeu/dsl/group_test.rb +1 -1
  48. data/test/lib/vedeu/dsl/interface_test.rb +3 -3
  49. data/test/lib/vedeu/dsl/line_test.rb +2 -2
  50. data/test/lib/vedeu/dsl/stream_test.rb +1 -1
  51. data/test/lib/vedeu/dsl/view_test.rb +3 -3
  52. data/test/lib/vedeu/error_test.rb +13 -0
  53. data/test/lib/vedeu/input/key_test.rb +1 -1
  54. data/test/lib/vedeu/menus/menu_test.rb +1 -1
  55. data/test/lib/vedeu/models/interface_test.rb +26 -0
  56. data/test/lib/vedeu/output/renderers/escape_sequence_test.rb +7 -0
  57. data/test/lib/vedeu/output/renderers/file_test.rb +7 -0
  58. data/test/lib/vedeu/output/renderers/html_test.rb +7 -0
  59. data/test/lib/vedeu/output/renderers/json_test.rb +7 -0
  60. data/test/lib/vedeu/output/renderers/null_test.rb +7 -0
  61. data/test/lib/vedeu/output/renderers/terminal_test.rb +11 -0
  62. data/test/lib/vedeu/output/renderers/text_test.rb +7 -0
  63. data/test/lib/vedeu/terminal/buffer_test.rb +31 -12
  64. data/test/lib/vedeu/terminal/terminal_test.rb +24 -21
  65. data/test/support/examples/material_colours_app.rb +2 -0
  66. data/test/test_helper.rb +2 -2
  67. metadata +2 -2
@@ -2,8 +2,8 @@ module Vedeu
2
2
 
3
3
  module DSL
4
4
 
5
- # Provides behaviour to be shared between both {Vedeu::DSL::Interface} and
6
- # {Vedeu::DSL::View} objects.
5
+ # Provides behaviour to be shared between both
6
+ # {Vedeu::DSL::Interface} and {Vedeu::DSL::View} objects.
7
7
  #
8
8
  module Shared
9
9
 
@@ -12,19 +12,21 @@ module Vedeu
12
12
  # @example
13
13
  # Vedeu.interface 'my_interface' do
14
14
  # border do
15
- # # ... see Vedeu::Borders::DSL for DSL methods for borders.
15
+ # # ... see Vedeu::Borders::DSL for DSL methods for
16
+ # # borders.
16
17
  # end
17
18
  # end
18
19
  #
19
- # @param name [String] The name of the interface; this is already provided
20
- # when we define the interface or view, setting it here is just
21
- # mirroring functionality of {Vedeu::Borders::DSL.border}.
20
+ # @param name [String] The name of the interface; this is
21
+ # already provided when we define the interface or view,
22
+ # setting it here is just mirroring functionality of
23
+ # {Vedeu::Borders::DSL.border}.
22
24
  # @param block [Proc]
23
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
25
+ # @raise [Vedeu::Error::RequiresBlock]
24
26
  # @return [Vedeu::Borders::Border]
25
27
  # @see Vedeu::Borders::DSL
26
28
  def border(name = nil, &block)
27
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
29
+ fail Vedeu::Error::RequiresBlock unless block_given?
28
30
 
29
31
  model_name = name ? name : model.name
30
32
 
@@ -55,19 +57,21 @@ module Vedeu
55
57
  # @example
56
58
  # Vedeu.interface 'my_interface' do
57
59
  # geometry do
58
- # # ... see Vedeu::Geometry::DSL for DSL methods for geometries.
60
+ # # ... see Vedeu::Geometry::DSL for DSL methods for
61
+ # # geometries.
59
62
  # end
60
63
  # end
61
64
  #
62
- # @param name [String] The name of the interface; this is already provided
63
- # when we define the interface or view, setting it here is just
64
- # mirroring functionality of {Vedeu::Geometry::DSL.geometry}.
65
+ # @param name [String] The name of the interface; this is
66
+ # already provided when we define the interface or view,
67
+ # setting it here is just mirroring functionality of
68
+ # {Vedeu::Geometry::DSL.geometry}.
65
69
  # @param block [Proc]
66
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
70
+ # @raise [Vedeu::Error::RequiresBlock]
67
71
  # @return [Vedeu::Geometry::Geometry]
68
72
  # @see Vedeu::Geometry::DSL
69
73
  def geometry(name = nil, &block)
70
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
74
+ fail Vedeu::Error::RequiresBlock unless block_given?
71
75
 
72
76
  model_name = name ? name : model.name
73
77
 
@@ -21,11 +21,10 @@ module Vedeu
21
21
  end
22
22
 
23
23
  # @param block [Proc]
24
- # @raise [Vedeu::Error::InvalidSyntax] The required block was
25
- # not given.
24
+ # @raise [Vedeu::Error::RequiresBlock]
26
25
  # @return [void]
27
26
  def stream(&block)
28
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
27
+ fail Vedeu::Error::RequiresBlock unless block_given?
29
28
 
30
29
  model.add(model.class.build(attributes, &block))
31
30
  end
@@ -6,11 +6,13 @@ module Vedeu
6
6
  #
7
7
  module Text
8
8
 
9
- # Specify the content for a view. Provides the means to align a string
10
- # (or object responding to `to_s`), and add it as a Line or to the Stream.
9
+ # Specify the content for a view. Provides the means to align a
10
+ # string (or object responding to `to_s`), and add it as a Line
11
+ # or to the Stream.
11
12
  #
12
- # @note If using the convenience methods; {left}, {centre}, {center} or
13
- # {right}, then a specified anchor will be ignored.
13
+ # @note If using the convenience methods; {left}, {centre},
14
+ # {center} or {right}, then a specified anchor will be
15
+ # ignored.
14
16
  #
15
17
  # @example
16
18
  # lines do
@@ -126,11 +126,10 @@ module Vedeu
126
126
  #
127
127
  # @param block [Proc] The directives you wish to send to render.
128
128
  # Typically includes `view` with associated sub-directives.
129
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
129
+ # @raise [Vedeu::Error::RequiresBlock]
130
130
  # @return [Array<View>]
131
131
  def renders(&block)
132
- fail Vedeu::Error::InvalidSyntax,
133
- 'block not given' unless block_given?
132
+ fail Vedeu::Error::RequiresBlock unless block_given?
134
133
 
135
134
  store(:store_immediate, &block)
136
135
  end
@@ -171,11 +170,10 @@ module Vedeu
171
170
  #
172
171
  # @param block [Proc] The directives you wish to send to render.
173
172
  # Typically includes `view` with associated sub-directives.
174
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
173
+ # @raise [Vedeu::Error::RequiresBlock]
175
174
  # @return [Array<View>]
176
175
  def views(&block)
177
- fail Vedeu::Error::InvalidSyntax,
178
- 'block not given' unless block_given?
176
+ fail Vedeu::Error::RequiresBlock unless block_given?
179
177
 
180
178
  store(:store_deferred, &block)
181
179
  end
@@ -243,10 +241,10 @@ module Vedeu
243
241
  # end
244
242
  # end
245
243
  #
246
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
244
+ # @raise [Vedeu::Error::RequiresBlock]
247
245
  # @return [Vedeu::Views::Line]
248
246
  def lines(&block)
249
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
247
+ fail Vedeu::Error::RequiresBlock unless block_given?
250
248
 
251
249
  model.add(model.member.build(attributes, &block))
252
250
  end
data/lib/vedeu/error.rb CHANGED
@@ -87,6 +87,18 @@ module Vedeu
87
87
 
88
88
  end # OutOfRange
89
89
 
90
+ # Raised when a method expecting a block to be given was not given
91
+ # the block.
92
+ #
93
+ class RequiresBlock < StandardError
94
+
95
+ # @return [String]
96
+ def message
97
+ 'The required block was not given.'
98
+ end
99
+
100
+ end
101
+
90
102
  end # Error
91
103
 
92
104
  end # Vedeu
@@ -12,7 +12,8 @@ module Vedeu
12
12
  alias_method :top, :y
13
13
 
14
14
  # @!attribute [r] yn
15
- # @return [Fixnum] Returns the bottom coordinate of the interface.
15
+ # @return [Fixnum] Returns the bottom coordinate of the
16
+ # interface.
16
17
  attr_reader :yn
17
18
  alias_method :bottom, :yn
18
19
 
@@ -22,7 +23,8 @@ module Vedeu
22
23
  alias_method :left, :x
23
24
 
24
25
  # @!attribute [r] xn
25
- # @return [Fixnum] Returns the right coordinate of the interface.
26
+ # @return [Fixnum] Returns the right coordinate of the
27
+ # interface.
26
28
  attr_reader :xn
27
29
  alias_method :right, :xn
28
30
 
@@ -44,8 +44,8 @@ module Vedeu
44
44
 
45
45
  private
46
46
 
47
- # Provide an instance of Vedeu::Geometry::GenericCoordinate to determine
48
- # correct x related coordinates.
47
+ # Provide an instance of {Vedeu::Geometry::GenericCoordinate} to
48
+ # determine correct x related coordinates.
49
49
  #
50
50
  # @return [Vedeu::Geometry::GenericCoordinate]
51
51
  def x
@@ -54,8 +54,8 @@ module Vedeu
54
54
  type: :x)
55
55
  end
56
56
 
57
- # Provide an instance of Vedeu::Geometry::GenericCoordinate to determine
58
- # correct y related coordinates.
57
+ # Provide an instance of {Vedeu::Geometry::GenericCoordinate} to
58
+ # determine correct y related coordinates.
59
59
  #
60
60
  # @return [Vedeu::Geometry::GenericCoordinate]
61
61
  def y
@@ -15,11 +15,13 @@ module Vedeu
15
15
  # Returns a new instance of Vedeu::Geometry::Dimension.
16
16
  #
17
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).
18
+ # @option attributes d [Fixnum|NilClass]
19
+ # The starting value (y or x).
20
+ # @option attributes dn [Fixnum|NilClass]
21
+ # The ending value (yn or xn).
20
22
  # @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 default [Fixnum|NilClass]
24
+ # The terminal width or height.
23
25
  # @option attributes options [Hash]
24
26
  # @return [Vedeu::Geometry::Dimension]
25
27
  def initialize(attributes = {})
@@ -3,11 +3,13 @@ module Vedeu
3
3
  module Geometry
4
4
 
5
5
  # Geometry allows the configuration of the position and size of an
6
- # interface. Within Vedeu, as the same for ANSI terminals, has the origin at
7
- # top-left, y = 1, x = 1. The 'y' coordinate is deliberately first.
6
+ # interface. Within Vedeu, as the same for ANSI terminals, has the
7
+ # origin at top-left, y = 1, x = 1. The 'y' coordinate is
8
+ # deliberately first.
8
9
  #
9
- # The Geometry DSL can be used within the Interface DSL or standalone. Here
10
- # are example of declarations for a `geometry` block:
10
+ # The Geometry DSL can be used within the Interface DSL or
11
+ # standalone. Here are example of declarations for a `geometry`
12
+ # block:
11
13
  #
12
14
  # A standalone geometry definition:
13
15
  #
@@ -34,11 +36,12 @@ module Vedeu
34
36
  # # ... some code here
35
37
  # end
36
38
  #
37
- # If a declaration is omitted for `height` or `width` the full remaining
38
- # space available in the terminal will be used. `x` and `y` both default to
39
- # 1.
39
+ # If a declaration is omitted for `height` or `width` the full
40
+ # remaining space available in the terminal will be used. `x` and
41
+ # `y` both default to 1.
40
42
  #
41
- # You can also make a geometry declaration dependent on another view:
43
+ # You can also make a geometry declaration dependent on another
44
+ # view:
42
45
  #
43
46
  # Vedeu.interface 'other_panel' do
44
47
  # # ... some code here
@@ -55,8 +58,8 @@ module Vedeu
55
58
  #
56
59
  # This view will begin just below "other\_panel".
57
60
  #
58
- # This crude ASCII diagram represents a Geometry within Vedeu, each of the
59
- # labels is a value you can access or define.
61
+ # This crude ASCII diagram represents a Geometry within Vedeu,
62
+ # each of the labels is a value you can access or define.
60
63
  #
61
64
  # x north xn # north: y - 1
62
65
  # y +--------------+ # top: y
@@ -73,19 +76,20 @@ module Vedeu
73
76
  include Vedeu::DSL
74
77
  include Vedeu::DSL::Use
75
78
 
76
- # Specify the geometry of an interface or view with a simple DSL.
79
+ # Specify the geometry of an interface or view with a simple
80
+ # DSL.
77
81
  #
78
82
  # Vedeu.geometry 'some_interface' do
79
83
  # # ...
80
84
  # end
81
85
  #
82
- # @param name [String] The name of the interface or view to which this
83
- # geometry belongs.
86
+ # @param name [String] The name of the interface or view to
87
+ # which this geometry belongs.
84
88
  # @param block [Proc]
85
- # @raise [Vedeu::Error::InvalidSyntax] The required block was not given.
89
+ # @raise [Vedeu::Error::RequiresBlock]
86
90
  # @return [Vedeu::Geometry::Geometry]
87
91
  def self.geometry(name, &block)
88
- fail Vedeu::Error::InvalidSyntax, 'block not given' unless block_given?
92
+ fail Vedeu::Error::RequiresBlock unless block_given?
89
93
 
90
94
  Vedeu::Geometry::Geometry.build(name: name, &block).store
91
95
  end
@@ -100,8 +104,9 @@ module Vedeu
100
104
  @client = client
101
105
  end
102
106
 
103
- # Instructs Vedeu to calculate x and y geometry automatically based on the
104
- # centre character of the terminal, the width and the height.
107
+ # Instructs Vedeu to calculate x and y geometry automatically
108
+ # based on the centre character of the terminal, the width and
109
+ # the height.
105
110
  #
106
111
  # Vedeu.geometry 'some_interface' do
107
112
  # centred false # or...
@@ -111,8 +116,8 @@ module Vedeu
111
116
  # # ... some code
112
117
  # end
113
118
  #
114
- # @param value [Boolean] Any value other than nil or false will evaluate
115
- # to true.
119
+ # @param value [Boolean] Any value other than nil or false will
120
+ # evaluate to true.
116
121
  # @return [Boolean]
117
122
  def centred(value = true)
118
123
  boolean = value ? true : false
@@ -122,7 +127,8 @@ module Vedeu
122
127
  alias_method :centred!, :centred
123
128
  alias_method :centred=, :centred
124
129
 
125
- # Returns the width in characters for the number of columns specified.
130
+ # Returns the width in characters for the number of columns
131
+ # specified.
126
132
  #
127
133
  # Vedeu.geometry 'main_interface' do
128
134
  # # ... some code
@@ -133,15 +139,15 @@ module Vedeu
133
139
  # end
134
140
  #
135
141
  # @param value [Fixnum]
136
- # @raise [Vedeu::Error::OutOfRange] When the value parameter is not
137
- # between 1 and 12 inclusive.
142
+ # @raise [Vedeu::Error::OutOfRange] When the value parameter is
143
+ # not between 1 and 12 inclusive.
138
144
  # @return [Fixnum|Vedeu::Error::OutOfRange]
139
145
  def columns(value)
140
146
  Vedeu::Geometry::Grid.columns(value)
141
147
  end
142
148
 
143
- # Specify the number of characters/rows/lines tall the interface will be.
144
- # This value will be ignored when `y` and `yn` are set.
149
+ # Specify the number of characters/rows/lines tall the interface
150
+ # will be. This value will be ignored when `y` and `yn` are set.
145
151
  #
146
152
  # Vedeu.geometry 'some_interface' do
147
153
  # height 8
@@ -155,7 +161,8 @@ module Vedeu
155
161
  end
156
162
  alias_method :height=, :height
157
163
 
158
- # Returns the height in characters for the number of rows specified.
164
+ # Returns the height in characters for the number of rows
165
+ # specified.
159
166
  #
160
167
  # Vedeu.geometry 'main_interface' do
161
168
  # # ... some code
@@ -166,15 +173,15 @@ module Vedeu
166
173
  # end
167
174
  #
168
175
  # @param value [Fixnum]
169
- # @raise [Vedeu::Error::OutOfRange] When the value parameter is not
170
- # between 1 and 12 inclusive.
176
+ # @raise [Vedeu::Error::OutOfRange] When the value parameter is
177
+ # not between 1 and 12 inclusive.
171
178
  # @return [Fixnum]
172
179
  def rows(value)
173
180
  Vedeu::Geometry::Grid.rows(value)
174
181
  end
175
182
 
176
- # Specify the number of characters/columns wide the interface will be.
177
- # This value will be ignored when `x` and `xn` are set.
183
+ # Specify the number of characters/columns wide the interface
184
+ # will be. This value will be ignored when `x` and `xn` are set.
178
185
  #
179
186
  # Vedeu.geometry 'some_interface' do
180
187
  # width 25
@@ -193,10 +200,11 @@ module Vedeu
193
200
  # Vedeu.geometry 'some_interface' do
194
201
  # x 7 # start on column 7.
195
202
  #
196
- # x { use('other_interface').east } # start on column 8, if
197
- # # ... some code # `other_interface` changes
198
- # end # position, `some_interface` will
199
- # # too.
203
+ # # start on column 8, if `other_interface` changes position
204
+ # # then `some_interface` will too.
205
+ # x { use('other_interface').east }
206
+ # # ... some code
207
+ # end
200
208
  #
201
209
  # @param value [Fixnum]
202
210
  # @param block [Proc]
@@ -214,9 +222,10 @@ module Vedeu
214
222
  # Vedeu.geometry 'some_interface' do
215
223
  # xn 37 # end at column 37.
216
224
  #
217
- # xn { use('other_interface').right } # when `other_interface`
218
- # # changes position,
219
- # # ... some code # `some_interface` will too.
225
+ # # when `other_interface` changes position,
226
+ # # `some_interface` will too.
227
+ # xn { use('other_interface').right }
228
+ # # ... some code
220
229
  # end
221
230
  #
222
231
  # @param value [Fixnum]
@@ -234,10 +243,11 @@ module Vedeu
234
243
  # Vedeu.geometry 'some_interface' do
235
244
  # y 4 # start at row 4
236
245
  #
237
- # y { use('other_interface').north } # start on row/line 3, when
238
- # # ... some code # `other_interface` changes
239
- # end # position, `some_interface`
240
- # # will too.
246
+ # # start on row/line 3, when `other_interface` changes
247
+ # # position, `some_interface` will too.
248
+ # y { use('other_interface').north }
249
+ # # ... some code
250
+ # end
241
251
  #
242
252
  # @param value [Fixnum]
243
253
  # @param block [Proc]
@@ -255,9 +265,11 @@ module Vedeu
255
265
  # Vedeu.geometry 'some_interface' do
256
266
  # yn 24 # end at row 24.
257
267
  #
258
- # yn { use('other_interface').bottom } # if `other_interface` changes
259
- # # ... some code # position, `some_interface`
260
- # end # will too.
268
+ # # if `other_interface` changes position, `some_interface`
269
+ # # will too.
270
+ # yn { use('other_interface').bottom }
271
+ # # ... some code
272
+ # end
261
273
  #
262
274
  # @param value [Fixnum]
263
275
  # @param block [Proc]
@@ -113,10 +113,11 @@ module Vedeu
113
113
  border.send(coordinate_type[3])
114
114
  end
115
115
 
116
- # Ascertain the correct methods to use for determining the coordinates.
116
+ # Ascertain the correct methods to use for determining the
117
+ # coordinates.
117
118
  #
118
- # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type is not
119
- # given.
119
+ # @raise [Vedeu::Error::InvalidSyntax] When the coordinate type
120
+ # is not given.
120
121
  # @return [Fixnum]
121
122
  def coordinate_type
122
123
  @_type ||= case type