vedeu 0.4.46 → 0.4.47

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +3 -3
  3. data/lib/vedeu/bindings/bindings.rb +14 -4
  4. data/lib/vedeu/bindings/drb.rb +2 -0
  5. data/lib/vedeu/bindings/menus.rb +2 -0
  6. data/lib/vedeu/bindings/movement.rb +2 -0
  7. data/lib/vedeu/bindings/visibility.rb +2 -0
  8. data/lib/vedeu/buffers/buffer.rb +1 -1
  9. data/lib/vedeu/cursor/cursor.rb +2 -2
  10. data/lib/vedeu/geometry/dimension.rb +16 -13
  11. data/lib/vedeu/geometry/geometry.rb +3 -1
  12. data/lib/vedeu/geometry/index_position.rb +1 -1
  13. data/lib/vedeu/geometry/position_index.rb +1 -1
  14. data/lib/vedeu/input/input.rb +2 -1
  15. data/lib/vedeu/input/keymap.rb +1 -0
  16. data/lib/vedeu/models/char.rb +7 -6
  17. data/lib/vedeu/models/interface.rb +2 -12
  18. data/lib/vedeu/models/line.rb +2 -2
  19. data/lib/vedeu/models/stream.rb +2 -2
  20. data/lib/vedeu/null/geometry.rb +3 -6
  21. data/lib/vedeu/output/all.rb +1 -1
  22. data/lib/vedeu/output/border.rb +5 -5
  23. data/lib/vedeu/output/clear/all.rb +2 -0
  24. data/lib/vedeu/output/clear/named_group.rb +52 -0
  25. data/lib/vedeu/output/clear/named_interface.rb +99 -0
  26. data/lib/vedeu/output/esc.rb +1 -1
  27. data/lib/vedeu/output/viewport.rb +10 -2
  28. data/lib/vedeu/repositories/registerable.rb +9 -1
  29. data/lib/vedeu/repositories/repositories/borders.rb +0 -11
  30. data/lib/vedeu/repositories/repositories/buffers.rb +0 -11
  31. data/lib/vedeu/repositories/repositories/cursors.rb +4 -11
  32. data/lib/vedeu/repositories/repositories/geometries.rb +0 -11
  33. data/lib/vedeu/repositories/repositories/groups.rb +4 -11
  34. data/lib/vedeu/repositories/repositories/interfaces.rb +0 -11
  35. data/lib/vedeu/repositories/repositories/keymaps.rb +4 -11
  36. data/lib/vedeu/repositories/repositories/menus.rb +4 -11
  37. data/lib/vedeu/repositories/repository.rb +1 -11
  38. data/lib/vedeu/storage/store.rb +15 -0
  39. data/lib/vedeu/support/log.rb +1 -0
  40. data/lib/vedeu/support/terminal.rb +1 -10
  41. data/lib/vedeu/support/visibility.rb +0 -1
  42. data/lib/vedeu/version.rb +1 -1
  43. data/test/lib/vedeu/geometry/geometry_test.rb +4 -0
  44. data/test/lib/vedeu/geometry/position_test.rb +25 -8
  45. data/test/lib/vedeu/models/char_test.rb +4 -4
  46. data/test/lib/vedeu/models/interface_test.rb +7 -2
  47. data/test/lib/vedeu/output/clear/named_group_test.rb +41 -0
  48. data/test/lib/vedeu/output/clear/named_interface_test.rb +68 -0
  49. data/test/lib/vedeu/output/render_border_test.rb +47 -5
  50. data/test/lib/vedeu/repositories/registerable_test.rb +30 -3
  51. data/test/lib/vedeu/repositories/repositories/borders_test.rb +0 -13
  52. data/test/lib/vedeu/repositories/repositories/buffers_test.rb +0 -11
  53. data/test/lib/vedeu/repositories/repositories/cursors_test.rb +0 -11
  54. data/test/lib/vedeu/repositories/repositories/geometries_test.rb +0 -11
  55. data/test/lib/vedeu/repositories/repositories/groups_test.rb +0 -11
  56. data/test/lib/vedeu/repositories/repositories/interfaces_test.rb +0 -11
  57. data/test/lib/vedeu/repositories/repositories/keymaps_test.rb +0 -11
  58. data/test/lib/vedeu/repositories/repositories/menus_test.rb +0 -11
  59. data/test/lib/vedeu/repositories/repository_test.rb +0 -37
  60. data/test/lib/vedeu/storage/store_test.rb +41 -0
  61. data/test/test_helper.rb +3 -1
  62. metadata +9 -5
  63. data/lib/vedeu/output/clear.rb +0 -207
  64. data/test/lib/vedeu/output/clear_test.rb +0 -105
