vedeu 0.6.62 → 0.6.63

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: 161b51ae0f6dddf89fe026875fa21b5bcbef0b63
4
- data.tar.gz: f724c3d3b35f703f2ba58800123628837fd7a8fa
3
+ metadata.gz: 62cdfdd3391cb52b378f21160f57a5f0b1bd7792
4
+ data.tar.gz: 1253650d2091f8d085a6ba99cfb6e035aae658e8
5
5
  SHA512:
6
- metadata.gz: 66121dcb5d8c27bc23a7ec695a2eecf360dfe0946f7f0cb3cf85eb39682f6a0a683d14328987e3858807a8a3fbf75c3a440565ad0aa39c80d76eea9eea263396
7
- data.tar.gz: c21adb2837c843bbb19a8b60ced2f19fa76835417ed86a15f769153c9e212f5a8b98133a5cf47446a4ab1a212971bff37321f360c2697f7849f258abece2654b
6
+ metadata.gz: 2cfc8ed0ff83a941c2692d1d68ea36cfd9e4022b6796efefd9b254942cc947dd29b9267090c9ddb625948edbff56074c9a7268c9339dd30ca3ab86121c52ef06
7
+ data.tar.gz: 3a6780083ee0f2b053aaa8dd3450173c53b0020e7909753141b8d8d6660258a6d413d91747670e2c5efca3a76fbaec2be319e851f2b5860094352edcc0b5c560
data/.rubocop.yml CHANGED
@@ -124,7 +124,7 @@ Style/TrailingComma:
124
124
  Metrics/AbcSize:
125
125
  # The ABC size is a calculated magnitude, so this number can be a Fixnum or
126
126
  # a Float.
127
- Max: 20
127
+ Max: 25
128
128
 
129
129
  Metrics/BlockNesting:
130
130
  Max: 3
@@ -10,6 +10,31 @@ module Vedeu
10
10
  #
11
11
  class Caption < Title
12
12
 
13
+ # Overwrite the border from {#build_horizontal} on the bottom
14
+ # border to include the caption if given.
15
+ #
16
+ # @param [Array<Vedeu::Views::Char>]
17
+ # @return [Array<Vedeu::Views::Char>]
18
+ def render
19
+ return chars if empty?
20
+
21
+ caption_index = 0
22
+ chars.each_with_index do |char, index|
23
+ next if index <= start_index || index > (width - 4)
24
+
25
+ char.border = nil
26
+ char.value = characters[caption_index]
27
+ caption_index += 1
28
+ end
29
+ end
30
+
31
+ private
32
+
33
+ # @return [Fixnum]
34
+ def start_index
35
+ (width - size) - 4
36
+ end
37
+
13
38
  end # Caption
14
39
 
15
40
  end # Borders
@@ -97,18 +97,6 @@ module Vedeu
97
97
  end
98
98
  end
99
99
 
100
- # @return [Vedeu::Borders::Caption] An optional caption for when
101
- # the bottom border is to be shown.
102
- def render_caption
103
- @_caption ||= Vedeu::Borders::Caption.coerce(caption, width)
104
- end
105
-
106
- # @return [Vedeu::Borders::Title] An optional title for when the
107
- # top border is to be shown.
108
- def render_title
109
- @_title ||= Vedeu::Borders::Title.coerce(title, width)
110
- end
111
-
112
100
  # @param value [String]
113
101
  # @param type [Symbol|NilClass]
114
102
  # @param iy [Fixnum]
@@ -242,38 +230,25 @@ module Vedeu
242
230
  [build_top_left, titlebar, build_top_right].compact
243
231
  end
244
232
 
245
- # Overwrite the border from {#build_horizontal} on the bottom
246
- # border to include the caption if given.
233
+ # An optional caption for when the bottom border is to be shown.
247
234
  #
248
235
  # @return [Array<Vedeu::Views::Char>]
236
+ # @see [Vedeu::Borders::Caption#render]
249
237
  def captionbar
250
- return build_bottom if render_caption.empty?
251
-
252
- caption_starts_at = (width - render_caption.size) - 2
238
+ return nil unless caption
253
239
 
254
- caption_index = 0
255
- build_bottom.each_with_index do |char, index|
256
- next if index <= caption_starts_at || index > (width - 2)
257
-
258
- char.border = nil
259
- char.value = render_caption.characters[caption_index]
260
- caption_index += 1
261
- end
240
+ @_caption ||= Vedeu::Borders::Caption
241
+ .render(caption, width, build_bottom)
262
242
  end
263
243
 
264
- # Overwrite the border from {#build_horizontal} on the top
265
- # border to include the title if given.
244
+ # An optional title for when the top border is to be shown.
266
245
  #
267
246
  # @return [Array<Vedeu::Views::Char>]
247
+ # @see [Vedeu::Borders::Title#render]
268
248
  def titlebar
269
- return build_top if render_title.empty?
249
+ return nil unless title
270
250
 
271
- build_top.each_with_index do |char, index|
272
- next if index == 0 || index > render_title.size
273
-
274
- char.border = nil
275
- char.value = render_title.characters[index - 1]
276
- end
251
+ @_title ||= Vedeu::Borders::Title.render(title, width, build_top)
277
252
  end
278
253
 
279
254
  end # Refresh
@@ -14,40 +14,22 @@ module Vedeu
14
14
  # Vedeu::Borders::Caption]
15
15
  # @param width [Fixnum]
16
16
  # @return [Vedeu::Borders::Title|Vedeu::Borders::Caption]
17
- def self.coerce(value = '', width = Vedeu.width)
18
- if value.is_a?(self)
19
- value
20
-
21
- else
22
- new(value, width)
23
-
24
- end
17
+ def self.render(value = '', width = Vedeu.width, chars = [])
18
+ new(value, width, chars).render
25
19
  end
26
20
 
27
21
  # Returns a new instance of Vedeu::Borders::Title or
28
22
  # Vedeu::Borders::Caption.
29
23
  #
24
+ # @param chars [Array<Vedeu::Views::Char>]
30
25
  # @param value [String|Vedeu::Borders::Title|
31
26
  # Vedeu::Borders::Caption]
32
27
  # @param width [Fixnum]
33
28
  # @return [Vedeu::Borders::Title|Vedeu::Borders::Caption]
34
- def initialize(value = '', width = Vedeu.width)
29
+ def initialize(value = '', width = Vedeu.width, chars = [])
35
30
  @value = value
36
31
  @width = width
37
- end
38
-
39
- # Return the padded, truncated value as an Array of String.
40
- #
41
- # @return [Array<String>]
42
- def characters
43
- pad.chars
44
- end
45
-
46
- # Return boolean indicating whether the value is empty.
47
- #
48
- # @return [Boolean]
49
- def empty?
50
- value.empty?
32
+ @chars = chars
51
33
  end
52
34
 
53
35
  # An object is equal when its values are the same.
@@ -59,11 +41,20 @@ module Vedeu
59
41
  end
60
42
  alias_method :==, :eql?
61
43
 
62
- # Return the size of the padded, truncated value.
44
+ # Overwrite the border from {#build_horizontal} on the top
45
+ # border to include the title if given.
63
46
  #
64
- # @return [Fixnum]
65
- def size
66
- pad.size
47
+ # @param [Array<Vedeu::Views::Char>]
48
+ # @return [Array<Vedeu::Views::Char>]
49
+ def render
50
+ return chars if empty?
51
+
52
+ chars.each_with_index do |char, index|
53
+ next if index == start_index || index > size
54
+
55
+ char.border = nil
56
+ char.value = characters[index - 1]
57
+ end
67
58
  end
68
59
 
69
60
  # Convert the value to a string.
@@ -82,8 +73,28 @@ module Vedeu
82
73
  alias_method :title, :value
83
74
  alias_method :caption, :value
84
75
 
76
+ protected
77
+
78
+ # @!attribute [r] chars
79
+ # @return [Array<Vedeu::Views::Char>]
80
+ attr_reader :chars
81
+
85
82
  private
86
83
 
84
+ # Return the padded, truncated value as an Array of String.
85
+ #
86
+ # @return [Array<String>]
87
+ def characters
88
+ pad.chars
89
+ end
90
+
91
+ # Return boolean indicating whether the value is empty.
92
+ #
93
+ # @return [Boolean]
94
+ def empty?
95
+ value.empty?
96
+ end
97
+
87
98
  # Pads the value with a single whitespace either side.
88
99
  #
89
100
  # @example
@@ -100,6 +111,18 @@ module Vedeu
100
111
  truncate.center(truncate.size + 2)
101
112
  end
102
113
 
114
+ # Return the size of the padded, truncated value.
115
+ #
116
+ # @return [Fixnum]
117
+ def size
118
+ pad.size
119
+ end
120
+
121
+ # @return [Fixnum]
122
+ def start_index
123
+ 0
124
+ end
125
+
103
126
  # Truncates the value to the width of the interface, minus
104
127
  # characters needed to ensure there is at least a single
105
128
  # character of horizontal border and a whitespace on either side
@@ -115,7 +115,9 @@ module Vedeu
115
115
  Vedeu.bind(:_drb_retrieve_output_) { Vedeu::Buffers::Terminal.output }
116
116
 
117
117
  # @see Vedeu::Buffers::Terminal#write
118
- Vedeu.bind(:_drb_store_output_) { |data| Vedeu::Buffers::Terminal.write(data) }
118
+ Vedeu.bind(:_drb_store_output_) do |data|
119
+ Vedeu::Buffers::Terminal.write(data)
120
+ end
119
121
 
120
122
  # :nocov:
121
123
 
@@ -186,7 +186,13 @@ module Vedeu
186
186
  # @return [String]
187
187
  def rgb
188
188
  if Vedeu::Configuration.colour_mode == 16_777_216
189
- register(colour, format(rgb_prefix, *css_to_rgb))
189
+ if registered?(colour)
190
+ retrieve(colour)
191
+
192
+ else
193
+ register(colour, format(rgb_prefix, *css_to_rgb))
194
+
195
+ end
190
196
 
191
197
  else
192
198
  numbered
@@ -85,6 +85,12 @@ module Vedeu
85
85
  end
86
86
  alias_method :==, :eql?
87
87
 
88
+ # @return [String]
89
+ def inspect
90
+ "<#{self.class.name} name:'#{name}', x:#{x}, y:#{y}, ox:#{ox}, " \
91
+ "oy:#{oy}, visible:#{visible}>"
92
+ end
93
+
88
94
  # Moves the cursor down by one row.
89
95
  #
90
96
  # Vedeu.trigger(:_cursor_down_, name)
@@ -13,6 +13,15 @@ module Vedeu
13
13
  extend Forwardable
14
14
  include Vedeu::Common
15
15
 
16
+ def_delegators :cursor,
17
+ :ox,
18
+ :oy,
19
+ :render,
20
+ :visible,
21
+ :visible?,
22
+ :x,
23
+ :y
24
+
16
25
  def_delegators :geometry,
17
26
  :bordered_height,
18
27
  :bordered_width
@@ -45,11 +54,10 @@ module Vedeu
45
54
  refresh_view if refresh_view?
46
55
 
47
56
  Vedeu.log(type: :output,
48
- message: "Refreshing cursor: '#{name}' (x:#{cursor.x}, " \
49
- "y:#{cursor.y}, ox:#{cursor.ox}, oy:#{cursor.oy}, " \
50
- "visible:#{cursor.visible})".freeze)
57
+ message: "Refreshing cursor: '#{name}' (x:#{x}, y:#{y}, " \
58
+ "ox:#{ox}, oy:#{oy}, visible:#{visible})".freeze)
51
59
 
52
- cursor.render
60
+ render
53
61
  end
