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
@@ -92,39 +92,6 @@ module Vedeu
92
92
  "border-#{direction}:1px #{char.foreground.to_html} solid;"
93
93
  end
94
94
 
95
- # # @return [String]
96
- # def fg
97
- # @fg ||= colour(char, 'foreground', '#222')
98
- # end
99
-
100
- # # @return [String]
101
- # def bg
102
- # @bg ||= colour(char, 'background', '#000')
103
- # end
104
-
105
- # @param char [Vedeu::Views::Char]
106
- # @param type [String] 'background' or 'foreground'
107
- # @param default [String] A default colour (CSS style; e.g. '#b2adf2')
108
- # @return [String]
109
- # def colour(char, type, default)
110
- # parent_type = char.send(:parent).send(type).send(:to_html)
111
- # #parent_type = ('parent_' + type).to_sym
112
- # type_to_html = char.send(type).send(:to_html)
113
- # #parent_type_to_html = char.send(parent_type).send(:to_html)
114
-
115
- # if present?(type_to_html)
116
- # type_to_html
117
-
118
- # elsif char.parent
119
- # parent_type
120
- # #char.parent.send(type).send(:to_html)
121
-
122
- # else
123
- # default
124
-
125
- # end
126
- # end
127
-
128
95
  # @return [Symbol|NilClass]
129
96
  def border
130
97
  char.border
@@ -10,8 +10,8 @@ module Vedeu
10
10
  end # Streams
11
11
 
12
12
  # Represents a character or collection of characters as part of a
13
- # {Vedeu::Views::Line} which you wish to colour and style independently of
14
- # the other characters in that line.
13
+ # {Vedeu::Views::Line} which you wish to colour and style
14
+ # independently of the other characters in that line.
15
15
  #
16
16
  class Stream
17
17
 
@@ -58,10 +58,10 @@ module Vedeu
58
58
  end
59
59
  alias_method :<<, :add
60
60
 
61
- # Returns an array of characters, each element is the escape sequences of
62
- # colours and styles for this stream, the character itself, and the escape
63
- # sequences of colours and styles for the parent of the stream
64
- # ({Vedeu::Views::Line}).
61
+ # Returns an array of characters, each element is the escape
62
+ # sequences of colours and styles for this stream, the character
63
+ # itself, and the escape sequences of colours and styles for the
64
+ # parent of the stream ({Vedeu::Views::Line}).
65
65
  #
66
66
  # @return [Array]
67
67
  def chars
@@ -87,7 +87,8 @@ module Vedeu
87
87
  end
88
88
  alias_method :==, :eql?
89
89
 
90
- # Returns the size of the content in characters without formatting.
90
+ # Returns the size of the content in characters without
91
+ # formatting.
91
92
  #
92
93
  # @return [Fixnum]
93
94
  def size
@@ -9,8 +9,8 @@ module Vedeu
9
9
 
10
10
  end # ViewCollection
11
11
 
12
- # Represents a container for {Vedeu::Views::Line} and {Vedeu::Views::Stream}
13
- # objects.
12
+ # Represents a container for {Vedeu::Views::Line} and
13
+ # {Vedeu::Views::Stream} objects.
14
14
  #
15
15
  class View
16
16
 
@@ -80,7 +80,7 @@ module Vedeu
80
80
  def render
81
81
  return [] unless visible?
82
82
 
83
- Vedeu.trigger(:_clear_, name)
83
+ Vedeu.trigger(:_clear_view_, name)
84
84
 
85
85
  output = [
86
86
  Vedeu::Output::Viewport.render(self),
@@ -90,21 +90,21 @@ module Vedeu
90
90
  output
91
91
  end
92
92
 
93
- # Store the view and immediately refresh it; causing to be pushed to the
94
- # Terminal. Called by {Vedeu::DSL::View.renders}.
93
+ # Store the view and immediately refresh it; causing to be
94
+ # pushed to the Terminal. Called by {Vedeu::DSL::View.renders}.
95
95
  #
96
96
  # @return [Vedeu::Views::View]
97
97
  def store_immediate
98
98
  store_deferred
99
99
 
100
- Vedeu.trigger(:_refresh_, name)
100
+ Vedeu.trigger(:_refresh_view_, name)
101
101
 
102
102
  self
103
103
  end
104
104
 
105
- # When a name is given, the view is stored with this name. This view will
106
- # be shown next time a refresh event is triggered with this name.
107
- # Called by {Vedeu::DSL::View.views}.
105
+ # When a name is given, the view is stored with this name. This
106
+ # view will be shown next time a refresh event is triggered with
107
+ # this name. Called by {Vedeu::DSL::View.views}.
108
108
  #
109
109
  # @raise [Vedeu::Error::InvalidSyntax] The name is not defined.
110
110
  # @return [Vedeu::Views::View]
data/lib/vedeu/options.rb CHANGED
@@ -8,7 +8,7 @@ module Vedeu
8
8
  # @param options [Hash]
9
9
  # @param defaults [Hash]
10
10
  def initialize(options = {}, defaults = {})
11
- @options = options || {}
11
+ @options = options || {}
12
12
  @defaults = defaults || {}
13
13
 
14
14
  @defaults.merge!(@options).each do |key, value|
@@ -0,0 +1,13 @@
1
+ module Vedeu
2
+
3
+ # Provides the mechanisms to clear an interface or group of
4
+ # interfaces.
5
+ #
6
+ module Clear
7
+
8
+ end # Clear
9
+
10
+ end # Vedeu
11
+
12
+ require 'vedeu/output/clear/group'
13
+ require 'vedeu/output/clear/interface'
@@ -1,13 +1,10 @@
1
1
  module Vedeu
2
2
 
3
- # Provides the mechanisms to clear an interface or group of
4
- # interfaces.
5
- #
6
3
  module Clear
7
4
 
8
5
  # Clear the interfaces belonging to the named group.
9
6
  #
10
- class NamedGroup
7
+ class Group
11
8
 
12
9
  class << self
13
10
 
@@ -26,17 +23,17 @@ module Vedeu
26
23
 
27
24
  end # Eigenclass
28
25
 
29
- # Return a new instance of Vedeu::Clear::NamedGroup.
26
+ # Return a new instance of Vedeu::Clear::Group.
30
27
  #
31
28
  # @param name [String]
32
- # @return [Vedeu::Clear::NamedGroup]
29
+ # @return [Vedeu::Clear::Group]
33
30
  def initialize(name)
34
31
  @name = name
35
32
  end
36
33
 
37
34
  # @return [void]
38
35
  def render
39
- members.each { |name| Vedeu::Clear::NamedInterface.render(name) }
36
+ members.each { |name| Vedeu::Clear::Interface.render(name) }
40
37
  end
41
38
 
42
39
  protected
@@ -1,13 +1,10 @@
1
1
  module Vedeu
2
2
 
3
- # Provides the mechanisms to clear an interface or group of
4
- # interfaces.
5
- #
6
3
  module Clear
7
4
 
8
5
  # Clear the named interface.
9
6
  #
10
- class NamedInterface
7
+ class Interface
11
8
 
12
9
  class << self
13
10
 
@@ -26,10 +23,10 @@ module Vedeu
26
23
 
27
24
  end # Eigenclass
28
25
 
29
- # Return a new instance of Vedeu::Clear::NamedInterface.
26
+ # Return a new instance of Vedeu::Clear::Interface.
30
27
  #
31
28
  # @param name [String] The name of the interface to clear.
32
- # @return [Vedeu::Clear::NamedInterface]
29
+ # @return [Vedeu::Clear::Interface]
33
30
  def initialize(name)
34
31
  @name = name
35
32
  end
@@ -81,7 +78,7 @@ module Vedeu
81
78
  end
82
79
  end
83
80
 
84
- end # NamedInterface
81
+ end # Interface
85
82
 
86
83
  end # Clear
87
84
 
@@ -22,8 +22,8 @@ module Vedeu
22
22
  # @return [Vedeu::Output::Direct]
23
23
  def initialize(value:, x:, y:)
24
24
  @value = value || ''
25
- @x = x || 1
26
- @y = y || 1
25
+ @x = x || 1
26
+ @y = y || 1
27
27
  end
28
28
 
29
29
  # @return [String]
@@ -24,6 +24,14 @@ module Vedeu
24
24
 
25
25
  private
26
26
 
27
+ # Returns a boolean indicating the model has a position
28
+ # attribute.
29
+ #
30
+ # @return [Boolean]
31
+ def position?
32
+ self.respond_to?(:position) && position.is_a?(Vedeu::Geometry::Position)
33
+ end
34
+
27
35
  # Renders the colour attributes of the receiver and yields (to
28
36
  # then render the styles).
29
37
  #
@@ -34,14 +42,9 @@ module Vedeu
34
42
 
35
43
  # @return [String]
36
44
  def render_position
37
- if self.respond_to?(:position) &&
38
- position.is_a?(Vedeu::Geometry::Position)
39
- position.to_s { yield }
40
-
41
- else
42
- yield
45
+ return yield unless position?
43
46
 
44
- end
47
+ position.to_s { yield }
45
48
  end
46
49
 
47
50
  # Renders the style attributes of the receiver and yields (to
@@ -82,14 +82,14 @@ module Vedeu
82
82
  #
83
83
  # @return [Set]
84
84
  def reset
85
- @storage = Set.new
85
+ @storage = in_memory
86
86
  end
87
87
 
88
88
  private
89
89
 
90
90
  # @return [Set]
91
- def storage
92
- @storage ||= reset
91
+ def in_memory
92
+ Set.new
93
93
  end
94
94
 
95
95
  # @return [Mutex]
@@ -97,11 +97,16 @@ module Vedeu
97
97
  @mutex ||= Mutex.new
98
98
  end
99
99
 
100
+ # @return [Set]
101
+ def storage
102
+ @storage ||= in_memory
103
+ end
104
+
100
105
  end # Renderers
101
106
 
102
107
  end # Vedeu
103
108
 
104
- require 'vedeu/output/renderers/renderer_options'
109
+ require 'vedeu/output/renderers/options'
105
110
  require 'vedeu/output/renderers/escape_sequence'
106
111
  require 'vedeu/output/renderers/file'
107
112
  require 'vedeu/output/renderers/html'
@@ -6,7 +6,7 @@ module Vedeu
6
6
  #
7
7
  class EscapeSequence
8
8
 
9
- include Vedeu::Renderers::RendererOptions
9
+ include Vedeu::Renderers::Options
10
10
 
11
11
  # Returns a new instance of Vedeu::Renderers::EscapeSequence.
12
12
  #
@@ -6,7 +6,7 @@ module Vedeu
6
6
  #
7
7
  class File
8
8
 
9
- include Vedeu::Renderers::RendererOptions
9
+ include Vedeu::Renderers::Options
10
10
 
11
11
  # Returns a new instance of Vedeu::Renderers::File.
12
12
  #
@@ -6,7 +6,7 @@ module Vedeu
6
6
  #
7
7
  class Null
8
8
 
9
- include Vedeu::Renderers::RendererOptions
9
+ include Vedeu::Renderers::Options
10
10
 
11
11
  # Returns a new instance of Vedeu::Renderers::Null.
12
12
  #
@@ -5,7 +5,7 @@ module Vedeu
5
5
  # Provides shared functionality to Vedeu::Renderer classes.
6
6
  #
7
7
  # :nocov:
8
- module RendererOptions
8
+ module Options
9
9
 
10
10
  private
11
11
 
@@ -24,7 +24,7 @@ module Vedeu
24
24
  {}
25
25
  end
26
26
 
27
- end # RendererOptions
27
+ end # Options
28
28
  # :nocov:
29
29
 
30
30
  end # Renderers
@@ -7,7 +7,7 @@ module Vedeu
7
7
  #
8
8
  class Terminal
9
9
 
10
- include Vedeu::Renderers::RendererOptions
10
+ include Vedeu::Renderers::Options
11
11
 
12
12
  # Returns a new instance of Vedeu::Renderers::Terminal.
13
13
  #
@@ -7,7 +7,7 @@ module Vedeu
7
7
  #
8
8
  class Text
9
9
 
10
- include Vedeu::Renderers::RendererOptions
10
+ include Vedeu::Renderers::Options
11
11
 
12
12
  # Returns a new instance of Vedeu::Renderers::Text.
13
13
  #
@@ -102,15 +102,11 @@ module Vedeu
102
102
  #
103
103
  # @return [Vedeu::Views::Line|Vedeu::Views::Stream]
104
104
  def content
105
- if model.is_a?(Vedeu::Views::View)
106
- stream.parent = line
107
- line.add(stream)
108
- line
105
+ return stream unless model.is_a?(Vedeu::Views::View)
109
106
 
110
- else
111
- stream
112
-
113
- end
107
+ stream.parent = line
108
+ line.add(stream)
109
+ line
114
110
  end
115
111
 
116
112
  # The default values for a new instance of this class.
@@ -137,13 +137,9 @@ module Vedeu
137
137
  # @param dimension [Fixnum] Either the height or width.
138
138
  # @return [Fixnum]
139
139
  def content_offset(offset, dimension)
140
- if offset >= dimension
141
- offset - dimension
140
+ return 0 unless offset >= dimension
142
141
 
143
- else
144
- 0
145
-
146
- end
142
+ offset - dimension
147
143
  end
148
144
 
149
145
  # Return the border associated with the interface/view we are
@@ -115,13 +115,9 @@ module Vedeu
115
115
  # @param string [String]
116
116
  # @return [String]
117
117
  def ellipsis_string(string)
118
- if string.size < ellipsis.size
119
- prune_string(string)
118
+ return prune_string(string) if string.size < ellipsis.size
120
119
 
121
- else
122
- "#{prune_string(string)}#{ellipsis}"
123
-
124
- end
120
+ "#{prune_string(string)}#{ellipsis}"
125
121
  end
126
122
 
127
123
  # Returns the string pruned.
@@ -65,13 +65,9 @@ module Vedeu
65
65
  def by_name(name)
66
66
  name ||= Vedeu.focus
67
67
 
68
- if registered?(name)
69
- find(name)
68
+ return find(name) if registered?(name)
70
69
 
71
- else
72
- null_model.new(name: name)
73
-
74
- end
70
+ null_model.new(name: name)
75
71
  end
76
72
 
77
73
  # Return the model for the interface currently in focus.
@@ -107,16 +103,12 @@ module Vedeu
107
103
  # @param name [String]
108
104
  # @return [void]
109
105
  def find_or_create(name)
110
- if registered?(name)
111
- find(name)
106
+ return find(name) if registered?(name)
112
107
 
113
- else
114
- Vedeu.log(type: :store,
115
- message: "Model (#{model}) not found, " \
116
- "registering: '#{name}'")
108
+ Vedeu.log(type: :store,
109
+ message: "Model (#{model}) not found, registering: '#{name}'")
117
110
 
118
- model.new(name).store
119
- end
111
+ model.new(name).store
120
112
  end
121
113
 
122
114
  # @return [String]
@@ -143,15 +135,10 @@ module Vedeu
143
135
  # @return [Hash|FalseClass]
144
136
  def remove(name)
145
137
  return false if empty?
138
+ return false unless registered?(name)
146
139
 
147
- if registered?(name)
148
- storage.delete(name)
149
- storage unless storage.is_a?(Set)
150
-
151
- else
152
- false
153
-
154
- end
140
+ storage.delete(name)
141
+ storage unless storage.is_a?(Set)
155
142
  end
156
143
  alias_method :destroy, :remove
157
144
  alias_method :delete, :remove