vedeu 0.6.48 → 0.6.49

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: 9759381f1db665ae94ab60090c238d752bbdc117
4
- data.tar.gz: ac4f61ccd7ed1156dc851b590afe18d957ec2b97
3
+ metadata.gz: 40290f698e67f6437fbc9b2727e8cdfe54d68a6d
4
+ data.tar.gz: 259c3305848dd4a9dc9b58332051ebf4987b1f99
5
5
  SHA512:
6
- metadata.gz: 20aa205043bf1c5563dd7814f26fc3edd2c26dc3b4edfd65ba85534a3e9294f38c682f1dcd662add1152d93ff3358544679c0bd8db784f54ba7aa59fff0ec1d0
7
- data.tar.gz: d0ed14b86e102240df0609974d09dc6530c6e75cfc0dd86afa17b892ad19074427ac9b24459b9a3209c2d7792ff888b70732ee9a4edad8c92de8401575d93966
6
+ metadata.gz: 34e50c0fa3539b628e7592fb0f19b4d9cc20ff7a3d9808bcb515c24fb06c8590e1e26f73c538276716bdc33f1296aa1c9ba710cd768d2ec6409de7cb19b574a4
7
+ data.tar.gz: 234914b85448331f85d85db2b754b917d71c5e7c76675a5d1ce68fd2af8c37ca3f7701ad76d2df0eb017d99b76b6bf078b1e438cbd7798b751184fb31ada2d09
data/.rubocop.yml CHANGED
@@ -79,6 +79,9 @@ Style/IndentHash:
79
79
  - special_inside_parentheses
80
80
  - consistent
81
81
 
82
+ Style/MultilineOperationIndentation:
83
+ Enabled: false
84
+
82
85
  Style/ModuleFunction:
83
86
  Enabled: false
84
87
 
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  [![Code Climate](https://codeclimate.com/github/gavinlaking/vedeu.png)](https://codeclimate.com/github/gavinlaking/vedeu)
2
2
  [![Build Status](https://travis-ci.org/gavinlaking/vedeu.svg?branch=master)](https://travis-ci.org/gavinlaking/vedeu)
3
- [![Test Coverage](https://codeclimate.com/github/gavinlaking/vedeu/badges/coverage.svg)](https://codeclimate.com/github/gavinlaking/vedeu/coverage)
4
3
 
5
4
  # Vedeu
6
5
 
@@ -0,0 +1,239 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'vedeu'
5
+
6
+ # If you have cloned this repository from GitHub, you can run this example:
7
+ #
8
+ # bundle exec ./examples/dsl_menus.rb
9
+ #
10
+ class DSLMenus
11
+ include Vedeu
12
+
13
+ Vedeu.bind(:_initialize_) {
14
+ Vedeu.trigger(:_show_group_, :file_browser)
15
+ Vedeu.trigger(:_refresh_group_, :file_browser)
16
+ }
17
+
18
+ Vedeu.configure do
19
+ debug!
20
+ log '/tmp/dsl_menus.log'
21
+ end
22
+
23
+ Vedeu.interface :files do
24
+ border do
25
+ title 'Files'
26
+ end
27
+ foreground '#ffffff'
28
+ geometry do
29
+ width columns(3) - 1
30
+ height Vedeu.height - 1
31
+ x 1
32
+ y 1
33
+ end
34
+ group :file_browser
35
+ keymap do
36
+ key('k', :up) do
37
+ Vedeu.trigger(:_menu_prev_, :files)
38
+ Vedeu.trigger(:update)
39
+ end
40
+ key('j', :down) do
41
+ Vedeu.trigger(:_menu_next_, :files)
42
+ Vedeu.trigger(:update)
43
+ end
44
+ key(:enter) do
45
+ Vedeu.trigger(:_menu_select_, :files)
46
+ Vedeu.trigger(:update)
47
+ end
48
+ end
49
+ end
50
+
51
+ Vedeu.interface :contents do
52
+ border do
53
+ title 'Contents'
54
+ end
55
+ foreground '#ffffff'
56
+ geometry do
57
+ width Vedeu.width - (columns(3) - 1)
58
+ height Vedeu.height - 1
59
+ x use(:files).east
60
+ y 1
61
+ end
62
+ group :file_browser
63
+ keymap do
64
+ key('k', :up) do
65
+ Vedeu.trigger(:_cursor_up_, :contents)
66
+ end
67
+ key('j', :down) do
68
+ Vedeu.trigger(:_cursor_down_, :contents)
69
+ end
70
+ end
71
+ end
72
+
73
+ Vedeu.keymap '_global_' do
74
+ key('q') { Vedeu.exit }
75
+ key(:shift_tab) { Vedeu.trigger(:_focus_prev_) }
76
+ key(:tab) { Vedeu.trigger(:_focus_next_) }
77
+ end
78
+
79
+ # Orchestrates the user interactions with the application.
80
+ #
81
+ class Controller
82
+ def initialize(args = [])
83
+ @args = args
84
+
85
+ menu = Vedeu.menu(:files) { items(files) }
86
+
87
+ Vedeu.bind :update do
88
+ FilesView.new.show
89
+ ContentsView.new.show
90
+ Vedeu.trigger(:_refresh_group_, :file_browser)
91
+ end
92
+
93
+ FilesView.new.show
94
+ end
95
+
96
+ private
97
+
98
+ attr_reader :args
99
+
100
+ def files
101
+ @files ||= Files.new(args).all_files
102
+ end
103
+ end
104
+
105
+ # Get all the files in the current or specified directory.
106
+ #
107
+ class Files
108
+ def initialize(args = [])
109
+ @args = args
110
+ end
111
+
112
+ def all_files
113
+ @_all_files ||= files.map { |file| SomeFile.new(file) }.sort_by(&:name)
114
+ end
115
+
116
+ private
117
+
118
+ attr_reader :args
119
+
120
+ def files
121
+ @_files ||= Dir.glob(recursive).select { |file| File.file?(file) }
122
+ end
123
+
124
+ def recursive
125
+ directory + '/*'
126
+ end
127
+
128
+ def directory
129
+ args.first || '.'
130
+ end
131
+ end
132
+
133
+ # A class to wrap a file, providing its name and contents (in the
134
+ # form of 'data').
135
+ #
136
+ class SomeFile
137
+ attr_reader :file
138
+
139
+ def initialize(file)
140
+ @file = file
141
+ end
142
+
143
+ def name
144
+ file.to_s
145
+ end
146
+
147
+ def data
148
+ @data ||= Contents.new(file).contents
149
+ end
150
+ end
151
+
152
+ # The contents of a file.
153
+ #
154
+ class Contents
155
+ attr_reader :path
156
+
157
+ def initialize(path)
158
+ @path = path
159
+ end
160
+
161
+ def contents
162
+ File.readlines(path)
163
+ end
164
+ end
165
+
166
+ # Displays a list of files from the current or specified directory.
167
+ #
168
+ class FilesView
169
+ def show
170
+ Vedeu.renders do
171
+ view :files do
172
+ files_menu.each do |sel, cur, item|
173
+ if sel && cur
174
+ line do
175
+ stream do
176
+ text "\u{25B6}> #{item.name}"
177
+ end
178
+ end
179
+
180
+ elsif cur
181
+ line do
182
+ stream do
183
+ text " > #{item.name}"
184
+ end
185
+ end
186
+
187
+ elsif sel
188
+ line do
189
+ stream do
190
+ text "\u{25B6} #{item.name}"
191
+ end
192
+ end
193
+
194
+ else
195
+ line do
196
+ stream do
197
+ text " #{item.name}"
198
+ end
199
+ end
200
+ end
201
+ end
202
+ end
203
+ end
204
+ end
205
+
206
+ def files_menu
207
+ @files_menu ||= Vedeu.trigger(:_menu_view_, :files)
208
+ end
209
+ end
210
+
211
+ # Displays the contents of a selected file.
212
+ #
213
+ class ContentsView
214
+ def show
215
+ Vedeu.renders do
216
+ view :contents do
217
+ open_file.data.each do |data_line|
218
+ line do
219
+ text "#{data_line.chomp}"
220
+ end
221
+ end if open_file
222
+ end
223
+ end
224
+ end
225
+
226
+ def open_file
227
+ @file_contents ||= Vedeu.trigger(:_menu_selected_, :files)
228
+ end
229
+ end
230
+
231
+ def self.start(argv = ARGV)
232
+ Controller.new(argv)
233
+
234
+ Vedeu::Launcher.execute!(argv)
235
+ end
236
+
237
+ end # DSLMenus
238
+
239
+ DSLMenus.start
@@ -33,6 +33,7 @@ module Vedeu
33
33
 
34
34
  end # Vedeu
35
35
 
36
+ require 'vedeu/borders/title'
36
37
  require 'vedeu/borders/border'
37
38
  require 'vedeu/borders/dsl'
38
39
  require 'vedeu/borders/null'
@@ -66,15 +66,15 @@ module Vedeu
66
66
  attr_accessor :show_top
67
67
  alias_method :top?, :show_top
68
68
 
69
- # @!attribute [rw] caption
70
- # @return [String] An optional caption for when the bottom
69
+ # # @!attribute [rw] caption
70
+ # # @return [String] An optional caption for when the bottom
71
71
  # border is to be shown.
72
- attr_accessor :caption
72
+ # attr_accessor :caption
73
73
 
74
74
  # @!attribute [rw] title
75
75
  # @return [String] An optional title for when the top
76
76
  # border is to be shown.
77
- attr_accessor :title
77
+ # attr_accessor :title
78
78
 
79
79
  # @!attribute [rw] top_left
80
80
  # @return [String] The character to be used for the top left
@@ -204,6 +204,28 @@ module Vedeu
204
204
  (enabled? && bottom?) ? yn - 1 : yn
205
205
  end
206
206
 
207
+ # @return [Vedeu::Borders::Caption]
208
+ def caption
209
+ Vedeu::Borders::Caption.coerce(@caption, width)
210
+ end
211
+
212
+ # @param value [String]
213
+ # @return [Vedeu::Borders::Caption]
214
+ def caption=(value)
215
+ @caption = Vedeu::Borders::Caption.coerce(value, width)
216
+ end
217
+
218
+ # @return [Vedeu::Borders::Title]
219
+ def title
220
+ Vedeu::Borders::Title.coerce(@title, width)
221
+ end
222
+
223
+ # @param value [String]
224
+ # @return [Vedeu::Borders::Title]
225
+ def title=(value)
226
+ @title = Vedeu::Borders::Title.coerce(value, width)
227
+ end
228
+
207
229
  # Returns a DSL instance responsible for defining the DSL
208
230
  # methods of this model.
209
231
  #
@@ -233,9 +233,10 @@ module Vedeu
233
233
  # +- My Cool Title --------------------------------+
234
234
  #
235
235
  # @param value [String] The title.
236
- # @return [String]
236
+ # @return [Vedeu::Borders::Title]
237
237
  def title(value)
238
238
  model.title = value
239
+ model.title
239
240
  end
240
241
  alias_method :title=, :title
241
242
 
@@ -252,9 +253,10 @@ module Vedeu
252
253
  # +------------------------------ My Cool Caption -+
253
254
  #
254
255
  # @param value [String] The caption.
255
- # @return [String]
256
+ # @return [Vedeu::Borders::Caption]
256
257
  def caption(value)
257
258
  model.caption = value
259
+ model.caption
258
260
  end
259
261
  alias_method :caption=, :caption
260
262
 
@@ -230,17 +230,17 @@ module Vedeu
230
230
  #
231
231
  # @return [Array<Vedeu::Views::Char>]
232
232
  def captionbar
233
- return build_bottom unless caption? && caption_fits?
233
+ return build_bottom if caption.empty?
234
234
 
235
- caption_starts_at = (width - caption_characters.size) - 2
235
+ caption_starts_at = (width - caption.size) - 2
236
236
 
237
- caption_char = 0
237
+ caption_index = 0
238
238
  build_bottom.each_with_index do |char, index|
239
239
  next if index <= caption_starts_at || index > (width - 2)
240
240
 
241
- char.border = nil
242
- char.value = caption_characters[caption_char]
243
- caption_char += 1
241
+ char.border = nil
242
+ char.value = caption.characters[caption_index]
243
+ caption_index += 1
244
244
  end
245
245
  end
246
246
 
@@ -249,126 +249,16 @@ module Vedeu
249
249
  #
250
250
  # @return [Array<Vedeu::Views::Char>]
251
251
  def titlebar
252
- return build_top unless title? && title_fits?
252
+ return build_top if title.empty?
253
253
 
254
254
  build_top.each_with_index do |char, index|
255
- next if index == 0 || index > title_characters.size
255
+ next if index == 0 || index > title.size
256
256
 
257
257
  char.border = nil
258
- char.value = title_characters[(index - 1)]
258
+ char.value = title.characters[index - 1]
259
259
  end
260
260
  end
261
261
 
262
- # Return boolean indicating whether this border has a non-empty
263
- # title.
264
- #
265
- # @return [Boolean]
266
- def title?
267
- present?(title)
268
- end
269
-
270
- # Return boolean indicating whether this border has a non-empty
271
- # caption.
272
- #
273
- # @return [Boolean]
274
- def caption?
275
- present?(caption)
276
- end
277
-
278
- # Return boolean indicating whether the title fits within the
279
- # width of the top border.
280
- #
281
- # @return [Boolean]
282
- def title_fits?
283
- width > title_characters.size
284
- end
285
-
286
- # Return boolean indicating whether the caption fits within the
287
- # width of the bottom border.
288
- #
289
- # @return [Boolean]
290
- def caption_fits?
291
- width > caption_characters.size
292
- end
293
-
294
- # @return [Array<String>]
295
- def title_characters
296
- @title_characters ||= title_padded.chars
297
- end
298
-
299
- # @return [Array<String>]
300
- def caption_characters
301
- @caption_characters ||= caption_padded.chars
302
- end
303
-
304
- # Pads the title with a single whitespace either side.
305
- #
306
- # @example
307
- # title = 'Truncated!'
308
- # width = 20
309
- # # => ' Truncated! '
310
- #
311
- # width = 10
312
- # # => ' Trunca '
313
- #
314
- # @return [String]
315
- # @see #truncated_title
316
- def title_padded
317
- truncated_title.center(truncated_title.size + 2)
318
- end
319
-
320
- # Pads the caption with a single whitespace either side.
321
- #
322
- # @example
323
- # caption = 'Truncated!'
324
- # width = 20
325
- # # => ' Truncated! '
326
- #
327
- # width = 10
328
- # # => ' Trunca '
329
- #
330
- # @return [String]
331
- # @see #truncated_caption
332
- def caption_padded
333
- truncated_caption.center(truncated_caption.size + 2)
334
- end
335
-
336
- # Truncates the title to the width of the interface, minus
337
- # characters needed to ensure there is at least a single
338
- # character of horizontal border and a whitespace on either side
339
- # of the title.
340
- #
341
- # @example
342
- # title = 'Truncated!'
343
- # width = 20
344
- # # => 'Truncated!'
345
- #
346
- # width = 10
347
- # # => 'Trunca'
348
- #
349
- # @return [String]
350
- def truncated_title
351
- title.chomp.slice(0..(width - 5))
352
- end
353
-
354
- # Truncates the caption to the width of the interface, minus
355
- # characters needed to ensure there is at least a single
356
- # character of horizontal border and a whitespace on either
357
- # side of the caption.
358
- #
359
- # @example
360
- # caption = 'Truncated!'
361
- # width = 20
362
- # # => 'Truncated!'
363
- #
364
- # width = 10
365
- # # => 'Trunca'
366
- #
367
- # @return [String]
368
- def truncated_caption
369
- caption.chomp.slice(0..(width - 5))
370
- end
371
-
372
262
  end # Refresh
373
263
 
374
264
  end # Borders
@@ -0,0 +1,138 @@
1
+ module Vedeu
2
+
3
+ module Borders
4
+
5
+ # When a {Vedeu::Borders::Border} has a title, truncate it if the
6
+ # title is longer than the interface is wide, and pad with a space
7
+ # either side.
8
+ #
9
+ class Title
10
+
11
+ # @param value [String|Vedeu::Borders::Title|
12
+ # Vedeu::Borders::Caption]
13
+ # @param width [Fixnum]
14
+ # @return [Vedeu::Borders::Title|Vedeu::Borders::Caption]
15
+ def self.coerce(value = '', width = Vedeu.width)
16
+ if value.is_a?(self)
17
+ value
18
+
19
+ else
20
+ new(value, width)
21
+
22
+ end
23
+ end
24
+
25
+ # Returns a new instance of Vedeu::Borders::Title or
26
+ # Vedeu::Borders::Caption.
27
+ #
28
+ # @param value [String|Vedeu::Borders::Title|
29
+ # Vedeu::Borders::Caption]
30
+ # @param width [Fixnum]
31
+ # @return [Vedeu::Borders::Title|Vedeu::Borders::Caption]
32
+ def initialize(value = '', width = Vedeu.width)
33
+ @value = value
34
+ @width = width
35
+ end
36
+
37
+ # Return the padded, truncated value as an Array of String.
38
+ #
39
+ # @return [Array<String>]
40
+ def characters
41
+ pad.chars
42
+ end
43
+
44
+ # Return boolean indicating whether the value is empty.
45
+ #
46
+ # @return [Boolean]
47
+ def empty?
48
+ value.empty?
49
+ end
50
+
51
+ # An object is equal when its values are the same.
52
+ #
53
+ # @param other [Vedeu::Borders::Title]
54
+ # @return [Boolean]
55
+ def eql?(other)
56
+ self.class == other.class && value == other.value
57
+ end
58
+ alias_method :==, :eql?
59
+
60
+ # Return the size of the padded, truncated value.
61
+ #
62
+ # @return [Fixnum]
63
+ def size
64
+ pad.size
65
+ end
66
+
67
+ # Convert the value to a string.
68
+ #
69
+ # @return [String]
70
+ def to_s
71
+ value.to_s
72
+ end
73
+
74
+ # Return the value or an empty string.
75
+ #
76
+ # @return [String]
77
+ def value
78
+ @value || ''
79
+ end
80
+ alias_method :title, :value
81
+ alias_method :caption, :value
82
+
83
+ private
84
+
85
+ # Pads the value with a single whitespace either side.
86
+ #
87
+ # @example
88
+ # value = 'Truncated!'
89
+ # width = 20
90
+ # # => ' Truncated! '
91
+ #
92
+ # width = 10
93
+ # # => ' Trunca '
94
+ #
95
+ # @return [String]
96
+ # @see #truncate
97
+ def pad
98
+ truncate.center(truncate.size + 2)
99
+ end
100
+
101
+ # Truncates the value to the width of the interface, minus
102
+ # characters needed to ensure there is at least a single
103
+ # character of horizontal border and a whitespace on either side
104
+ # of the value.
105
+ #
106
+ # @example
107
+ # value = 'Truncated!'
108
+ # width = 20
109
+ # # => 'Truncated!'
110
+ #
111
+ # width = 10
112
+ # # => 'Trunca'
113
+ #
114
+ # @return [String]
115
+ def truncate
116
+ title.chomp.slice(0...(width - 4))
117
+ end
118
+
119
+ # Return the given width or the width of the terminal.
120
+ #
121
+ # @return [Fixnum]
122
+ def width
123
+ @width || Vedeu.width
124
+ end
125
+
126
+ end # Title
127
+
128
+ # When a {Vedeu::Borders::Border} has a caption, truncate it if
129
+ # the caption is longer than the interface is wide, and pad with a
130
+ # space either side.
131
+ #
132
+ class Caption < Title
133
+
134
+ end # Caption
135
+
136
+ end # Borders
137
+
138
+ end # Vedeu
@@ -70,7 +70,7 @@ module Vedeu
70
70
  # @return [Hash<Symbol => Boolean>]
71
71
  def defaults
72
72
  {
73
- content_only: false,
73
+ content_only: false
74
74
  }
75
75
  end
76
76
 
@@ -190,6 +190,14 @@ module Vedeu
190
190
 
191
191
  private
192
192
 
193
+ # Returns the client object which called the DSL method.
194
+ #
195
+ # @param block [Proc]
196
+ # @return [Object]
197
+ def client(&block)
198
+ eval('self', block.binding)
199
+ end
200
+
193
201
  # Creates a new Vedeu::Views::Composition which may contain
194
202
  # one or more views (Vedeu::Views::View objects).
195
203
  #
@@ -202,6 +210,9 @@ module Vedeu
202
210
  Vedeu::Views::Composition.build(attrs, &block)
203
211
  end
204
212
 
213
+ # Creates a new Vedeu::Views::Composition which may contain
214
+ # one or more views (Vedeu::Views::View objects).
215
+ #
205
216
  # Stores each of the views defined in their respective buffers
206
217
  # ready to be rendered on next refresh.
207
218
  #
@@ -13,6 +13,7 @@ require 'vedeu/editor/cropper'
13
13
  require 'vedeu/editor/delete'
14
14
  require 'vedeu/editor/editor'
15
15
  require 'vedeu/editor/insert'
16
+ require 'vedeu/editor/item'
16
17
  require 'vedeu/editor/line'
17
18
  require 'vedeu/editor/lines'
18
19
  require 'vedeu/editor/cursor'
@@ -0,0 +1,71 @@
1
+ module Vedeu
2
+
3
+ module Editor
4
+
5
+ # Fetches an item from a collection.
6
+ #
7
+ class Item
8
+
9
+ # @param collection [Vedeu::Editor::Line|Vedeu::Editor::Lines]
10
+ # @param index [Fixnum]
11
+ # @return [String|Vedeu::Editor::Line]
12
+ def self.by_index(collection, index = nil)
13
+ new(collection, index).by_index
14
+ end
15
+
16
+ # Returns a new instance of Vedeu::Editor::Item.
17
+ #
18
+ # @param collection [Vedeu::Editor::Line|Vedeu::Editor::Lines]
19
+ # @param index [Fixnum]
20
+ # @return [Vedeu::Editor::item]
21
+ def initialize(collection, index = nil)
22
+ @collection = collection
23
+ @index = index
24
+ end
25
+
26
+ # @return [String|Vedeu::Editor::Line]
27
+ def by_index
28
+ return nil unless size > 0
29
+
30
+ if index.nil? || index > size
31
+ collection[-1]
32
+
33
+ elsif index <= 0
34
+ collection[0]
35
+
36
+ elsif index > 0 && index <= size
37
+ collection[index]
38
+
39
+ end
40
+ end
41
+
42
+ protected
43
+
44
+ # @!attribute [r] collection
45
+ # @return [Vedeu::Editor::Line|Vedeu::Editor::Lines]
46
+ attr_reader :collection
47
+
48
+ # @!attribute [r] index
49
+ # @return [Fixnum]
50
+ attr_reader :index
51
+
52
+ private
53
+
54
+ # Returns the size of the collection or 0.
55
+ #
56
+ # @return [Fixnum]
57
+ def size
58
+ if collection
59
+ collection.size
60
+
61
+ else
62
+ 0
63
+
64
+ end
65
+ end
66
+
67
+ end # Item
68
+
69
+ end # Editor
70
+
71
+ end # Vedeu
@@ -39,8 +39,7 @@ module Vedeu
39
39
  line[index]
40
40
  end
41
41
 
42
- # Return the character from the line positioned at the given
43
- # index.
42
+ # Return the character at the given index.
44
43
  #
45
44
  # @param index [Fixnum|NilClass]
46
45
  # @return [String|NilClass]
@@ -48,16 +47,7 @@ module Vedeu
48
47
  return '' if line && line.empty?
49
48
  return line[-1] unless index
50
49
 
51
- if index <= 0
52
- line[0]
53
-
54
- elsif index && index <= size
55
- line[index]
56
-
57
- else
58
- line[-1]
59
-
60
- end
50
+ Vedeu::Editor::Item.by_index(line, index)
61
51
  end
62
52
 
63
53
  # Delete the character from the line positioned at the given
@@ -131,18 +131,7 @@ module Vedeu
131
131
  return Vedeu::Editor::Line.new unless lines
132
132
  return Vedeu::Editor::Line.coerce(lines[-1]) unless index
133
133
 
134
- indexed = if index <= 0
135
- lines[0]
136
-
137
- elsif index && index <= size
138
- lines[index]
139
-
140
- else
141
- lines[-1]
142
-
143
- end
144
-
145
- Vedeu::Editor::Line.coerce(indexed)
134
+ Vedeu::Editor::Line.coerce(Vedeu::Editor::Item.by_index(lines, index))
146
135
  end
147
136
 
148
137
  # Return the number of lines.
@@ -33,6 +33,8 @@ module Vedeu
33
33
  end
34
34
  end
35
35
 
36
+ # Returns a new instance of Vedeu::Geometry::Alignment.
37
+ #
36
38
  # @param value [NilClass|Symbol]
37
39
  # @return [Vedeu::Geometry::Alignment]
38
40
  def initialize(value = nil)
@@ -242,6 +242,7 @@ module Vedeu
242
242
  def show!
243
243
  visible(true)
244
244
  end
245
+ alias_method :visible!, :show!
245
246
 
246
247
  # Set the interface to invisible.
247
248
  #
@@ -13,6 +13,8 @@ module Vedeu
13
13
  attr_accessor :samples
14
14
  attr_accessor :benchmark
15
15
 
16
+ # Returns a new instance of Vedeu::Logging::Debug::IPS.
17
+ #
16
18
  # @return [Vedeu::Logging::Debug::IPS]
17
19
  def initialize
18
20
  @old_stdout = $stdout
@@ -91,6 +91,8 @@ module Vedeu
91
91
  alias_method :toggle_group, :toggle
92
92
  alias_method :toggle_interface, :toggle
93
93
 
94
+ # Hide the cursor if visible.
95
+ #
94
96
  # @example
95
97
  # Vedeu.hide_cursor(name)
96
98
  #
@@ -101,6 +103,8 @@ module Vedeu
101
103
  hide(name) if cursor_visible?(name)
102
104
  end
103
105
 
106
+ # Show the cursor if not already visible.
107
+ #
104
108
  # @example
105
109
  # Vedeu.show_cursor(name)
106
110
  #
@@ -108,9 +112,11 @@ module Vedeu
108
112
  # @return [void]
109
113
  # @see Vedeu::Toggleable#show
110
114
  def show_cursor(name = Vedeu.focus)
111
- show(name) if cursor_visible?(name)
115
+ show(name) unless cursor_visible?(name)
112
116
  end
113
117
 
118
+ # Toggle the cursor visibility.
119
+ #
114
120
  # @example
115
121
  # Vedeu.toggle_cursor(name)
116
122
  #
@@ -118,11 +124,13 @@ module Vedeu
118
124
  # @return [void]
119
125
  # @see Vedeu::Toggleable#toggle
120
126
  def toggle_cursor(name = Vedeu.focus)
121
- toggle(name) if cursor_visible?(name)
127
+ toggle(name)
122
128
  end
123
129
 
124
130
  private
125
131
 
132
+ # Returns a boolean indicating whether the cursor is visible.
133
+ #
126
134
  # @param name [String|Symbol]
127
135
  # @return [Boolean]
128
136
  def cursor_visible?(name)
@@ -46,7 +46,7 @@ module Vedeu
46
46
  # @return [Hash<Symbol => Array<String|Symbol>|String|Symbol>]
47
47
  def attributes
48
48
  {
49
- style: value,
49
+ style: value
50
50
  }
51
51
  end
52
52
 
@@ -50,7 +50,7 @@ module Vedeu
50
50
  # @return [Hash]
51
51
  def defaults
52
52
  {
53
- ready: false,
53
+ ready: false
54
54
  }
55
55
  end
56
56
 
@@ -74,6 +74,7 @@ module Vedeu
74
74
  uncaught_exception.message
75
75
  end
76
76
 
77
+ Vedeu.log(type: :error, message: output)
77
78
  Vedeu.log_stdout(type: :error, message: output)
78
79
  end
79
80
 
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.48'.freeze
4
+ VERSION = '0.6.49'.freeze
5
5
 
6
6
  end
@@ -55,8 +55,6 @@ module Vedeu
55
55
  instance.must_respond_to(:bottom_left=)
56
56
  instance.must_respond_to(:bottom_right)
57
57
  instance.must_respond_to(:bottom_right=)
58
- instance.must_respond_to(:caption)
59
- instance.must_respond_to(:caption=)
60
58
  instance.must_respond_to(:horizontal)
61
59
  instance.must_respond_to(:horizontal=)
62
60
  instance.must_respond_to(:show_bottom)
@@ -71,8 +69,6 @@ module Vedeu
71
69
  instance.must_respond_to(:show_top)
72
70
  instance.must_respond_to(:top?)
73
71
  instance.must_respond_to(:show_top=)
74
- instance.must_respond_to(:title)
75
- instance.must_respond_to(:title=)
76
72
  instance.must_respond_to(:top_left)
77
73
  instance.must_respond_to(:top_left=)
78
74
  instance.must_respond_to(:top_right)
@@ -173,8 +173,8 @@ module Vedeu
173
173
 
174
174
  subject { instance.title(_value) }
175
175
 
176
- it { subject.must_be_instance_of(String) }
177
- it { subject.must_equal('Some title') }
176
+ it { subject.must_be_instance_of(Vedeu::Borders::Title) }
177
+ it { subject.title.must_equal('Some title') }
178
178
  it { instance.must_respond_to(:title=) }
179
179
  end
180
180
 
@@ -183,8 +183,8 @@ module Vedeu
183
183
 
184
184
  subject { instance.caption(_value) }
185
185
 
186
- it { subject.must_be_instance_of(String) }
187
- it { subject.must_equal('Some caption') }
186
+ it { subject.must_be_instance_of(Vedeu::Borders::Caption) }
187
+ it { subject.caption.must_equal('Some caption') }
188
188
  it { instance.must_respond_to(:caption=) }
189
189
  end
190
190
 
@@ -223,7 +223,7 @@ module Vedeu
223
223
 
224
224
  it 'allows the use of another models attributes' do
225
225
  subject
226
- Vedeu.borders.by_name('other_border').title.must_equal('Some border')
226
+ Vedeu.borders.by_name('other_border').title.to_s.must_equal('Some border')
227
227
  end
228
228
  end
229
229
 
@@ -0,0 +1,101 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Borders
6
+
7
+ describe Title do
8
+
9
+ let(:described) { Vedeu::Borders::Title }
10
+ let(:instance) { described.new(_value, width) }
11
+ let(:_value) { 'Aluminium' }
12
+ let(:width) { 10 }
13
+
14
+ describe '#initialize' do
15
+ it { instance.must_be_instance_of(described) }
16
+ it { instance.instance_variable_get('@value').must_equal(_value) }
17
+ it { instance.instance_variable_get('@width').must_equal(width) }
18
+ end
19
+
20
+ describe '.coerce' do
21
+ subject { described.coerce(_value, width) }
22
+
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
52
+ end
53
+
54
+ describe '#eql?' do
55
+ let(:other) { instance }
56
+
57
+ subject { instance.eql?(other) }
58
+
59
+ it { subject.must_equal(true) }
60
+
61
+ context 'when different to other' do
62
+ let(:other) { described.new('Vanadium') }
63
+
64
+ it { subject.must_equal(false) }
65
+ end
66
+ end
67
+
68
+ describe '#size' do
69
+ subject { instance.size }
70
+
71
+ it { subject.must_equal(8) }
72
+ end
73
+
74
+ describe '#to_s' do
75
+ subject { instance.to_s }
76
+
77
+ it { subject.must_equal('Aluminium') }
78
+ end
79
+
80
+ describe '#value' do
81
+ subject { instance.value }
82
+
83
+ it { instance.must_respond_to(:title) }
84
+ it { instance.must_respond_to(:caption) }
85
+
86
+ context 'when the value is nil' do
87
+ let(:_value) {}
88
+
89
+ it { subject.must_equal('') }
90
+ end
91
+
92
+ context 'when the value is not nil' do
93
+ it { subject.must_equal('Aluminium') }
94
+ end
95
+ end
96
+
97
+ end # Title
98
+
99
+ end # Borders
100
+
101
+ end # Vedeu
@@ -0,0 +1,73 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ describe Item do
8
+
9
+ let(:described) { Vedeu::Editor::Item }
10
+ let(:instance) { described.new(collection, index) }
11
+ let(:collection) {}
12
+ let(:index) {}
13
+
14
+ describe '#initialize' do
15
+ it { instance.must_be_instance_of(described) }
16
+ it { instance.instance_variable_get('@collection').must_equal(collection) }
17
+ it { instance.instance_variable_get('@index').must_equal(index) }
18
+ end
19
+
20
+ describe '.by_index' do
21
+ subject { described.by_index(collection, index) }
22
+
23
+ context 'when the collection is empty or nil' do
24
+ it { subject.must_equal(nil) }
25
+ end
26
+
27
+ context 'when the collection is not empty' do
28
+ let(:collection) { [:hydrogen, :helium, :lithium] }
29
+
30
+ context 'when the index is nil' do
31
+ it 'returns the last item' do
32
+ subject.must_equal(:lithium)
33
+ end
34
+ end
35
+
36
+ context 'when the index is greater than the size of the collection' do
37
+ let(:index) { 4 }
38
+
39
+ it 'returns the last item' do
40
+ subject.must_equal(:lithium)
41
+ end
42
+ end
43
+
44
+ context 'when the index < 0' do
45
+ let(:index) { -2 }
46
+
47
+ it { subject.must_equal(:hydrogen) }
48
+ end
49
+
50
+ context 'when the index == 0' do
51
+ let(:index) { 0 }
52
+
53
+ it { subject.must_equal(:hydrogen) }
54
+ end
55
+
56
+ context 'when the index > 0 and the index is less than the size of ' \
57
+ 'the collection' do
58
+ let(:index) { 1 }
59
+
60
+ it { subject.must_equal(:helium) }
61
+ end
62
+ end
63
+ end
64
+
65
+ describe '#by_index' do
66
+ it { instance.must_respond_to(:by_index) }
67
+ end
68
+
69
+ end # Item
70
+
71
+ end # Editor
72
+
73
+ end # Vedeu
@@ -16,9 +16,10 @@ module Vedeu
16
16
 
17
17
  describe Toggleable do
18
18
 
19
- let(:described) { Vedeu::Toggleable }
20
- let(:instance) { Vedeu::ToggleableTestClass.new(visible) }
21
- let(:visible) { false }
19
+ let(:described) { Vedeu::Toggleable }
20
+ let(:described_included) { Vedeu::ToggleableTestClass }
21
+ let(:instance) { described_included.new(visible) }
22
+ let(:visible) { false }
22
23
 
23
24
  describe 'accessors' do
24
25
  it {
@@ -78,22 +79,40 @@ module Vedeu
78
79
  end
79
80
  end
80
81
 
81
- describe '#hide_cursor' do
82
- subject { instance.hide_cursor }
82
+ describe '.hide_cursor' do
83
+ subject { described_included.hide_cursor }
83
84
 
84
- # @todo Add more tests.
85
+ context 'when the cursor is visible' do
86
+ # @todo Add more tests.
87
+ end
88
+
89
+ context 'when the cursor is not visible' do
90
+ # @todo Add more tests.
91
+ end
85
92
  end
86
93
 
87
- describe '#show_cursor' do
88
- subject { instance.show_cursor }
94
+ describe '.show_cursor' do
95
+ subject { described_included.show_cursor }
96
+
97
+ context 'when the cursor is visible' do
98
+ # @todo Add more tests.
99
+ end
89
100
 
90
- # @todo Add more tests.
101
+ context 'when the cursor is not visible' do
102
+ # @todo Add more tests.
103
+ end
91
104
  end
92
105
 
93
- describe '#toggle_cursor' do
94
- subject { instance.toggle_cursor }
106
+ describe '.toggle_cursor' do
107
+ subject { described_included.toggle_cursor }
108
+
109
+ context 'when the cursor is visible' do
110
+ # @todo Add more tests.
111
+ end
95
112
 
96
- # @todo Add more tests.
113
+ context 'when the cursor is not visible' do
114
+ # @todo Add more tests.
115
+ end
97
116
  end
98
117
  end # Toggleable
99
118
 
data/vedeu.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency 'minitest-reporters', '1.1.5'
28
28
  spec.add_development_dependency 'mocha', '1.1.0'
29
29
  spec.add_development_dependency 'pry', '0.10.3'
30
- spec.add_development_dependency 'rubocop', '0.34.2'
30
+ spec.add_development_dependency 'rubocop', '0.35.0'
31
31
  spec.add_development_dependency 'simplecov', '0.10.0'
32
32
  spec.add_development_dependency 'simplecov-console', '0.2.0'
33
33
  spec.add_development_dependency 'yard', '0.8.7.6'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.48
4
+ version: 0.6.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -114,14 +114,14 @@ dependencies:
114
114
  requirements:
115
115
  - - '='
116
116
  - !ruby/object:Gem::Version
117
- version: 0.34.2
117
+ version: 0.35.0
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
- version: 0.34.2
124
+ version: 0.35.0
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: simplecov
127
127
  requirement: !ruby/object:Gem::Requirement
@@ -317,6 +317,7 @@ files:
317
317
  - examples/dsl_editor.rb
318
318
  - examples/dsl_hello_worlds.rb
319
319
  - examples/dsl_horizontal_alignment.rb
320
+ - examples/dsl_menus.rb
320
321
  - examples/dsl_vertical_alignment.rb
321
322
  - lib/vedeu.rb
322
323
  - lib/vedeu/all.rb
@@ -333,6 +334,7 @@ files:
333
334
  - lib/vedeu/borders/null.rb
334
335
  - lib/vedeu/borders/refresh.rb
335
336
  - lib/vedeu/borders/repository.rb
337
+ - lib/vedeu/borders/title.rb
336
338
  - lib/vedeu/buffers/all.rb
337
339
  - lib/vedeu/buffers/buffer.rb
338
340
  - lib/vedeu/buffers/null.rb
@@ -387,6 +389,7 @@ files:
387
389
  - lib/vedeu/editor/document.rb
388
390
  - lib/vedeu/editor/editor.rb
389
391
  - lib/vedeu/editor/insert.rb
392
+ - lib/vedeu/editor/item.rb
390
393
  - lib/vedeu/editor/line.rb
391
394
  - lib/vedeu/editor/lines.rb
392
395
  - lib/vedeu/editor/repository.rb
@@ -526,6 +529,7 @@ files:
526
529
  - test/lib/vedeu/borders/null_test.rb
527
530
  - test/lib/vedeu/borders/refresh_test.rb
528
531
  - test/lib/vedeu/borders/repository_test.rb
532
+ - test/lib/vedeu/borders/title_test.rb
529
533
  - test/lib/vedeu/buffers/buffer_test.rb
530
534
  - test/lib/vedeu/buffers/null_test.rb
531
535
  - test/lib/vedeu/buffers/refresh_test.rb
@@ -565,6 +569,7 @@ files:
565
569
  - test/lib/vedeu/editor/document_test.rb
566
570
  - test/lib/vedeu/editor/editor_test.rb
567
571
  - test/lib/vedeu/editor/insert_test.rb
572
+ - test/lib/vedeu/editor/item_test.rb
568
573
  - test/lib/vedeu/editor/line_test.rb
569
574
  - test/lib/vedeu/editor/lines_test.rb
570
575
  - test/lib/vedeu/editor/repository_test.rb
@@ -729,6 +734,7 @@ test_files:
729
734
  - test/lib/vedeu/borders/null_test.rb
730
735
  - test/lib/vedeu/borders/refresh_test.rb
731
736
  - test/lib/vedeu/borders/repository_test.rb
737
+ - test/lib/vedeu/borders/title_test.rb
732
738
  - test/lib/vedeu/buffers/buffer_test.rb
733
739
  - test/lib/vedeu/buffers/null_test.rb
734
740
  - test/lib/vedeu/buffers/refresh_test.rb
@@ -768,6 +774,7 @@ test_files:
768
774
  - test/lib/vedeu/editor/document_test.rb
769
775
  - test/lib/vedeu/editor/editor_test.rb
770
776
  - test/lib/vedeu/editor/insert_test.rb
777
+ - test/lib/vedeu/editor/item_test.rb
771
778
  - test/lib/vedeu/editor/line_test.rb
772
779
  - test/lib/vedeu/editor/lines_test.rb
773
780
  - test/lib/vedeu/editor/repository_test.rb