54
62
 
55
63
  private
@@ -71,8 +79,7 @@ module Vedeu
71
79
  #
72
80
  # @return [Boolean]
73
81
  def refresh_view?
74
- cursor.visible? && (cursor.ox >= bordered_width ||
75
- cursor.oy >= bordered_height)
82
+ visible? && (ox >= bordered_width || oy >= bordered_height)
76
83
  end
77
84
 
78
85
  # @return [Vedeu::Cursors::Cursor]
@@ -90,13 +90,6 @@ module Vedeu
90
90
  @lines[oy...(oy + bordered_height)] || []
91
91
  end
92
92
 
93
- # Returns the interface by name.
94
- #
95
- # @return (see Vedeu::Interfaces::Repository#by_name)
96
- def interface
97
- @interface ||= Vedeu.interfaces.by_name(name)
98
- end
99
-
100
93
  # Return a range of visible characters from each line.
101
94
  #
102
95
  # @return [String]
@@ -60,7 +60,7 @@ module Vedeu
60
60
  elsif Vedeu::Input::Mapper.registered?(@key, name)
61
61
  Vedeu.trigger(:_keypress_, @key, name)
62
62
 
63
- elsif interface.editable?
63
+ elsif Vedeu.interfaces.by_name(name).editable?
64
64
  Vedeu.trigger(:_editor_, @key)
65
65
 
66
66
  elsif @key.nil?
@@ -133,11 +133,6 @@ module Vedeu
133
133
  Vedeu.focus
134
134
  end
135
135
 
136
- # @return [Vedeu::Interfaces::Interface]
137
- def interface
138
- Vedeu.interfaces.by_name(name)
139
- end
140
-
141
136
  end # Input
142
137
 
143
138
  end # Input
@@ -33,13 +33,6 @@ module Vedeu
33
33
  all_keypresses << keypress
34
34
  end
35
35
 
36
- # Access all commands and keypresses stored.
37
- #
38
- # @return [Hash<Symbol => Array<Symbol|String>>]
39
- def all
40
- storage
41
- end
42
-
43
36
  # Access all commands stored.
44
37
  #
45
38
  # @example
@@ -93,12 +86,15 @@ module Vedeu
93
86
  end
94
87
  alias_method :reset, :reset!
95
88
 
96
- private
97
-
89
+ # Access all commands and keypresses stored.
90
+ #
98
91
  # @return [Hash<Symbol => Array<Symbol|String>>]
99
92
  def storage
100
93
  @storage ||= in_memory
101
94
  end
95
+ alias_method :all, :storage
96
+
97
+ private
102
98
 
103
99
  # @return [Hash<Symbol => Array<Symbol|String>>]
104
100
  def in_memory
@@ -88,7 +88,7 @@ module Vedeu
88
88
 
89
89
  # @return [Vedeu::Colours::Colour]
90
90
  def colour
91
- @colour ||= interface.colour
91
+ @colour ||= Vedeu.interfaces.by_name(name).colour
92
92
  end
93
93
 
94
94
  # @return [Boolean]
@@ -127,13 +127,6 @@ module Vedeu
127
127
  end
128
128
  end
129
129
 
130
- # Returns the interface by name.
131
- #
132
- # @return (see Vedeu::Interfaces::Repository#by_name)
133
- def interface
134
- @interface ||= Vedeu.interfaces.by_name(name)
135
- end
136
-
137
130
  # @return [Hash<Symbol => Boolean>]
138
131
  def options
139
132
  defaults.merge!(@options)
@@ -71,7 +71,7 @@ module Vedeu
71
71
  #
72
72
  # @return [String]
73
73
  def current
74
- return storage[0] unless empty?
74
+ return storage[0] unless storage.empty?
75
75
 
76
76
  no_interfaces_registered!
77
77
  end
@@ -90,13 +90,6 @@ module Vedeu
90
90
  end
91
91
  alias_method :focussed?, :current?
92
92
 
