vedeu 0.4.16 → 0.4.17

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/lib/vedeu/api.rb +7 -21
  3. data/lib/vedeu/bindings.rb +2 -6
  4. data/lib/vedeu/buffers/buffer.rb +29 -34
  5. data/lib/vedeu/cursor/cursor.rb +5 -2
  6. data/lib/vedeu/distributed/all.rb +5 -5
  7. data/lib/vedeu/distributed/server.rb +1 -1
  8. data/lib/vedeu/dsl/components/border.rb +1 -2
  9. data/lib/vedeu/dsl/components/geometry.rb +0 -47
  10. data/lib/vedeu/dsl/interface.rb +4 -11
  11. data/lib/vedeu/dsl/line.rb +1 -2
  12. data/lib/vedeu/dsl/shared/all.rb +1 -2
  13. data/lib/vedeu/dsl/shared/{colour.rb → presentation.rb} +27 -4
  14. data/lib/vedeu/dsl/shared/use.rb +50 -29
  15. data/lib/vedeu/dsl/stream.rb +1 -2
  16. data/lib/vedeu/geometry/geometry.rb +22 -11
  17. data/lib/vedeu/geometry/index_position.rb +0 -19
  18. data/lib/vedeu/geometry/position_validator.rb +8 -8
  19. data/lib/vedeu/models/interface.rb +34 -76
  20. data/lib/vedeu/models/null_interface.rb +5 -0
  21. data/lib/vedeu/models/stream.rb +1 -1
  22. data/lib/vedeu/output/border.rb +25 -41
  23. data/lib/vedeu/output/clear.rb +1 -7
  24. data/lib/vedeu/output/esc.rb +10 -10
  25. data/lib/vedeu/output/presentation.rb +2 -0
  26. data/lib/vedeu/output/renderers/escape_sequence_renderer.rb +3 -0
  27. data/lib/vedeu/repositories/model.rb +6 -0
  28. data/lib/vedeu/repositories/repositories/groups.rb +12 -0
  29. data/lib/vedeu/repositories/repository.rb +11 -8
  30. data/lib/vedeu/storage/all.rb +4 -4
  31. data/lib/vedeu/support/visibility.rb +8 -0
  32. data/test/lib/vedeu/buffers/buffer_test.rb +0 -2
  33. data/test/lib/vedeu/cursor/cursor_test.rb +14 -0
  34. data/test/lib/vedeu/dsl/components/border_test.rb +2 -2
  35. data/test/lib/vedeu/dsl/components/geometry_test.rb +63 -82
  36. data/test/lib/vedeu/dsl/components/keymap_test.rb +3 -3
  37. data/test/lib/vedeu/dsl/components/menu_test.rb +8 -8
  38. data/test/lib/vedeu/dsl/interface_test.rb +14 -22
  39. data/test/lib/vedeu/dsl/line_test.rb +4 -4
  40. data/test/lib/vedeu/dsl/shared/{colour_test.rb → presentation_test.rb} +19 -11
  41. data/test/lib/vedeu/dsl/shared/text_test.rb +15 -15
  42. data/test/lib/vedeu/dsl/shared/use_test.rb +24 -7
  43. data/test/lib/vedeu/geometry/geometry_test.rb +22 -19
  44. data/test/lib/vedeu/geometry/grid_test.rb +3 -3
  45. data/test/lib/vedeu/geometry/index_position_test.rb +0 -45
  46. data/test/lib/vedeu/geometry/position_test.rb +5 -5
  47. data/test/lib/vedeu/models/cell_test.rb +3 -3
  48. data/test/lib/vedeu/models/char_test.rb +5 -5
  49. data/test/lib/vedeu/models/interface_test.rb +7 -53
  50. data/test/lib/vedeu/models/null_test.rb +2 -2
  51. data/test/lib/vedeu/models/stream_test.rb +5 -5
  52. data/test/lib/vedeu/output/border_test.rb +1 -0
  53. data/test/lib/vedeu/output/colour_test.rb +16 -16
  54. data/test/lib/vedeu/output/esc_test.rb +15 -1
  55. data/test/lib/vedeu/output/html_char_test.rb +4 -4
  56. data/test/lib/vedeu/output/style_test.rb +15 -13
  57. data/test/lib/vedeu/output/text_test.rb +3 -3
  58. data/test/lib/vedeu/repositories/collection_test.rb +2 -2
  59. data/test/lib/vedeu/repositories/model_test.rb +19 -0
  60. data/test/lib/vedeu/repositories/repositories/groups_test.rb +22 -0
  61. data/test/lib/vedeu/repositories/repository_test.rb +50 -16
  62. data/test/lib/vedeu/support/common_test.rb +5 -5
  63. data/test/lib/vedeu/support/terminal_test.rb +3 -3
  64. data/test/lib/vedeu/support/visibility_test.rb +8 -0
  65. data/test/support/helpers/model_test_class.rb +18 -0
  66. data/test/test_helper.rb +1 -1
  67. data/vedeu.gemspec +2 -2
  68. metadata +7 -20
  69. data/lib/vedeu/dsl/shared/style.rb +0 -39
  70. data/test/lib/vedeu/dsl/shared/style_test.rb +0 -25
  71. data/test/support/helpers/all.rb +0 -5
  72. data/test/support/helpers/dsl_model_test_class.rb +0 -25
  73. data/test/support/helpers/helpers.rb +0 -17
  74. data/test/support/helpers/repositories.rb +0 -26
  75. data/test/support/helpers/repository_test_module.rb +0 -21
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4a9751fe9473165039b61060cd75848373362b2e
4
- data.tar.gz: f26036519a3f79b436bbe48dc6ff56c0be95ee5e
3
+ metadata.gz: adae57ef3023290f75d36a2744e07ef707297278
4
+ data.tar.gz: ae4a68bbb7eb2254a774a93bfc41eac41b9e57b2
5
5
  SHA512:
6
- metadata.gz: a6cf213571c0d78127d30f13d5b7371e6f35ed841e5df29943082c43ecf2be8e6254a0959acfeddf119f1f4807a30540948d420399d727c8e3b365da2628c80c
7
- data.tar.gz: 65f8b8ab0fe4bfec7074ac7d1c54294b04a764f9e9303fc2da3c27fec296c6c87897ee402f5d04e3289bd46efdc34de635eb6210ed06e1865516f78ddee3e7dd
6
+ metadata.gz: 70f4525ba7779abc257a051e2c82952f36ec208a207f511d67c70a1eb7e5d8c0ff741c36fc54c887a7265580bfc042e18de418b537af661af332317980806ce6
7
+ data.tar.gz: be52af102efe89af2e0b17419ce9bae9b815eb45516a72970f7f4efafe74614f8516912e2602fd2c066bdcdad3af1a823bc47cd8b5d32f0da0ea3f824326cf55
@@ -95,8 +95,7 @@ module Vedeu
95
95
  # @see Vedeu::Event.bind
96
96
  # @!method unbind
97
97
  # @see Vedeu::Event.unbind
98
- def_delegators Vedeu::Event, :bind,
99
- :unbind
98
+ def_delegators Vedeu::Event, :bind, :unbind
100
99
 
101
100
  # @!method trigger
102
101
  # @see Vedeu::Trigger.trigger
@@ -106,8 +105,7 @@ module Vedeu
106
105
  # @see Vedeu::Configuration.configure
107
106
  # @!method configuration
108
107
  # @see Vedeu::Configuration.configuration
109
- def_delegators Vedeu::Configuration, :configure,
110
- :configuration
108
+ def_delegators Vedeu::Configuration, :configure, :configuration
111
109
 
112
110
  # @!method border
113
111
  # @see Vedeu::DSL::Border.border
@@ -125,19 +123,13 @@ module Vedeu
125
123
  # @see Vedeu::DSL::Group.group
126
124
  def_delegators Vedeu::DSL::Group, :group
127
125
 
128
- # @!method use
129
- # @see Vedeu::DSL::Use#use
130
- def_delegators Vedeu::DSL::Use, :use
131
-
132
126
  # @!method interface
133
127
  # @see Vedeu::DSL::View.interface
134
128
  # @!method renders
135
129
  # @see Vedeu::DSL::View.renders
136
130
  # @!method views
137
131
  # @see Vedeu::DSL::View.views
