vedeu 0.6.15 → 0.6.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +2 -60
  3. data/config/rubocop_enabled.yml +6 -1023
  4. data/docs/events/refresh.md +6 -2
  5. data/docs/events/visibility.md +8 -3
  6. data/lib/vedeu.rb +4 -3
  7. data/lib/vedeu/all.rb +3 -2
  8. data/lib/vedeu/api/external.rb +6 -6
  9. data/lib/vedeu/bindings/bindings.rb +3 -3
  10. data/lib/vedeu/bindings/movement.rb +4 -4
  11. data/lib/vedeu/bindings/refresh.rb +9 -9
  12. data/lib/vedeu/bindings/visibility.rb +10 -12
  13. data/lib/vedeu/buffers/buffer.rb +1 -1
  14. data/lib/vedeu/buffers/refresh.rb +1 -1
  15. data/lib/vedeu/colours/repository.rb +1 -0
  16. data/lib/vedeu/colours/translator.rb +2 -6
  17. data/lib/vedeu/common.rb +2 -1
  18. data/lib/vedeu/configuration/api.rb +16 -7
  19. data/lib/vedeu/cursors/cursor.rb +12 -21
  20. data/lib/vedeu/cursors/refresh.rb +1 -1
  21. data/lib/vedeu/dsl/text.rb +21 -18
  22. data/lib/vedeu/dsl/use.rb +13 -11
  23. data/lib/vedeu/dsl/view.rb +52 -46
  24. data/lib/vedeu/editor/cursor.rb +2 -2
  25. data/lib/vedeu/editor/insert.rb +2 -6
  26. data/lib/vedeu/editor/line.rb +3 -8
  27. data/lib/vedeu/editor/lines.rb +1 -12
  28. data/lib/vedeu/events/event.rb +52 -43
  29. data/lib/vedeu/events/trigger.rb +7 -15
  30. data/lib/vedeu/geometry/generic_coordinate.rb +4 -12
  31. data/lib/vedeu/geometry/geometry.rb +1 -1
  32. data/lib/vedeu/input/translator.rb +50 -31
  33. data/lib/vedeu/models/focus.rb +33 -22
  34. data/lib/vedeu/models/group.rb +8 -7
  35. data/lib/vedeu/models/interface.rb +6 -10
  36. data/lib/vedeu/models/toggleable.rb +6 -9
  37. data/lib/vedeu/models/views/char.rb +24 -30
  38. data/lib/vedeu/models/views/html_char.rb +0 -33
  39. data/lib/vedeu/models/views/stream.rb +8 -7
  40. data/lib/vedeu/models/views/view.rb +9 -9
  41. data/lib/vedeu/options.rb +1 -1
  42. data/lib/vedeu/output/clear/all.rb +13 -0
  43. data/lib/vedeu/output/clear/{named_group.rb → group.rb} +4 -7
  44. data/lib/vedeu/output/clear/{named_interface.rb → interface.rb} +4 -7
  45. data/lib/vedeu/output/direct.rb +2 -2
  46. data/lib/vedeu/output/presentation/presentation.rb +10 -7
  47. data/lib/vedeu/output/renderers/all.rb +9 -4
  48. data/lib/vedeu/output/renderers/escape_sequence.rb +1 -1
  49. data/lib/vedeu/output/renderers/file.rb +1 -1
  50. data/lib/vedeu/output/renderers/null.rb +1 -1
  51. data/lib/vedeu/output/renderers/{renderer_options.rb → options.rb} +2 -2
  52. data/lib/vedeu/output/renderers/terminal.rb +1 -1
  53. data/lib/vedeu/output/renderers/text.rb +1 -1
  54. data/lib/vedeu/output/text.rb +4 -8
  55. data/lib/vedeu/output/viewport.rb +2 -6
  56. data/lib/vedeu/output/wordwrap.rb +2 -6
  57. data/lib/vedeu/repositories/repository.rb +9 -22
  58. data/lib/vedeu/runtime/application.rb +2 -6
  59. data/lib/vedeu/templating/view_template.rb +7 -15
  60. data/lib/vedeu/version.rb +1 -1
  61. data/test/lib/vedeu/bindings/bindings_test.rb +32 -6
  62. data/test/lib/vedeu/bindings/refresh_test.rb +1 -0
  63. data/test/lib/vedeu/bindings/visibility_test.rb +1 -0
  64. data/test/lib/vedeu/buffers/buffer_test.rb +2 -2
  65. data/test/lib/vedeu/colours/background_test.rb +0 -18
  66. data/test/lib/vedeu/colours/foreground_test.rb +0 -18
  67. data/test/lib/vedeu/cursors/refresh_test.rb +5 -3
  68. data/test/lib/vedeu/events/aliases_test.rb +0 -6
  69. data/test/lib/vedeu/models/views/view_test.rb +1 -1
  70. data/test/lib/vedeu/output/clear/{named_group_test.rb → group_test.rb} +5 -5
  71. data/test/lib/vedeu/output/clear/{named_interface_test.rb → interface_test.rb} +4 -4
  72. data/test/lib/vedeu/output/renderers/{renderer_options_test.rb → options_test.rb} +2 -2
  73. data/vedeu.gemspec +1 -1
  74. metadata +14 -14
  75. data/config/rubocop_disabled.yml +0 -50
@@ -3,7 +3,7 @@
3
3
  ## Refresh Events
4
4
 
5
5
  ### :_refresh_
6
- Refreshes all registered interfaces or the named interface.
6
+ Refreshes all registered interfaces.
7
7
 
8
8
  The interfaces will be refreshed in z-index order, meaning that
9
9
  interfaces with a lower z-index will be drawn first. This means
@@ -11,7 +11,6 @@ overlapping interfaces will be drawn as specified. Hidden interfaces
11
11
  will be still refreshed in memory but not shown.
12
12
 
13
13
  Vedeu.trigger(:_refresh_)
14
- Vedeu.trigger(:_refresh_, name)
15
14
 
16
15
  ### :_refresh_cursor_
17
16
  Will cause the named cursor to refresh, or the cursor of the interface
@@ -23,3 +22,8 @@ which is currently in focus.
23
22
  Will cause all interfaces in the named group to refresh.
24
23
 
25
24
  Vedeu.trigger(:_refresh_group_, name)
25
+
26
+ ### :_refresh_view_
27
+ Will cause the named view to refresh.
28
+
29
+ Vedeu.trigger(:_refresh_view_, name)
@@ -3,11 +3,10 @@
3
3
  ## Visibility Events
4
4
 
5
5
  ### :_clear_
6
- Clears the whole terminal space, or when a name is given, the named
7
- interface area will be cleared.
6
+ Clears the whole terminal space.
8
7
 
9
8
  Vedeu.trigger(:_clear_)
10
- Vedeu.clear_by_name(name)
9
+ Vedeu.clear
11
10
 
12
11
  ### :_clear_group_
13
12
  Clears the spaces occupied by the interfaces belonging to the named
@@ -16,6 +15,12 @@ group.
16
15
  Vedeu.trigger(:_clear_group_, name)
17
16
  Vedeu.clear_by_group(name)
18
17
 
18
+ ### :_clear_view_
19
+ Clears the named view/interface area.
20
+
21
+ Vedeu.trigger(:_clear_view_, name)
22
+ Vedeu.clear_by_name(name)
23
+
19
24
  ### :_hide_cursor_
20
25
  Hide the cursor of the named interface or when a name is not given,
21
26
  the interface currently in focus.
data/lib/vedeu.rb CHANGED
@@ -22,7 +22,8 @@ require 'thor'
22
22
 
23
23
  require 'vedeu/logging/log'
24
24
 
25
- # Vedeu is a GUI framework for terminal/console applications written in Ruby.
25
+ # Vedeu is a GUI framework for terminal/console applications written
26
+ # in Ruby.
26
27
  #
27
28
  module Vedeu
28
29
 
@@ -39,8 +40,8 @@ module Vedeu
39
40
  end
40
41
 
41
42
  # :nocov:
42
- # When Vedeu is included within one of your classes, you should have all
43
- # API methods at your disposal.
43
+ # When Vedeu is included within one of your classes, you should have
44
+ # all API methods at your disposal.
44
45
  #
45
46
  # @example
46
47
  # class YourClassHere
data/lib/vedeu/all.rb CHANGED
@@ -18,8 +18,9 @@ require 'vedeu/models/toggleable'
18
18
 
19
19
  require 'vedeu/output/presentation/presentation'
20
20
  require 'vedeu/output/direct'
21
- require 'vedeu/output/clear/named_group'
22
- require 'vedeu/output/clear/named_interface'
21
+
22
+ require 'vedeu/output/clear/all'
23
+
23
24
  require 'vedeu/output/compressor'
24
25
  require 'vedeu/output/text'
25
26
  require 'vedeu/output/output'
@@ -138,16 +138,16 @@ module Vedeu
138
138
  def_delegators Vedeu::Runtime::Application, :exit
139
139
 
140
140
  # @!method clear
141
- # @see Vedeu::Terminal#clear
142
- def_delegators Vedeu::Terminal, :clear
141
+ # @see Vedeu::Terminal::Buffer#clear
142
+ def_delegators Vedeu::Terminal::Buffer, :clear
143
143
 
144
144
  # @!method clear_by_name
145
- # @see Vedeu::Clear::NamedInterface.render
146
- def_delegators Vedeu::Clear::NamedInterface, :clear_by_name
145
+ # @see Vedeu::Clear::Interface.render
146
+ def_delegators Vedeu::Clear::Interface, :clear_by_name
147
147
 
148
148
  # @!method clear_by_group
149
- # @see Vedeu::Clear::NamedGroup.render
150
- def_delegators Vedeu::Clear::NamedGroup, :clear_by_group
149
+ # @see Vedeu::Clear::Group.render
150
+ def_delegators Vedeu::Clear::Group, :clear_by_group
151
151
 
152
152
  # @!method hide_cursor
153
153
  # @see Vedeu::Cursors::Cursor#hide
@@ -12,14 +12,14 @@ module Vedeu
12
12
 
13
13
  Vedeu::Bindings::Application.setup!
14
14
  Vedeu::Bindings::Document.setup!
15
- Vedeu::Bindings::Visibility.setup!
16
- Vedeu::Bindings::Movement.setup!
17
- Vedeu::Bindings::Menus.setup!
18
15
  Vedeu::Bindings::DRB.setup!
19
16
  Vedeu::Bindings::Focus.setup!
17
+ Vedeu::Bindings::Menus.setup!
18
+ Vedeu::Bindings::Movement.setup!
20
19
  Vedeu::Bindings::Refresh.setup!
21
20
  Vedeu::Bindings::System.setup!
22
21
  Vedeu::Bindings::View.setup!
22
+ Vedeu::Bindings::Visibility.setup!
23
23
 
24
24
  true
25
25
  end
@@ -37,8 +37,8 @@ module Vedeu
37
37
 
38
38
  Vedeu.trigger(:_clear_)
39
39
  Vedeu.trigger(:_refresh_)
40
- Vedeu.trigger(:_clear_, name)
41
- Vedeu.trigger(:_refresh_, name)
40
+ Vedeu.trigger(:_clear_view_, name)
41
+ Vedeu.trigger(:_refresh_view_, name)
42
42
  end
43
43
 
44
44
  Vedeu.bind_alias("_geometry_#{direction}_".to_sym,
@@ -67,8 +67,8 @@ module Vedeu
67
67
  Vedeu.bind(:_cursor_reposition_) do |name, y, x|
68
68
  Vedeu.cursors.by_name(name).reposition(y, x)
69
69
 
70
- Vedeu.trigger(:_clear_, name)
71
- Vedeu.trigger(:_refresh_, name)
70
+ Vedeu.trigger(:_clear_view_, name)
71
+ Vedeu.trigger(:_refresh_view_, name)
72
72
  Vedeu.trigger(:_refresh_cursor_, name)
73
73
  end
74
74
  end
@@ -16,6 +16,7 @@ module Vedeu
16
16
  refresh!
17
17
  refresh_cursor!
18
18
  refresh_group!
19
+ refresh_view!
19
20
  end
20
21
 
21
22
  private
@@ -24,15 +25,7 @@ module Vedeu
24
25
 
25
26
  # See {file:docs/events/refresh.md#\_refresh_}
26
27
  def refresh!
27
- Vedeu.bind(:_refresh_) do |name|
28
- if name
29
- Vedeu::Buffers::Refresh.by_name(name)
30
-
31
- else
32
- Vedeu::Output::Refresh.all
33
-
34
- end
35
- end
28
+ Vedeu.bind(:_refresh_) { Vedeu::Output::Refresh.all }
36
29
  end
37
30
 
38
31
  # See {file:docs/events/refresh.md#\_refresh_cursor_}
@@ -49,6 +42,13 @@ module Vedeu
49
42
  end
50
43
  end
51
44
 
45
+ # See {file:docs/events/refresh.md#\_refresh_view_}
46
+ def refresh_view!
47
+ Vedeu.bind(:_refresh_view_) do |name|
48
+ Vedeu::Buffers::Refresh.by_name(name)
49
+ end
50
+ end
51
+
52
52
  # :nocov:
53
53
 
54
54
  end # Refresh
@@ -16,6 +16,7 @@ module Vedeu
16
16
  def setup!
17
17
  clear!
18
18
  clear_group!
19
+ clear_view!
19
20
  hide_cursor!
20
21
  hide_group!
21
22
  hide_interface!
@@ -31,23 +32,20 @@ module Vedeu
31
32
 
32
33
  # :nocov:
33
34
 
34
- # See {file:docs/events/system.md#\_cleanup_}
35
+ # See {file:docs/events/visibility.md#\_cleanup_}
35
36
  def clear!
36
- Vedeu.bind(:_clear_) do |name|
37
- if name
38
- Vedeu::Clear::NamedInterface.render(name)
39
-
40
- else
41
- Vedeu::Terminal::Buffer.clear
42
-
43
- end
44
- end
37
+ Vedeu.bind(:_clear_) { Vedeu::Terminal::Buffer.clear }
45
38
  end
46
39
 
47
40
  # See {file:docs/events/visibility.md#\_clear_group_}
48
41
  def clear_group!
49
- Vedeu.bind(:_clear_group_) do |name|
50
- Vedeu::Clear::NamedGroup.render(name)
42
+ Vedeu.bind(:_clear_group_) { |name| Vedeu::Clear::Group.render(name) }
43
+ end
44
+
45
+ # See {file:docs/events/visibility.md#\_clear_view_}
46
+ def clear_view!
47
+ Vedeu.bind(:_clear_view_) do |name|
48
+ Vedeu::Clear::Interface.render(name)
51
49
  end
52
50
  end
53
51
 
@@ -108,7 +108,7 @@ module Vedeu
108
108
  #
109
109
  # @return [Array<Array<Array<Vedeu::Views::Char>>>]
110
110
  def hide
111
- Vedeu.trigger(:_clear_, name)
111
+ Vedeu.trigger(:_clear_view_, name)
112
112
  end
113
113
 
114
114
  # Return the content for this buffer.
@@ -5,7 +5,7 @@ module Vedeu
5
5
  # Refreshes the given named interface.
6
6
  #
7
7
  # @example
8
- # Vedeu.trigger(:_refresh_, name)
8
+ # Vedeu.trigger(:_refresh_view_, name)
9
9
  #
10
10
  class Refresh
11
11
 
@@ -54,6 +54,7 @@ module Vedeu
54
54
  # registers the colour with its respective escape sequence.
55
55
  #
56
56
  # @return [String]
57
+ # @todo Unused - GL 2015-09-26
57
58
  def retrieve_or_register(colour, escape_sequence)
58
59
  if registered?(colour)
59
60
  retrieve(colour)
@@ -39,13 +39,9 @@ module Vedeu
39
39
  # @param value [Object|NilClass]
40
40
  # @return [Object]
41
41
  def self.coerce(value)
42
- if value.is_a?(self)
43
- value
42
+ return value if value.is_a?(self)
44
43
 
45
- else
46
- new(value)
47
-
48
- end
44
+ new(value)
49
45
  end
50
46
 
51
47
  # Return a new instance of Vedeu::Colours::Translator.
data/lib/vedeu/common.rb CHANGED
@@ -21,7 +21,8 @@ module Vedeu
21
21
  #
22
22
  # @example
23
23
  # snake_case(MyClassName) # => "my_class_name"
24
- # snake_case(NameSpaced::ClassName) # => "name_spaced/class_name"
24
+ # snake_case(NameSpaced::ClassName)
25
+ # # => "name_spaced/class_name"
25
26
  #
26
27
  # @param name [String]
27
28
  # @return [String]
@@ -453,14 +453,9 @@ module Vedeu
453
453
  # @see Vedeu::Config::API#fake!
454
454
  # @see Vedeu::Config::API#raw!
455
455
  def terminal_mode(mode)
456
- if [:cooked, :fake, :raw].include?(mode)
457
- options[:terminal_mode] = mode
456
+ return invalid_mode! unless valid_mode?(mode)
458
457
 
459
- else
460
- fail Vedeu::Error::InvalidSyntax,
461
- 'Terminal mode can be set to either :cooked, :fake or :raw'
462
-
463
- end
458
+ options[:terminal_mode] = mode
464
459
  end
465
460
 
466
461
  # Sets the width of the terminal.
@@ -478,6 +473,12 @@ module Vedeu
478
473
 
479
474
  private
480
475
 
476
+ # @raise [Vedeu::Error::InvalidSyntax]
477
+ def invalid_mode!
478
+ fail Vedeu::Error::InvalidSyntax,
479
+ 'Terminal mode can be set to either :cooked, :fake or :raw'
480
+ end
481
+
481
482
  # Returns the options set via the configuration API DSL or an
482
483
  # empty Hash when none were set.
483
484
  #
@@ -494,6 +495,14 @@ module Vedeu
494
495
  value.is_a?(Fixnum) && [8, 16, 256, 16_777_216].include?(value)
495
496
  end
496
497
 
498
+ # Checks that the mode provided is valid.
499
+ #
500
+ # @param mode [Symbol] :cooked, :fake or :raw are valid
501
+ # @return [Boolean]
502
+ def valid_mode?(mode)
503
+ [:cooked, :fake, :raw].include?(mode)
504
+ end
505
+
497
506
  end # API
498
507
 
499
508
  end # Config
@@ -136,7 +136,7 @@ module Vedeu
136
136
  #
137
137
  # @return [Array<Vedeu::Models::Escape>]
138
138
  def render
139
- Vedeu::Output::Output.render(visibility)
139
+ Vedeu::Output::Output.render(escape_sequence)
140
140
  end
141
141
 
142
142
  # Arbitrarily move the cursor to a given position.
@@ -158,13 +158,9 @@ module Vedeu
158
158
  #
159
159
  # @return [String]
160
160
  def to_s
161
- if block_given?
162
- "#{position}#{yield}#{visibility}"
161
+ return escape_sequence.to_s unless block_given?
163
162
 
164
- else
165
- "#{visibility}"
166
-
167
- end
163
+ "#{position}#{yield}#{escape_sequence}"
168
164
  end
169
165
  alias_method :to_str, :to_s
170
166
 
@@ -221,13 +217,9 @@ module Vedeu
221
217
  #
222
218
  # @return [Vedeu::Models::Escape]
223
219
  def toggle
224
- if visible?
225
- hide
226
-
227
- else
228
- show
220
+ return hide if visible?
229
221
 
230
- end
222
+ show
231
223
  end
232
224
 
233
225
  # @return [Fixnum] The column/character coordinate.
@@ -277,6 +269,11 @@ module Vedeu
277
269
  }
278
270
  end
279
271
 
272
+ # @return [Vedeu::Models::Escape]
273
+ def escape_sequence
274
+ Vedeu::Models::Escape.new(position: position, value: visibility)
275
+ end
276
+
280
277
  # @return [Hash]
281
278
  def new_attributes(new_y = y, new_x = x, new_oy = oy, new_ox = ox)
282
279
  attributes.merge!(x: new_x, y: new_y, ox: new_ox, oy: new_oy)
@@ -287,15 +284,9 @@ module Vedeu
287
284
  #
288
285
  # @return [String]
289
286
  def visibility
290
- value = if visible?
291
- Vedeu::EscapeSequences::Esc.show_cursor
292
-
293
- else
294
- Vedeu::EscapeSequences::Esc.hide_cursor
295
-
296
- end
287
+ return Vedeu::EscapeSequences::Esc.show_cursor if visible?
297
288
 
298
- Vedeu::Models::Escape.new(position: position, value: value)
289
+ Vedeu::EscapeSequences::Esc.hide_cursor
299
290
  end
300
291
 
301
292
  end # Cursor
@@ -36,7 +36,7 @@ module Vedeu
36
36
  def by_name
37
37
  Vedeu.log(type: :info, message: "Refreshing cursor: '#{name}'")
38
38
 
39
- Vedeu.trigger(:_refresh_, name) if refresh_view?
39
+ Vedeu.trigger(:_refresh_view_, name) if refresh_view?
40
40
 
41
41
  cursor.render
42
42
  end
@@ -1,3 +1,4 @@
1
+
1
2
  module Vedeu
2
3
 
3
4
  module DSL
@@ -38,28 +39,30 @@ module Vedeu
38
39
  #
39
40
  # right 'This will be right aligned.', width: 35
40
41
  # # => ' This will be right aligned.'
41
-
42
- # right 'This will be right aligned.', width: 35, anchor: centre
43
- # # => ' This will be right aligned.'
44
42
  #
45
- # text 'This will be truncated here. More text here.', width: 28
46
- # # => 'This will be truncated here.'
43
+ # right 'This will be right aligned.', width: 35,
44
+ # anchor: centre
45
+ #
46
+ # text 'This will be truncated here. More text here.',
47
+ # width: 28 # => 'This will be truncated here.'
47
48
  #
48
- # text 'Padded with hyphens.', width: 25, pad: '-', anchor: :right
49
- # # => '-----Padded with hyphens.'
49
+ # text 'Padded with hyphens.', width: 25, pad: '-',
50
+ # anchor: :right # => '-----Padded with hyphens.'
50
51
  #
51
- # @param value [String|Object] A string or object that responds to `to_s`.
52
+ # @param value [String|Object] A string or object that responds
53
+ # to `to_s`.
52
54
  # @param options [Hash] Text options.
53
- # @option options :anchor [Symbol] One of `:left`, `:centre`/`:center`, or
54
- # `:right`.
55
- # @option options :width [Integer|NilClass] The width of the text stream
56
- # to add. If the `string` provided is longer than this value, the string
57
- # will be truncated. If no width is provided in the context of 'lines',
58
- # then the interface width is used. If no width is provided in the
59
- # context of a 'stream', then no alignment will occur.
60
- # @option options :pad [String] The character to use to pad the width, by
61
- # default uses an empty space (0x20). Only when the string is shorter
62
- # than the specified width.
55
+ # @option options :anchor [Symbol] One of `:left`,
56
+ # `:centre`/`:center`, or `:right`.
57
+ # @option options :width [Integer|NilClass] The width of the
58
+ # text stream to add. If the `string` provided is longer than
59
+ # this value, the string will be truncated. If no width is
60
+ # provided in the context of 'lines', then the interface width
61
+ # is used. If no width is provided in the context of a
62
+ # 'stream', then no alignment will occur.
63
+ # @option options :pad [String] The character to use to pad the
64
+ # width, by default uses an empty space (0x20). Only when the
65
+ # string is shorter than the specified width.
63
66
  # @return [String]
64
67
  def text(value = '', options = {})
65
68
  options.merge!(anchor: __callee__, model: model)