93
- # Return a boolean indicating whether the storage is empty.
94
- #
95
- # @return [Boolean]
96
- def empty?
97
- storage.empty?
98
- end
99
-
100
93
  # Put the next interface relative to the current interfaces in
101
94
  # focus.
102
95
  #
@@ -121,7 +114,7 @@ module Vedeu
121
114
 
122
115
  loop do
123
116
  storage.rotate!
124
- break if Vedeu.interfaces.by_name(current).visible?
117
+ break if interface.visible?
125
118
  end
126
119
 
127
120
  update
@@ -153,7 +146,7 @@ module Vedeu
153
146
 
154
147
  loop do
155
148
  storage.rotate!(-1)
156
- break if Vedeu.interfaces.by_name(current).visible?
149
+ break if interface.visible?
157
150
  end
158
151
 
159
152
  update
@@ -183,7 +176,7 @@ module Vedeu
183
176
  # @param name [String|Symbol]
184
177
  # @return [Boolean]
185
178
  def registered?(name)
186
- return false if empty?
179
+ return false if storage.empty?
187
180
 
188
181
  storage.include?(name)
189
182
  end
@@ -198,6 +191,11 @@ module Vedeu
198
191
 
199
192
  private
200
193
 
194
+ # @return [Vedeu::Interfaces::Interface]
195
+ def interface
196
+ Vedeu.interfaces.by_name(current)
197
+ end
198
+
201
199
  # @raise [Vedeu::Error::Fatal]
202
200
  def no_interfaces_registered!
203
201
  fail Vedeu::Error::Fatal,
@@ -218,7 +216,7 @@ module Vedeu
218
216
  #
219
217
  # @return [String|FalseClass]
220
218
  def update
221
- return false if empty?
219
+ return false if storage.empty?
222
220
 
223
221
  Vedeu.log(message: "Interface in focus: '#{current}'".freeze)
224
222
 
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.6.62'.freeze
4
+ VERSION = '0.6.63'.freeze
5
5
 
6
6
  end
@@ -6,7 +6,21 @@ module Vedeu
6
6
 
7
7
  describe Caption do
8
8
 
9
- # @todo Add more tests.
9
+ let(:instance) {}
10
+
11
+ describe '#render' do
12
+ let(:top_border) {}
13
+
14
+ subject { instance.render(top_border) }
15
+
16
+ context 'when the title is empty' do
17
+ # @todo Add more tests.
18
+ end
19
+
20
+ context 'when the title is not empty' do
21
+ # @todo Add more tests.
22
+ end
23
+ end
10
24
 
11
25
  end # Caption
12
26
 
@@ -7,48 +7,22 @@ module Vedeu
7
7
  describe Title do
8
8
 
9
9
  let(:described) { Vedeu::Borders::Title }
10
- let(:instance) { described.new(_value, width) }
10
+ let(:instance) { described.new(_value, width, chars) }
11
11
  let(:_value) { 'Aluminium' }
12
12
  let(:width) { 10 }
13
+ let(:chars) { [] }
13
14
 
14
15
  describe '#initialize' do
15
16
  it { instance.must_be_instance_of(described) }
16
17
  it { instance.instance_variable_get('@value').must_equal(_value) }
17
18
  it { instance.instance_variable_get('@width').must_equal(width) }
19
+ it { instance.instance_variable_get('@chars').must_equal(chars) }
18
20
  end
19
21
 
20
- describe '.coerce' do
21
- subject { described.coerce(_value, width) }
22
+ describe '.render' do
23
+ subject { described.render(_value, width, chars) }
22
24
 