138
- def_delegators Vedeu::DSL::View, :interface,
139
- :renders,
140
- :views
132
+ def_delegators Vedeu::DSL::View, :interface, :renders, :views
141
133
 
142
134
  # @!method focus
143
135
  # @see Vedeu::Focus#focus
@@ -149,11 +141,8 @@ module Vedeu
149
141
  # @see Vedeu::Focus#focus_next
150
142
  # @!method focus_previous
151
143
  # @see Vedeu::Focus#focus_previous
152
- def_delegators Vedeu::Focus, :focus,
153
- :focus_by_name,
154
- :focussed?,
155
- :focus_next,
156
- :focus_previous
144
+ def_delegators Vedeu::Focus, :focus, :focus_by_name, :focussed?,
145
+ :focus_next, :focus_previous
157
146
 
158
147
  # @!method log
159
148
  # @see Vedeu::Log.log
@@ -169,16 +158,13 @@ module Vedeu
169
158
  # @see Vedeu::Terminal#width
170
159
  # @!method resize
171
160
  # @see Vedeu::Terminal#resize
172
- def_delegators Vedeu::Terminal, :height,
173
- :width,
174
- :resize
161
+ def_delegators Vedeu::Terminal, :height, :width, :resize
175
162
 
176
163
  # @!method renderer
177
164
  # @see Vedeu::Renderers#renderer
178
165
  # @!method renderers
179
166
  # @see Vedeu::Renderers#renderers
180
- def_delegators Vedeu::Renderers, :renderer,
181
- :renderers
167
+ def_delegators Vedeu::Renderers, :renderer, :renderers
182
168
 
183
169
  end # API
184
170
 
@@ -93,16 +93,12 @@ module Vedeu
93
93
 
94
94
  # Hide the cursor of the named interface or interface currently in focus.
95
95
  Vedeu.bind(:_cursor_hide_) do |name|
96
- named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
97
-
98
- Vedeu::Visibility.hide(named)
96
+ Vedeu::Visibility.for_cursor(name).hide
99
97
  end
100
98
 
101
99
  # Show the cursor of the named interface or interface currently in focus.
102
100
  Vedeu.bind(:_cursor_show_) do |name|
103
- named = name ? Vedeu.cursors.by_name(name) : Vedeu.cursor
104
-
105
- Vedeu::Visibility.show(named)
101
+ Vedeu::Visibility.for_cursor(name).show
106
102
  end
107
103
 
108
104
  # @see {Vedeu::Move}
@@ -43,27 +43,21 @@ module Vedeu
43
43
  # @option attributes front [Interface]
44
44
  # @option attributes previous [Interface]
45
45
  # @option attributes repository [Vedeu::Buffers]
46
- # @return [Buffer]
46
+ # @return [Vedeu::Buffer]
47
47
  def initialize(attributes = {})
48
48
  @attributes = defaults.merge!(attributes)
49
49
 
50
- @name = @attributes[:name]
51
- @back = @attributes[:back]
52
- @front = @attributes[:front]
53
- @previous = @attributes[:previous]
54
- @repository = @attributes[:repository] || Vedeu.buffers
50
+ @attributes.each do |key, value|
51
+ instance_variable_set("@#{key}", value)
52
+ end
55
53
  end
56
54
 
57
- # Add the content to the back buffer, then update the repository. Returns
58
- # boolean indicating that the repository was updated. Here we also apply any
59
- # overridden colours or styles in the buffered view to the stored interface.
55
+ # Add the content to the back buffer, then update the repository.
56
+ # Returns boolean indicating that the repository was updated.
60
57
  #
61
- # @param content [Interface]
58
+ # @param content [Vedeu::Interface]
62
59
  # @return [Boolean]
63
60
  def add(content)
64
- content.colour = interface.colour unless content.colour
65
- content.style = interface.style unless content.style
66
-
67
61
  @back = content
68
62
 
69
63
  store
@@ -82,24 +76,8 @@ module Vedeu
82
76
  # 'previous' buffer.
83
77
  # - If the 'previous' buffer is empty, return an empty collection.
84
78
  #
85
- # @return [Array<Hash>]
79
+ # @return [Array<Array<Array<Vedeu::Char>>>]
86
80
  def render
87
- buffer = if content_for?(:back)
88
- swap
89
-
90
- [front.render]
91
-
92
- elsif content_for?(:front)
93
- [front.render]
94
-
95
- elsif content_for?(:previous)
96
- [previous.render]
97
-
98
- else
99
- []
100
-
101
- end
102
-
103
81
  Vedeu::Output.render(buffer) unless buffer.empty?
104
82
 
105
83
  buffer
@@ -117,6 +95,22 @@ module Vedeu
117
95
 
118
96
  private
119
97
 
98
+ # @return [Array<Array<Array<Vedeu::Char>>>]
99
+ def buffer
100
+ swap if content_for?(:back)
101
+
102
+ if content_for?(:front)
103
+ [front.render]
104
+
105
+ elsif content_for?(:previous)
106
+ [previous.render]
107
+
108
+ else
109
+ []
110
+
111
+ end
112
+ end
113
+
120
114
  # @return [void]
121
115
  def clear_buffer
122
116
  @clear_buffer ||= Vedeu::Clear.new(view).clear
@@ -125,10 +119,11 @@ module Vedeu
125
119
  # @return [Hash<Symbol => NilClass, String>]
126
120
  def defaults
127
121
  {
128
- back: nil,
129
- front: nil,
130
- name: '',
131
- previous: nil,
122
+ back: nil,
123
+ front: nil,
124
+ name: '',
125
+ previous: nil,
126
+ repository: Vedeu.buffers,
132
127
  }
133
128
  end
134
129
 
@@ -8,8 +8,11 @@ module Vedeu
8
8
  #
9
9
  class Cursor
10
10
 
11
+ extend Forwardable
11
12
  include Vedeu::Model
12
13
 
14
+ def_delegators Vedeu::Esc, :hide_cursor, :show_cursor
15
+
13
16
  # @!attribute [r] attributes
14
17
  # @return [Hash]
15
18
  attr_reader :attributes
@@ -133,10 +136,10 @@ module Vedeu
133
136
  # @return [String]
134
137
  def visibility
135
138
  if visible?
136
- Vedeu::Esc.string('show_cursor')
139
+ show_cursor
137
140
 
138
141
  else
139
- Vedeu::Esc.string('hide_cursor')
142
+ hide_cursor
140
143
 
141
144
  end
142
145
  end
@@ -1,8 +1,8 @@
1
- require 'vedeu/distributed/uri'
2
- require 'vedeu/distributed/server'
3
- require 'vedeu/distributed/client'
4
- require 'vedeu/distributed/subprocess'
5
- require 'vedeu/distributed/test_application'
1
+ require_relative 'uri'
2
+ require_relative 'server'
3
+ require_relative 'client'
4
+ require_relative 'subprocess'
5
+ require_relative 'test_application'
6
6
 
7
7
  module Vedeu
8
8
 
@@ -66,7 +66,7 @@ module Vedeu
66
66
 
67
67
  # @return [void]
68
68
  def restart
69
- log('Attempting to restart')
69
+ log('Attempting to restart')
70
70
 
71
71
  return not_enabled unless drb?
72
72
 
@@ -25,8 +25,7 @@ module Vedeu
25
25
  class Border
26
26
 
27
27
  include Vedeu::DSL
28
- include Vedeu::DSL::Colour
29
- include Vedeu::DSL::Style
28
+ include Vedeu::DSL::Presentation
30
29
 
31
30
  # Specify the border of an interface or view with a simple DSL.
32
31
  #
@@ -78,53 +78,6 @@ module Vedeu
78
78
  model.height = value
79
79
  end
80
80
 
81
- # Use the geometry of another interface as the basis for the geometry you
82
- # are creating.
83
- #
84
- # @example
85
- # geometry 'some_interface' do
86
- # use 'other_interface' # will fetch the geometry of 'other_interface'
87
- # # ...
88
- #
89
- # geometry 'other_interface' do
90
- # centred!
91
- # height 4
92
- # # ...
93
- #
94
- # geometry 'some_interface' do
95
- # use 'other_interface' # will fetch the geometry of 'other_interface'
96
- # centred false
97
- # # ...
98
- #
99
- # @note
100
- # - When using 'use', the 'other_interface' (from the example) must
101
- # already exist.
102
- # - When using 'use', note that geometry defined before it's invocation
103
- # will be overwritten by 'other_interface',
104
- # - and geometry defined after will overwrite the inherited geometry.
105
- # - Special geometry settings, like 'centred' also cause unexpected
106
- # behaviour. If 'other_interface' was centred, then 'some_interface'
107
- # will also be centred, to disable this, declare 'some_interface' to
108
- # not be centred.
109
- #
110
- # @param name [String] The name of the interface you wish to use the
111
- # geometry of.
112
- # @raise [ModelNotFound] When the geometry to be used does not exist yet.
113
- # @return [Vedeu::Geometry]
114
- # def use(name)
115
- # if Vedeu.geometries.registered?(name)
116
- # other = Vedeu.geometries.find(name).dup
117
- # other.name = name
118
- # @model = other
119
- # @model.store
120
-
121
- # else
122
- # fail ModelNotFound, "Cannot use the geometry of '#{name}', as it " \
123
- # "is not yet defined."
124
-
125
- # end
126
- # end
127
-
128
81
  # Specify the number of characters/columns wide the interface will be.
129
82
  #
130
83
  # @param value [Fixnum]
@@ -16,8 +16,7 @@ module Vedeu
16
16
 
17
17
  include Vedeu::Common
18
18
  include Vedeu::DSL
19
- include Vedeu::DSL::Colour
20
- include Vedeu::DSL::Style
19
+ include Vedeu::DSL::Presentation
21
20
  include Vedeu::DSL::Text
22
21
  include Vedeu::DSL::Use
23
22
 
@@ -152,19 +151,13 @@ module Vedeu
152
151
  #
153
152
  # @param name [String] The name of the group to which this interface
154
153
  # should belong.
155
- # @return [String]
154
+ # @return [Vedeu::Group]
156
155
  def group(name)
157
156
  return false unless defined_value?(name)
158
- model.group = name
159
-
160
- if Vedeu.groups.registered?(name)
161
- Vedeu.groups.find(name).add(model.name)
162
157
 
163
- else
164
- new_group = Vedeu::Group.new(name: name)
165
- new_group.add(model.name)
158
+ model.group = name
166
159
 
167
- end
160
+ Vedeu.groups.by_name(name).add(model.name)
168
161
  end
169
162
 
170
163
  # @see Vedeu::DSL::Keymap.keymap
@@ -38,8 +38,7 @@ module Vedeu
38
38
  class Line
39
39
 
40
40
  include Vedeu::DSL
41
- include Vedeu::DSL::Colour
42
- include Vedeu::DSL::Style
41
+ include Vedeu::DSL::Presentation
43
42
  include Vedeu::DSL::Text
44
43
 
45
44
  # Returns an instance of DSL::Line.
@@ -1,4 +1,3 @@
1
- require_relative 'colour'
2
- require_relative 'style'
1
+ require_relative 'presentation'
3
2
  require_relative 'text'
4
3
  require_relative 'use'
@@ -2,12 +2,12 @@ module Vedeu
2
2
 
3
3
  module DSL
4
4
 
5
- # Provides colour helpers for use in the {Vedeu::DSL::Interface},
5
+ # Provides colour and style helpers for use in the {Vedeu::DSL::Interface},
6
6
  # {Vedeu::DSL::Line} and {Vedeu::DSL::Stream} classes.
7
7
  #
8
8
  # @api public
9
9
  #
10
- module Colour
10
+ module Presentation
11
11
 
12
12
  # Define the background colour for an interface, line, or a stream. When
13
13
  # called with a block, will create a new stream with the background colour
@@ -41,7 +41,7 @@ module Vedeu
41
41
  alias_method :bg, :background
42
42
  alias_method :bgcolor, :background
43
43
 
44
- # @see Vedeu::DSL::Colour#background
44
+ # @see Vedeu::DSL::Presentation#background
45
45
  def foreground(value = '')
46
46
  colour(foreground: value)
47
47
  end
@@ -78,7 +78,30 @@ module Vedeu
78
78
  model.colour = Vedeu::Colour.coerce(attributes)
79
79
  end
80
80
 
81
- end # Colour
81
+ # Define a style or styles for an interface, line or a stream.
82
+ #
83
+ # @param value [Array<Symbol>|Array<String>|Symbol|String]
84
+ #
85
+ # @example
86
+ # interface 'my_interface' do
87
+ # style 'normal'
88
+ # ...
89
+ #
90
+ # lines do
91
+ # style ['bold', 'underline']
92
+ # ...
93
+ #
94
+ # stream do
95
+ # style 'blink'
96
+ # ...
97
+ #
98
+ # @return [Vedeu::Style]
99
+ def style(value)
100
+ model.style = Vedeu::Style.coerce(value)
101
+ end
102
+ alias_method :styles, :style
103
+
104
+ end # Presentation
82
105
 
83
106
  end # DSL
84
107
 
@@ -6,41 +6,62 @@ module Vedeu
6
6
  #
7
7
  module Use
8
8
 
9
- extend self
10
-
11
- # Use the specified interface; useful for sharing attributes with other
12
- # interfaces. Any public method of {Vedeu::Interface} is available.
9
+ # Duplicate a stored model.
10
+ #
11
+ # This DSL method copies the attributes of a stored model, changes the
12
+ # name to that of the current model, and stores the duplicate as a new
13
+ # model in model's repository.
13
14
  #
14
15
  # @example
15
- # Vedeu.interface 'my_interface' do
16
- # # use the delay of another interface
17
- # delay Vedeu.use('my_other_interface').delay
18
- # # ...
16
+ # # Here the attributes of 'my_geometry' are used to create the
17
+ # # new model 'my_other_geometry'.
18
+ # Vedeu.geometry 'my_other_geometry' do
19
+ # duplicate('my_geometry')
19
20
  # end
20
21
  #
21
- # Vedeu.interface 'my_interface' do
22
- # geometry do
23
- # # use the width of another interface
24
- # width Vedeu.use('my_other_interface').width
25
- # # ...
26
- # end
27
- # end
22
+ # @note
23
+ # - Only models of the same repository can be used in this way.
24
+ # - If the stored model cannot be found, the duplicate may not have
25
+ # the values you required.
26
+ # - Values defined before will be overwritten by the new values from
27
+ # the stored model.
28
+ # - Values defined after will overwrite the values of the new
29
+ # duplicate model.
28
30
  #
29
- # Vedeu.use('my_other_interface').width # can be used in your code to
30
- # # get this value
31
- #
32
- # @param value [String] The name of the interface you wish to use.
33
- # Typically used when defining interfaces to share geometry.
34
- # @raise [ModelNotFound] The interface has not yet been defined.
35
- # @return [Vedeu::Interface]
36
- def use(value)
37
- if Vedeu.interfaces.registered?(value) == false
38
- fail ModelNotFound, "The properties of this interface (#{value}) " \
39
- 'cannot be used, since the interface has not ' \
40
- 'been defined.'
41
- end
31
+ # @param name [String] The name of the model to duplicate.
32
+ # @return [void] The new model based on the original.
33
+ def duplicate(name)
34
+ duplicated = model.repository.by_name(name).dup
35
+ duplicated.name = model.name
36
+ duplicated.store
37
+ end
42
38
 
43
- Vedeu.interfaces.find(value)
39
+ # Use the attribute of stored model.
40
+ #
41
+ # This DSL method provides access to a stored model by name. You can
42
+ # then request an attribute of that model for use within the current
43
+ # model.
44
+ #
45
+ # @example
46
+ # # Here the character used for 'my_border' is used in
47
+ # # 'my_other_border'.
48
+ # Vedeu.border 'my_other_border' do
49
+ # top_right use('my_border').top_right
50
+ # end
51
+ #
52
+ # @note
53
+ # - Only models of the same repository can be used in this way.
54
+ # - If the stored model cannot be found, a ModelNotFound exception may
55
+ # be raised, or the request for an attribute may raise a
56
+ # NoMethodError exception.
57
+ #
58
+ # @param name [String] The name of the model with the value you wish to
59
+ # use.
60
+ # @raise [ModelNotFound|NoMethodError] The model or attribute cannot be
61
+ # found.
62
+ # @return [void] The stored model.
63
+ def use(name)
64
+ model.repository.by_name(name)
44
65
  end
45
66
 
46
67
  end # Use