@@ -0,0 +1,2 @@
1
+ require_relative 'named_group'
2
+ require_relative 'named_interface'
@@ -0,0 +1,52 @@
1
+ module Vedeu
2
+
3
+ module Clear
4
+
5
+ # Clear the named group.
6
+ #
7
+ # @api private
8
+ class NamedGroup
9
+
10
+ class << self
11
+
12
+ # @param name [String]
13
+ # @return [void]
14
+ def render(name)
15
+ new(name).render
16
+ end
17
+ alias_method :clear_by_group, :render
18
+ alias_method :by_group, :render
19
+
20
+ end # Eigenclass
21
+
22
+ # Return a new instance of Vedeu::Clear::NamedGroup.
23
+ #
24
+ # @param name [String]
25
+ # @return [Vedeu::Clear::NamedGroup]
26
+ def initialize(name)
27
+ @name = name
28
+ end
29
+
30
+ # @return [void]
31
+ def render
32
+ members.each { |name| Vedeu::Clear::NamedInterface.render(name) }
33
+ end
34
+
35
+ protected
36
+
37
+ # @!attribute [r] name
38
+ # @return [String]
39
+ attr_reader :name
40
+
41
+ private
42
+
43
+ # @return [Array<String>]
44
+ def members
45
+ Vedeu.groups.by_name(name).members
46
+ end
47
+
48
+ end # Group
49
+
50
+ end # Clear
51
+
52
+ end # Vedeu
@@ -0,0 +1,99 @@
1
+ module Vedeu
2
+
3
+ module Clear
4
+
5
+ # Clear the named interface.
6
+ #
7
+ # @api private
8
+ class NamedInterface
9
+
10
+ class << self
11
+
12
+ # @return [void]
13
+ # @see #initialize
14
+ def render(name)
15
+ new(name).render
16
+ end
17
+ alias_method :clear_by_name, :render
18
+ alias_method :by_name, :render
19
+
20
+ end # Eigenclass
21
+
22
+ # Return a new instance of Vedeu::Clear::NamedInterface.
23
+ #
24
+ # @param name [String] The name of the interface to clear.
25
+ # @return [Vedeu::Clear::NamedInterface]
26
+ def initialize(name)
27
+ @name = name
28
+ end
29
+
30
+ # @return [void]
31
+ def render
32
+ return [] unless interface.visible?
33
+
34
+ output
35
+ end
36
+
37
+ protected
38
+
39
+ # @!attribute [r] name
40
+ # @return [String]
41
+ attr_reader :name
42
+
43
+ private
44
+
45
+ # @see Vedeu::Geometries#by_name
46
+ def geometry
47
+ @geometry ||= Vedeu.geometries.by_name(name)
48
+ end
49
+
50
+ # @see Vedeu::Interfaces#by_name
51
+ def interface
52
+ @interface ||= Vedeu.interfaces.by_name(name)
53
+ end
54
+
55
+ # For each visible line of the interface, set the foreground and
56
+ # background colours to those specified when the interface was defined,
57
+ # then starting write space characters over the area which the interface
58
+ # occupies.
59
+ #
60
+ # @return [Array<Array<Vedeu::Char>>]
61
+ def output
62
+ Vedeu.timer("Clearing: #{name}") do
63
+ @clear ||= Array.new(height) do |iy|
64
+ Array.new(width) do |ix|
65
+ Vedeu::Char.new(value: ' ',
66
+ colour: colour,
67
+ position: Vedeu::Position[y + iy, x + ix])
68
+ end
69
+ end
70
+ end
71
+ end
72
+
73
+ def colour
74
+ @colour ||= interface.colour
75
+ end
76
+
77
+ def height
78
+ @height ||= geometry.height
79
+ end
80
+
81
+ def width
82
+ @width ||= geometry.width
83
+ end
84
+
85
+ # @return [Fixnum]
86
+ def x
87
+ @x ||= geometry.x
88
+ end
89
+
90
+ # @return [Fixnum]
91
+ def y
92
+ @y ||= geometry.y
93
+ end
94
+
95
+ end # NamedInterface
96
+
97
+ end # Clear
98
+
99
+ end # Vedeu
@@ -175,7 +175,7 @@ module Vedeu
175
175
 
176
176
  # @return [String]
177
177
  def last_character_position
178
- Vedeu::Position.new(Vedeu.height, Vedeu.width).to_s
178
+ Vedeu::Position[Vedeu.height, Vedeu.width].to_s
179
179
  end
180
180
 
181
181
  end # Esc
@@ -18,8 +18,6 @@ module Vedeu
18
18
  :visible?
19
19
 
20
20
  def_delegators :border,
21
- :bx,
22
- :by,
23
21
  :height,
24
22
  :width
25
23
 
@@ -158,6 +156,16 @@ module Vedeu
158
156
  @border ||= Vedeu.borders.by_name(name)
159
157
  end
160
158
 
159
+ # @return [Fixnum]
160
+ def bx
161
+ @bx ||= border.bx
162
+ end
163
+
164
+ # @return [Fixnum]
165
+ def by
166
+ @by ||= border.by
167
+ end
168
+
161
169
  # Fetch the cursor associated with the interface we are drawing.
162
170
  #
163
171
  # @return (see Vedeu::Cursors#by_name)
@@ -22,7 +22,7 @@ module Vedeu
22
22
  # @param klass [Class]
23
23
  # @return [Symbol]
24
24
  def real(klass)
25
- define_method(:real_model) { klass }
25
+ define_method(:model) { instance_variable_set('@model', klass) }
26
26
  end
27
27
 
28
28
  # Register a repository for storing models.
@@ -48,6 +48,14 @@ module Vedeu
48
48
  @models ||= reset!
49
49
  end
50
50
 
51
+ # Remove all stored models from the repository.
52
+ #
53
+ # @return [void]
54
+ def reset!
55
+ @models = register
56
+ end
57
+ alias_method :reset, :reset!
58
+
51
59
  end # ClassMethods
52
60
 
53
61
  # When this module is included in a class, provide ClassMethods as class
@@ -13,17 +13,6 @@ module Vedeu
13
13
 
14
14
  alias_method :borders, :repository
15
15
 
16
- # Remove all stored models from the repository.
17
- #
18
- # @example
19
- # Vedeu.borders.reset!
20
- #
21
- # @return [Vedeu::Borders]
22
- def reset!
23
- @borders = register(Vedeu::Border)
24
- end
25
- alias_method :reset, :reset!
26
-
27
16
  end # Eigenclass
28
17
 
29
18
  null Vedeu::Null::Border
@@ -12,17 +12,6 @@ module Vedeu
12
12
 
13
13
  alias_method :buffers, :repository
14
14
 
15
- # Remove all stored models from the repository.
16
- #
17
- # @example
18
- # Vedeu.buffers.reset!
19
- #
20
- # @return [Vedeu::Buffers]
21
- def reset!
22
- @buffers = register(Vedeu::Buffer)
23
- end
24
- alias_method :reset, :reset!
25
-
26
15
  end # Eigenclass
27
16
 
28
17
  null Vedeu::Null::Buffer
@@ -1,3 +1,5 @@
1
+ require 'vedeu/cursor/cursor'
2
+
1
3
  module Vedeu
2
4
 
3
5
  # Allows the storing of each interface's cursor.
@@ -15,19 +17,10 @@ module Vedeu
15
17
  cursors.by_name(Vedeu.focus) if Vedeu.focus
16
18
  end
17
19
 
18
- # Remove all stored models from the repository.
19
- #
20
- # @example
21
- # Vedeu.cursors.reset!
22
- #
23
- # @return [Vedeu::Cursors]
24
- def reset!
25
- @cursors = register(Vedeu::Cursor)
26
- end
27
- alias_method :reset, :reset!
28
-
29
20
  end # Eigenclass
30
21
 
22
+ real Vedeu::Cursor
23
+
31
24
  # @example
32
25
  # Vedeu.cursors.by_name('some_name')
33
26
  #
@@ -13,17 +13,6 @@ module Vedeu
13
13
 
14
14
  alias_method :geometries, :repository
15
15
 
16
- # Remove all stored models from the repository.
17
- #
18
- # @example
19
- # Vedeu.geometries.reset!
20
- #
21
- # @return [Vedeu::Geometries]
22
- def reset!
23
- @geometries = register(Vedeu::Geometry)
24
- end
25
- alias_method :reset, :reset!
26
-
27
16
  end # Eigenclass
28
17
 
29
18
  null Vedeu::Null::Geometry
@@ -1,3 +1,5 @@
1
+ require 'vedeu/models/group'
2
+
1
3
  module Vedeu
2
4
 
3
5
  # Allows the storing of view groups.
@@ -9,19 +11,10 @@ module Vedeu
9
11
 
10
12
  alias_method :groups, :repository
11
13
 
12
- # Remove all stored models from the repository.
13
- #
14
- # @example
15
- # Vedeu.groups.reset!
16
- #
17
- # @return [Vedeu::Groups]
18
- def reset!
19
- @groups = register(Vedeu::Group)
20
- end
21
- alias_method :reset, :reset!
22
-
23
14
  end # Eigenclass
24
15
 
16
+ real Vedeu::Group
17
+
25
18
  # @example
26
19
  # Vedeu.groups.by_name('name')
27
20
  #
@@ -12,17 +12,6 @@ module Vedeu
12
12
 
13
13
  alias_method :interfaces, :repository
14
14
 
15
- # Remove all stored models from the repository.
16
- #
17
- # @example
18
- # Vedeu.interfaces.reset!
19
- #
20
- # @return [Vedeu::Interfaces]
21
- def reset!
22
- @interfaces = register(Vedeu::Interface)
23
- end
24
- alias_method :reset, :reset!
25
-
26
15
  end # Eigenclass
27
16
 
28
17
  null Vedeu::Null::Interface
@@ -1,3 +1,5 @@
1
+ require 'vedeu/input/keymap'
2
+
1
3
  module Vedeu
2
4
 
3
5
  # Allows the storing of keymaps.
@@ -9,19 +11,10 @@ module Vedeu
9
11
 
10
12
  alias_method :keymaps, :repository
11
13
 
12
- # Remove all stored models from the repository.
13
- #
14
- # @example
15
- # Vedeu.keymaps.reset!
16
- #
17
- # @return [Vedeu::Keymaps]
18
- def reset!
19
- @keymaps = register(Vedeu::Keymap)
20
- end
21
- alias_method :reset, :reset!
22
-
23
14
  end # Eigenclass
24
15
 
16
+ real Vedeu::Keymap
17
+
25
18
  end # Keymaps
26
19
 
27
20
  end # Vedeu
@@ -1,3 +1,5 @@
1
+ require 'vedeu/models/menu'
2
+
1
3
  module Vedeu
2
4
 
3
5
  # Allows the storing of menus by name.
@@ -9,19 +11,10 @@ module Vedeu
9
11
 
10
12
  alias_method :menus, :repository
11
13
 
12
- # Remove all stored models from the repository.
13
- #
14
- # @example
15
- # Vedeu.menus.reset!
16
- #
17
- # @return [Vedeu::Menus]
18
- def reset!
19
- @menus = register(Vedeu::Menu)
20
- end
21
- alias_method :reset, :reset!
22
-
23
14
  end # Eigenclass
24
15
 
16
+ real Vedeu::Menu
17
+
25
18
  end # Menus
26
19
 
27
20
  end # Vedeu
@@ -112,17 +112,6 @@ module Vedeu
112
112
  "<#{self.class.name}: #{registered.inspect}>"
113
113
  end
114
114
 
115
- # Returns a collection of the names of all the registered entities.
116
- #
117
- # @return [Array]
118
- def registered
119
- return [] if empty?
120
- return storage.keys if storage.is_a?(Hash)
121
- return storage.to_a if storage.is_a?(Set)
122
-
123
- storage
124
- end
125
-
126
115
  # Returns a boolean indicating whether the named model is registered.
127
116
  #
128
117
  # @param name [String]
@@ -169,6 +158,7 @@ module Vedeu
169
158
  storage[model.name] = model
170
159
  end
171
160
  alias_method :register, :store
161
+ alias_method :add, :store
172
162
 
173
163
  private
174
164
 
@@ -31,13 +31,28 @@ module Vedeu
31
31
  end
32
32
  alias_method :registered?, :exists?
33
33
 
34
+ # Returns a collection of the names of all the registered entities.
35
+ #
36
+ # @return [Array]
37
+ def registered
38
+ return [] if empty?
39
+ return storage.keys if storage.is_a?(Hash)
40
+ return storage.to_a if storage.is_a?(Set)
41
+
42
+ storage
43
+ end
44
+
34
45
  # Remove all currently stored data.
35
46
  #
36
47
  # @return [Array|Hash|Set]
37
48
  def reset
49
+ Vedeu.log(type: :reset,
50
+ message: "(#{self.class.name}) #{registered.inspect}")
51
+
38
52
  @storage = in_memory
39
53
  end
40
54
  alias_method :reset!, :reset
55
+ alias_method :clear, :reset
41
56
 
42
57
  # Return the number of entries stored.
43
58
  #