23
- context 'when the value is an instance of Vedeu::Borders::Title' do
24
- let(:_value) { Vedeu::Borders::Title.new('Aluminium', 10) }
25
-
26
- it { subject.must_equal(_value) }
27
- end
28
-
29
- context 'when the value is not an instance of Vedeu::Borders::Title' do
30
- it { subject.must_equal(instance) }
31
- end
32
- end
33
-
34
- describe '#characters' do
35
- subject { instance.characters }
36
-
37
- it { subject.must_equal([' ', 'A', 'l', 'u', 'm', 'i', 'n', ' ']) }
38
- end
39
-
40
- describe '#empty?' do
41
- subject { instance.empty? }
42
-
43
- context 'when the value is empty' do
44
- let(:_value) { '' }
45
-
46
- it { subject.must_equal(true) }
47
- end
48
-
49
- context 'when the value is not empty' do
50
- it { subject.must_equal(false) }
51
- end
25
+ # @todo Add more tests.
52
26
  end
53
27
 
54
28
  describe '#eql?' do
@@ -65,10 +39,18 @@ module Vedeu
65
39
  end
66
40
  end
67
41
 
68
- describe '#size' do
69
- subject { instance.size }
42
+ describe '#render' do
43
+ let(:top_border) {}
70
44
 
71
- it { subject.must_equal(8) }
45
+ subject { instance.render(top_border) }
46
+
47
+ context 'when the title is empty' do
48
+ # @todo Add more tests.
49
+ end
50
+
51
+ context 'when the title is not empty' do
52
+ # @todo Add more tests.
53
+ end
72
54
  end
73
55
 
74
56
  describe '#to_s' do
@@ -117,6 +117,18 @@ module Vedeu
117
117
  it { subject.must_be_instance_of(Vedeu::Models::Escape) }
118
118
  end
119
119
 
120
+ describe '#inspect' do
121
+ let(:expected) {
122
+ "<Vedeu::Cursors::Cursor name:'silver', x:19, y:8, ox:3, oy:2, " \
123
+ "visible:true>"
124
+ }
125
+
126
+ subject { instance.inspect }
127
+
128
+ it { subject.must_be_instance_of(String) }
129
+ it { subject.must_equal(expected) }
130
+ end
131
+
120
132
  describe '#move_down' do
121
133
  let(:x) { 19 }
122
134
  let(:y) { 8 }
@@ -26,32 +26,6 @@ module Vedeu
26
26
  it { subject.must_equal(['a']) }
27
27
  end
28
28
 
29
- describe '#all' do
30
- subject { described.all }
31
-
32
- context 'when empty' do
33
- it { subject.must_equal({ commands: [], keypresses: [] }) }
34
- end
35
-
36
- context 'when not empty' do
37
- let(:expected) {
38
- {
39
- commands: ['command_1', 'command_2'],
40
- keypresses: ['a', 'b'],
41
- }
42
- }
43
-
44
- before do
45
- described.add_command('command_1')
46
- described.add_command('command_2')
47
- described.add_keypress('a')
48
- described.add_keypress('b')
49
- end
50
-
51
- it { subject.must_equal(expected) }
52
- end
53
- end
54
-
55
29
  describe '#all_commands' do
56
30
  subject { described.all_commands }
57
31
 
@@ -130,6 +104,34 @@ module Vedeu
130
104
  it { subject.must_equal({ commands: [], keypresses: [] }) }
131
105
  end
132
106
 
107
+ describe '#storage' do
108
+ subject { described.storage }
109
+
110
+ it { described.must_respond_to(:all) }
111
+
112
+ context 'when empty' do
113
+ it { subject.must_equal({ commands: [], keypresses: [] }) }
114
+ end
115
+
116
+ context 'when not empty' do
117
+ let(:expected) {
118
+ {
119
+ commands: ['command_1', 'command_2'],
120
+ keypresses: ['a', 'b'],
121
+ }
122
+ }
123
+
124
+ before do
125
+ described.add_command('command_1')
126
+ described.add_command('command_2')
127
+ described.add_keypress('a')
128
+ described.add_keypress('b')
129
+ end
130
+
131
+ it { subject.must_equal(expected) }
132
+ end
133
+ end
134
+
133
135
  end # Store
134
136
 
135
137
  end # Input
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.6.62
4
+ version: 0.6.63
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-11-21 00:00:00.000000000 Z
11
+ date: 2015-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard