vedeu 0.5.9 → 0.5.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d9f471ab14ab7f5b69de2e0b0c250002f3f1775a
4
- data.tar.gz: 471ca4b7ef85a507cf71c0fa64e11844e464f7b0
3
+ metadata.gz: 1096fd3f0f65d843b0f6f92e4b70a721570f15da
4
+ data.tar.gz: 808dc9b634727f33c20aa32712e2d6066c759b4d
5
5
  SHA512:
6
- metadata.gz: 9e68cd9602da230d9b4c38efabaa2c8368d0e2659b6e3d1cbdf2a64522d81d5b5373b48c92ab9e9a86e6631b5fffedadaf1fecc7e3d8f5fc7795b98c4bd9f9db
7
- data.tar.gz: d7981f0948f3d7b0521d5cac304deee8f7282601a4c5d71961cd76381e5be7e2c569499292872d5fd94c2c45013c939871584f5e017c6667c8fbed5d2409dc1b
6
+ metadata.gz: 8cd549653f68705952718d30bd75d653cb17215dd2c30cd7fdbc407e933bb1a831f19f74da3e567c8fa4d610a93f2f93cf9a1ebf4c377a0b468816b8159d0fc9
7
+ data.tar.gz: 328c6e794c5387531e94a13bc3be5b30facb61697cd531fed4481214b8b56016b3c8aa7e96ec95182319a0577c63af1e96e12b23a344fd38cc4b53f205ae829f
@@ -33,6 +33,7 @@ class VedeuMaterialColoursApp
33
33
  border 'main_interface' do
34
34
  colour foreground: '#ffffff', background: :default
35
35
  title 'Rainbow!'
36
+ caption('Unicorns!')
36
37
  end
37
38
  colour foreground: '#ffffff', background: :default
38
39
  cursor!
@@ -53,6 +54,7 @@ class VedeuMaterialColoursApp
53
54
  border 'other_interface' do
54
55
  colour(foreground: '#ffffff', background: :default)
55
56
  title('Wow!')
57
+ caption('Shiny!')
56
58
  horizontal('-')
57
59
  top_right('+')
58
60
  top_left('+')
@@ -31,12 +31,14 @@ module Vedeu
31
31
  # Vedeu.trigger(:_drb_input_, data, type)
32
32
  #
33
33
  # @return [TrueClass]
34
+ # @see Vedeu::Distributed::Server#input
34
35
  def drb_input!
35
36
  Vedeu.bind(:_drb_input_) do |data, type|
36
37
  Vedeu.log(type: :drb, message: "Sending input (#{type})")
37
38
 
38
39
  case type
39
- when :command then Vedeu.trigger(:_command_, data)
40
+ when :command then Vedeu.trigger(:_command_, data)
41
+ when :keypress then Vedeu.trigger(:_keypress_, data)
40
42
  else Vedeu.trigger(:_keypress_, data)
41
43
  end
42
44
  end
@@ -59,6 +59,10 @@ module Vedeu
59
59
  attr_accessor :show_top
60
60
  alias_method :top?, :show_top
61
61
 
62
+ # @!attribute [rw] caption
63
+ # @return [String]
64
+ attr_accessor :caption
65
+
62
66
  # @!attribute [rw] title
63
67
  # @return [String]
64
68
  attr_accessor :title
@@ -105,8 +109,10 @@ module Vedeu
105
109
  # is to be shown.
106
110
  # @option attributes show_top [Boolean] Indicate whether the top border is
107
111
  # to be shown.
108
- # @option attributes title [String] A title bar for when the top border is
109
- # to be shown.
112
+ # @option attributes title [String] An optional title for when the top
113
+ # border is to be shown.
114
+ # @option attributes caption [String] An optional caption for when the
115
+ # bottom border is to be shown.
110
116
  # @option attributes top_left [String] The top left border character.
111
117
  # @option attributes top_right [String] The top right border character.
112
118
  # @option attributes vertical [String] The vertical border character.
@@ -179,6 +185,7 @@ module Vedeu
179
185
  {
180
186
  bottom_left: Vedeu::EscapeSequences::Borders.bottom_left,
181
187
  bottom_right: Vedeu::EscapeSequences::Borders.bottom_right,
188
+ caption: '',
182
189
  client: nil,
183
190
  colour: nil,
184
191
  enabled: false,
@@ -15,6 +15,7 @@ module Vedeu
15
15
  :bxn,
16
16
  :by,
17
17
  :byn,
18
+ :caption,
18
19
  :colour,
19
20
  :enabled?,
20
21
  :height,
@@ -117,11 +118,16 @@ module Vedeu
117
118
 
118
119
  # Renders the bottom border for the interface.
119
120
  #
121
+ # @note
122
+ # If a caption has been specified, then the bottom border will include
123
+ # this caption unless the size of the interface is smaller than the padded
124
+ # caption length.
125
+ #
120
126
  # @return [String]
121
127
  def bottom
122
128
  return [] unless bottom?
123
129
 
124
- [build_bottom_left, build_bottom, build_bottom_right].compact
130
+ [build_bottom_left, captionbar, build_bottom_right].compact
125
131
  end
126
132
 
127
133
  # @return [Vedeu::Geometry]
@@ -180,8 +186,27 @@ module Vedeu
180
186
  [build_top_left, titlebar, build_top_right].compact
181
187
  end
182
188
 
183
- # From the second element of {#title_characters} remove the border from each
184
- # {#build_horizontal} Vedeu::Views::Char, and add the title character.
189
+ # Overwrite the border from {#build_horizontal} on the bottom border to
190
+ # include the caption if given.
191
+ #
192
+ # @return [Array<Vedeu::Views::Char>]
193
+ def captionbar
194
+ return build_bottom unless caption? && caption_fits?
195
+
196
+ caption_starts_at = (width - caption_characters.size) - 2
197
+
198
+ caption_char = 0
199
+ build_bottom.each_with_index do |char, index|
200
+ next if index <= caption_starts_at || index > (width - 2)
201
+
202
+ char.border = nil
203
+ char.value = caption_characters[caption_char]
204
+ caption_char += 1
205
+ end
206
+ end
207
+
208
+ # Overwrite the border from {#build_horizontal} on the top border to
209
+ # include the title if given.
185
210
  #
186
211
  # @return [Array<Vedeu::Views::Char>]
187
212
  def titlebar
@@ -202,6 +227,13 @@ module Vedeu
202
227
  present?(title)
203
228
  end
204
229
 
230
+ # Return boolean indicating whether this border has a non-empty caption.
231
+ #
232
+ # @return [Boolean]
233
+ def caption?
234
+ present?(caption)
235
+ end
236
+
205
237
  # Return boolean indicating whether the title fits within the width of the
206
238
  # top border.
207
239
  #
@@ -210,11 +242,24 @@ module Vedeu
210
242
  width > title_characters.size
211
243
  end
212
244
 
245
+ # Return boolean indicating whether the caption fits within the width of the
246
+ # bottom border.
247
+ #
248
+ # @return [Boolean]
249
+ def caption_fits?
250
+ width > caption_characters.size
251
+ end
252
+
213
253
  # @return [Array<String>]
214
254
  def title_characters
215
255
  @title_characters ||= title_padded.chars
216
256
  end
217
257
 
258
+ # @return [Array<String>]
259
+ def caption_characters
260
+ @caption_characters ||= caption_padded.chars
261
+ end
262
+
218
263
  # Pads the title with a single whitespace either side.
219
264
  #
220
265
  # @example
@@ -231,6 +276,22 @@ module Vedeu
231
276
  truncated_title.center(truncated_title.size + 2)
232
277
  end
233
278
 
279
+ # Pads the caption with a single whitespace either side.
280
+ #
281
+ # @example
282
+ # caption = 'Truncated!'
283
+ # width = 20
284
+ # # => ' Truncated! '
285
+ #
286
+ # width = 10
287
+ # # => ' Trunca '
288
+ #
289
+ # @return [String]
290
+ # @see #truncated_caption
291
+ def caption_padded
292
+ truncated_caption.center(truncated_caption.size + 2)
293
+ end
294
+
234
295
  # Truncates the title to the width of the interface, minus characters needed
235
296
  # to ensure there is at least a single character of horizontal border and a
236
297
  # whitespace on either side of the title.
@@ -248,6 +309,23 @@ module Vedeu
248
309
  title.chomp.slice(0..(width - 5))
249
310
  end
250
311
 
312
+ # Truncates the caption to the width of the interface, minus characters
313
+ # needed to ensure there is at least a single character of horizontal border
314
+ # and a whitespace on either side of the caption.
315
+ #
316
+ # @example
317
+ # caption = 'Truncated!'
318
+ # width = 20
319
+ # # => 'Truncated!'
320
+ #
321
+ # width = 10
322
+ # # => 'Trunca'
323
+ #
324
+ # @return [String]
325
+ def truncated_caption
326
+ caption.chomp.slice(0..(width - 5))
327
+ end
328
+
251
329
  end # RenderBorder
252
330
 
253
331
  end # Vedeu
@@ -61,8 +61,10 @@ module Vedeu
61
61
 
62
62
  end # Eigenclass
63
63
 
64
- # @param data [String|Symbol]
65
- # @param type [Symbol] Either :keypress or :command.
64
+ # @param data [String|Symbol] The input to send to Vedeu.
65
+ # @param type [Symbol] Either :command or :keypress. Will trigger the
66
+ # respective capture mode within {Vedeu::Input}, or if not given, will
67
+ # treat the data as a keypress.
66
68
  # @return [void]
67
69
  def input(data, type = :keypress)
68
70
  Vedeu.trigger(:_drb_input_, data, type)
@@ -261,6 +261,23 @@ module Vedeu
261
261
  model.title = value
262
262
  end
263
263
 
264
+ # If you have you are showing a bottom border, you could add a caption.
265
+ #
266
+ # Vedeu.border 'border_demo' do
267
+ # caption 'My Cool Caption'
268
+ # # ... some code
269
+ # end
270
+ #
271
+ # produces, depending on other customisations:
272
+ #
273
+ # +------------------------------ My Cool Caption -+
274
+ #
275
+ # @param value [String] The caption.
276
+ # @return [String]
277
+ def caption(value)
278
+ model.caption = value
279
+ end
280
+
264
281
  # Enable/disable the top border.
265
282
  #
266
283
  # Vedeu.border 'border_demo' do
@@ -34,6 +34,15 @@ module Vedeu
34
34
  # # ... some code
35
35
  # end
36
36
  #
37
+ # or more succinctly:
38
+ #
39
+ # Vedeu.group 'main_screen' do
40
+ # members 'editor_interface', 'status_interface', 'command_interface'
41
+ # # ... some code
42
+ # end
43
+ #
44
+ # or when defining an interface:
45
+ #
37
46
  # Vedeu.interface 'some_interface' do
38
47
  # group 'some_group'
39
48
  # # ... some code
@@ -66,11 +75,23 @@ module Vedeu
66
75
  # end
67
76
  #
68
77
  # @param interface_name [String]
69
- # @return [void]
78
+ # @return [Vedeu::Group]
70
79
  def add(interface_name)
71
80
  model.add(interface_name)
72
81
  end
73
82
 
83
+ # Add the named interfaces to this group in bulk.
84
+ #
85
+ # Vedeu.group 'main_screen' do
86
+ # members ['editor_interface', 'some_interface', 'other_interface']
87
+ # end
88
+ #
89
+ # @param interface_names [Array<String>]
90
+ # @return [Array<String>]
91
+ def members(*interface_names)
92
+ interface_names.each { |name| add(name) }
93
+ end
94
+
74
95
  end # Group
75
96
 
76
97
  end # DSL
@@ -6,15 +6,13 @@ module Vedeu
6
6
 
7
7
  extend Forwardable
8
8
 
9
- def_delegators :border,
10
- :bx,
11
- :bxn,
12
- :by,
13
- :byn,
14
- :height,
15
- :width,
16
- :x,
17
- :y
9
+ def_delegators :x,
10
+ :x_position,
11
+ :xn
12
+
13
+ def_delegators :y,
14
+ :y_position,
15
+ :yn
18
16
 
19
17
  # Returns a new instance of Vedeu::Coordinate.
20
18
  #
@@ -28,87 +26,87 @@ module Vedeu
28
26
  @oy = oy
29
27
  end
30
28
 
31
- # Returns the maximum y coordinate for an area.
29
+ private
30
+
31
+ # Provide an instance of Vedeu::GenericCoordinate to determine correct x
32
+ # related coordinates.
32
33
  #
33
- # @example
34
- # # y = 2
35
- # # height = 4
36
- # yn # => 6
34
+ # @return [Vedeu::GenericCoordinate]
35
+ def x
36
+ @x ||= Vedeu::GenericCoordinate.new(name: @name, offset: @ox, type: :x)
37
+ end
38
+
39
+ # Provide an instance of Vedeu::GenericCoordinate to determine correct y
40
+ # related coordinates.
37
41
  #
38
- # @return [Fixnum]
39
- def yn
40
- if height <= 0
41
- 0
42
+ # @return [Vedeu::GenericCoordinate]
43
+ def y
44
+ @y ||= Vedeu::GenericCoordinate.new(name: @name, offset: @oy, type: :y)
45
+ end
42
46
 
43
- else
44
- y + height
47
+ end # Coordinate
45
48
 
46
- end
49
+ # Crudely corrects out of range values.
50
+ #
51
+ class GenericCoordinate
52
+
53
+ # Return a new instance of Vedeu::GenericCoordinate.
54
+ #
55
+ # @param attributes [Hash]
56
+ # @option attributes name [String]
57
+ # @option attributes type [Symbol]
58
+ # @option attributes offset [Fixnum]
59
+ # @return [Vedeu::GenericCoordinate]
60
+ def initialize(attributes = {})
61
+ @attributes = defaults.merge!(attributes)
62
+
63
+ @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
47
64
  end
48
65
 
49
- # Returns the maximum x coordinate for an area.
66
+ # Returns the maximum coordinate for an area.
50
67
  #
51
68
  # @example
52
- # # x = 5
53
- # # width = 20
54
- # xn # => 25
69
+ # # d = 2
70
+ # # d_dn = 4
71
+ # dn # => 6
55
72
  #
56
73
  # @return [Fixnum]
57
- def xn
58
- if width <= 0
74
+ def dn
75
+ if d_dn <= 0
59
76
  0
60
77
 
61
78
  else
62
- x + width
79
+ d + d_dn
63
80
 
64
81
  end
65
82
  end
83
+ alias_method :xn, :dn
84
+ alias_method :yn, :dn
66
85
 
67
- # Returns the y coordinate for a given index.
68
- #
69
- # @example
70
- # # y_range = [7, 8, 9, 10, 11]
71
- # y_position # => 7
72
- # y_position(-2) # => 7
73
- # y_position(2) # => 9
74
- # y_position(7) # => 11
75
- #
76
- # @return [Fixnum]
77
- def y_position
78
- pos = case
79
- when oy <= 0 then y
80
- when oy > yn_index then yn
81
- else
82
- y_range[oy]
83
- end
84
-
85
- pos = pos < by ? by : pos
86
- pos = pos > byn ? byn : pos
87
- pos
88
- end
89
-
90
- # Returns the x coordinate for a given index.
86
+ # Returns the coordinate for a given index.
91
87
  #
92
88
  # @example
93
- # # x_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
94
- # x_position # => 4
95
- # x_position(-2) # => 4
96
- # x_position(2) # => 6
97
- # x_position(15) # => 13
89
+ # # d_range = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
90
+ # position # => 4
91
+ # position(-2) # => 4
92
+ # position(2) # => 6
93
+ # position(15) # => 13
98
94
  #
99
95
  # @return [Fixnum]
100
- def x_position
96
+ def position
101
97
  pos = case
102
- when ox <= 0 then x
103
- when ox > xn_index then xn
98
+ when offset <= 0 then d
99
+ when offset > dn_index then dn
104
100
  else
105
- x_range[ox]
101
+ d_range[offset]
106
102
  end
107
103
 
108
- pos = pos < bx ? bx : pos
109
- pos = pos > bxn ? bxn : pos
104
+ pos = pos < bd ? bd : pos
105
+ pos = pos > bdn ? bdn : pos
110
106
  pos
111
107
  end
108
+ alias_method :x_position, :position
109
+ alias_method :y_position, :position
112
110
 
113
111
  protected
114
112
 
@@ -116,13 +114,13 @@ module Vedeu
116
114
  # @return [String]
117
115
  attr_reader :name
118
116
 
119
- # @!attribute [r] oy
117
+ # @!attribute [r] offset
120
118
  # @return [Fixnum]
121
- attr_reader :oy
119
+ attr_reader :offset
122
120
 
123
- # @!attribute [r] ox
124
- # @return [Fixnum]
125
- attr_reader :ox
121
+ # @!attribute [r] type
122
+ # @return [Symbol]
123
+ attr_reader :type
126
124
 
127
125
  private
128
126
 
@@ -131,66 +129,88 @@ module Vedeu
131
129
  @border ||= Vedeu.borders.by_name(name)
132
130
  end
133
131
 
134
- # Returns the maximum y index for an area.
132
+ # Return the :x or :y value from the border.
135
133
  #
136
- # @example
137
- # # height = 3
138
- # yn_index # => 2
134
+ # @return [Fixnum]
135
+ def d
136
+ border.send(coordinate_type[0])
137
+ end
138
+
139
+ # Return the :bx or :by value from the border.
139
140
  #
140
141
  # @return [Fixnum]
141
- def yn_index
142
- if height < 1
143
- 0
142
+ def bd
143
+ border.send(coordinate_type[1])
144
+ end
144
145
 
145
- else
146
- height - 1
146
+ # Return the :bxn or :byn value from the border.
147
+ #
148
+ # @return [Fixnum]
149
+ def bdn
150
+ border.send(coordinate_type[2])
151
+ end
147
152
 
148
- end
153
+ # Return the :width or :height value from the border.
154
+ #
155
+ # @return [Fixnum]
156
+ def d_dn
157
+ border.send(coordinate_type[3])
158
+ end
159
+
160
+ # Ascertain the correct methods to use for determining the coordinates.
161
+ #
162
+ # @return [Fixnum]
163
+ def coordinate_type
164
+ @_type ||= case type
165
+ when :x then [:x, :bx, :bxn, :width]
166
+ when :y then [:y, :by, :byn, :height]
167
+ else
168
+ fail Vedeu::InvalidSyntax,
169
+ 'Coordinate type not given, cannot continue.'
170
+ end
149
171
  end
150
172
 
151
- # Returns the maximum x index for an area.
173
+ # Returns the maximum index for an area.
152
174
  #
153
175
  # @example
154
- # # width = 6
155
- # xn_index # => 5
176
+ # # d_dn = 3
177
+ # dn_index # => 2
156
178
  #
157
179
  # @return [Fixnum]
158
- def xn_index
159
- if width < 1
180
+ def dn_index
181
+ if d_dn < 1
160
182
  0
161
183
 
162
184
  else
163
- width - 1
185
+ d_dn - 1
164
186
 
165
187
  end
166
188
  end
167
189
 
168
- # Returns an array with all coordinates from x to xn.
190
+ # Returns an array with all coordinates from d to dn.
169
191
  #
170
192
  # @example
171
- # # width = 10
172
- # # x = 4
173
- # # xn = 14
174
- # x_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
193
+ # # d_dn = 10
194
+ # # d = 4
195
+ # # dn = 14
196
+ # d_range # => [4, 5, 6, 7, 8, 9, 10, 11, 12, 13]
175
197
  #
176
198
  # @return [Array]
177
- def x_range
178
- (x...xn).to_a
199
+ def d_range
200
+ (d...dn).to_a
179
201
  end
180
202
 
181
- # Returns an array with all coordinates from y to yn.
182
- #
183
- # @example
184
- # # height = 4
185
- # # y = 7
186
- # # yn = 11
187
- # y_range # => [7, 8, 9, 10]
203
+ # The default values for a new instance of this class.
188
204
  #
189
- # @return [Array]
190
- def y_range
191
- (y...yn).to_a
205
+ # @return [Hash]
206
+ def defaults
207
+ {
208
+ name: '',
209
+ offset: nil,
210
+ type: :x,
211
+ }
192
212
  end
193
213
 
194
- end # Coordinate
214
+ end # GenericCoordinate
195
215
 
196
216
  end # Vedeu
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.5.9'
4
+ VERSION = '0.5.10'
5
5
 
6
6
  end
@@ -10,6 +10,7 @@ module Vedeu
10
10
  {
11
11
  bottom_left: 'm',
12
12
  bottom_right: 'j',
13
+ caption: '',
13
14
  client: nil,
14
15
  colour: nil,
15
16
  enabled: false,
@@ -56,6 +57,8 @@ module Vedeu
56
57
  it { instance.must_respond_to(:bottom_left=) }
57
58
  it { instance.must_respond_to(:bottom_right) }
58
59
  it { instance.must_respond_to(:bottom_right=) }
60
+ it { instance.must_respond_to(:caption) }
61
+ it { instance.must_respond_to(:caption=) }
59
62
  it { instance.must_respond_to(:horizontal) }
60
63
  it { instance.must_respond_to(:horizontal=) }
61
64
  it { instance.must_respond_to(:show_bottom) }
@@ -176,6 +176,15 @@ module Vedeu
176
176
  it { subject.must_equal('Some title') }
177
177
  end
178
178
 
179
+ describe '#caption' do
180
+ let(:_value) { 'Some caption'}
181
+
182
+ subject { instance.caption(_value) }
183
+
184
+ it { subject.must_be_instance_of(String) }
185
+ it { subject.must_equal('Some caption') }
186
+ end
187
+
179
188
  describe '#top_left' do
180
189
  let(:char) { 'A' }
181
190
 
@@ -47,6 +47,22 @@ module Vedeu
47
47
  it { subject.members.must_equal(Set['editor_interface']) }
48
48
  end
49
49
 
50
+ describe '#members' do
51
+ let(:expected) {
52
+ Set['editor_interface', 'some_interface', 'other_interface']
53
+ }
54
+
55
+ subject {
56
+ described.group(group_name) do
57
+ members('editor_interface', 'some_interface', 'other_interface')
58
+ end
59
+ }
60
+
61
+ it { subject.must_be_instance_of(Vedeu::Group) }
62
+
63
+ it { subject.members.must_equal(expected) }
64
+ end
65
+
50
66
  end # Group
51
67
 
52
68
  describe 'integration' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.9
4
+ version: 0.5.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-10 00:00:00.000000000 Z
11
+ date: 2015-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard