vedeu 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +5 -5
  3. data/docs/events.md +4 -0
  4. data/examples/borders_app.rb +43 -39
  5. data/examples/focus_app.rb +4 -0
  6. data/examples/hello_world.rb +10 -3
  7. data/lib/vedeu/all.rb +1 -2
  8. data/lib/vedeu/api.rb +4 -1
  9. data/lib/vedeu/application/application_controller.rb +24 -0
  10. data/lib/vedeu/application/application_view.rb +9 -9
  11. data/lib/vedeu/bindings.rb +2 -0
  12. data/lib/vedeu/bindings/movement.rb +9 -9
  13. data/lib/vedeu/bindings/system.rb +3 -3
  14. data/lib/vedeu/buffers/buffer.rb +4 -9
  15. data/lib/vedeu/buffers/display_buffer.rb +2 -48
  16. data/lib/vedeu/cli/generator/application.rb +6 -0
  17. data/lib/vedeu/cli/generator/templates/application/.ruby-version +1 -0
  18. data/lib/vedeu/cli/generator/templates/application/app/controllers/name.erb +2 -11
  19. data/lib/vedeu/configuration/api.rb +6 -0
  20. data/lib/vedeu/configuration/configuration.rb +6 -0
  21. data/lib/vedeu/cursor/cursor.rb +49 -15
  22. data/lib/vedeu/cursor/move.rb +2 -2
  23. data/lib/vedeu/cursor/refresh_cursor.rb +2 -7
  24. data/lib/vedeu/distributed/server.rb +7 -21
  25. data/lib/vedeu/dsl/view.rb +31 -6
  26. data/lib/vedeu/internal_api.rb +7 -0
  27. data/lib/vedeu/log/log.rb +5 -2
  28. data/lib/vedeu/models/escape.rb +24 -6
  29. data/lib/vedeu/models/interface.rb +2 -14
  30. data/lib/vedeu/null/buffer.rb +7 -21
  31. data/lib/vedeu/null/generic.rb +5 -16
  32. data/lib/vedeu/null/interface.rb +6 -18
  33. data/lib/vedeu/runtime/bootstrap.rb +1 -1
  34. data/lib/vedeu/runtime/flags.rb +57 -0
  35. data/lib/vedeu/runtime/router.rb +2 -2
  36. data/lib/vedeu/version.rb +2 -1
  37. data/test/lib/vedeu/api_test.rb +1 -0
  38. data/test/lib/vedeu/application/application_controller_test.rb +26 -2
  39. data/test/lib/vedeu/application/application_view_test.rb +9 -4
  40. data/test/lib/vedeu/bindings_test.rb +9 -0
  41. data/test/lib/vedeu/borders/border_test.rb +25 -42
  42. data/test/lib/vedeu/buffers/display_buffer_test.rb +0 -10
  43. data/test/lib/vedeu/configuration/api_test.rb +7 -1
  44. data/test/lib/vedeu/configuration/cli_test.rb +0 -1
  45. data/test/lib/vedeu/configuration/configuration_test.rb +16 -0
  46. data/test/lib/vedeu/cursor/cursor_test.rb +122 -4
  47. data/test/lib/vedeu/dsl/view_test.rb +2 -2
  48. data/test/lib/vedeu/internal_api_test.rb +2 -0
  49. data/test/lib/vedeu/models/escape_test.rb +16 -6
  50. data/test/lib/vedeu/models/focus_test.rb +2 -1
  51. data/test/lib/vedeu/models/interface_test.rb +9 -5
  52. data/test/lib/vedeu/null/buffer_test.rb +7 -25
  53. data/test/lib/vedeu/null/generic_test.rb +6 -20
  54. data/test/lib/vedeu/null/interface_test.rb +8 -14
  55. data/test/lib/vedeu/output/compressor_test.rb +4 -4
  56. data/test/lib/vedeu/output/renderers_test.rb +1 -1
  57. data/test/lib/vedeu/runtime/flags_test.rb +47 -0
  58. data/test/lib/vedeu/runtime/router_test.rb +4 -4
  59. data/test/test_helper.rb +2 -0
  60. metadata +6 -10
  61. data/examples/geometry_app.rb +0 -147
  62. data/examples/panel_app.rb +0 -71
  63. data/lib/vedeu/geometry/index_position.rb +0 -85
  64. data/lib/vedeu/geometry/position_validator.rb +0 -69
  65. data/test/lib/vedeu/geometry/index_position_test.rb +0 -130
  66. data/test/lib/vedeu/geometry/position_validator_test.rb +0 -149
@@ -86,7 +86,7 @@ module Vedeu
86
86
  def restart
87
87
  log('Attempting to restart')
88
88
 
89
- return not_enabled unless drb?
89
+ return not_enabled unless Vedeu::Configuration.drb?
90
90
 
91
91
  if drb_running?
92
92
  log('Restarting')
@@ -112,7 +112,7 @@ module Vedeu
112
112
  #
113
113
  # @return [void]
114
114
  def shutdown
115
- return not_enabled unless drb?
115
+ return not_enabled unless Vedeu::Configuration.drb?
116
116
 
117
117
  stop if drb_running?
118
118
 
@@ -127,7 +127,7 @@ module Vedeu
127
127
  def start
128
128
  log('Attempting to start')
129
129
 
130
- return not_enabled unless drb?
130
+ return not_enabled unless Vedeu::Configuration.drb?
131
131
 
132
132
  if drb_running?
133
133
  log('Already started')
@@ -147,7 +147,7 @@ module Vedeu
147
147
  def status
148
148
  log('Fetching status')
149
149
 
150
- return not_enabled unless drb?
150
+ return not_enabled unless Vedeu::Configuration.drb?
151
151
 
152
152
  if drb_running?
153
153
  log('Running')
@@ -168,7 +168,7 @@ module Vedeu
168
168
  def stop
169
169
  log('Attempting to stop')
170
170
 
171
- return not_enabled unless drb?
171
+ return not_enabled unless Vedeu::Configuration.drb?
172
172
 
173
173
  if drb_running?
174
174
  log('Stopping')
@@ -193,26 +193,11 @@ module Vedeu
193
193
 
194
194
  private
195
195
 
196
- # @return [Boolean]
197
- def drb?
198
- Vedeu::Configuration.drb?
199
- end
200
-
201
- # @return [String]
202
- def drb_host
203
- Vedeu::Configuration.drb_host
204
- end
205
-
206
196
  # @return [|NilClass]
207
197
  def drb_running?
208
198
  DRb.thread
209
199
  end
210
200
 
211
- # @return [Fixnum|String]
212
- def drb_port
213
- Vedeu::Configuration.drb_port
214
- end
215
-
216
201
  # @return [void]
217
202
  def log(message)
218
203
  Vedeu.log(type: :drb, message: "#{message}: '#{uri}'")
@@ -227,7 +212,8 @@ module Vedeu
227
212
 
228
213
  # @return [String]
229
214
  def uri
230
- Vedeu::Distributed::Uri.new(drb_host, drb_port).to_s
215
+ Vedeu::Distributed::Uri.new(Vedeu::Configuration.drb_host,
216
+ Vedeu::Configuration.drb_port).to_s
231
217
  end
232
218
 
233
219
  end # Server
@@ -81,6 +81,8 @@ module Vedeu
81
81
 
82
82
  class << self
83
83
 
84
+ include Vedeu::Common
85
+
84
86
  # Register an interface by name which will display output from a event
85
87
  # or command. This provides the means for you to define your the views
86
88
  # of your application without their content.
@@ -89,11 +91,6 @@ module Vedeu
89
91
  # # ... some code
90
92
  # end
91
93
  #
92
- # Vedeu.interface do
93
- # name 'interfaces_must_have_a_name'
94
- # # ... some code
95
- # end
96
- #
97
94
  # @param name [String] The name of the interface. Used to reference the
98
95
  # interface throughout your application's execution lifetime.
99
96
  # @param block [Proc] A set of attributes which define the features of
@@ -101,8 +98,13 @@ module Vedeu
101
98
  # @raise [Vedeu::InvalidSyntax] The required block was not given.
102
99
  # @return [Vedeu::Interface]
103
100
  # @todo More documentation required.
104
- def interface(name = '', &block)
101
+ def interface(name, &block)
105
102
  fail Vedeu::InvalidSyntax, 'block not given' unless block_given?
103
+ fail Vedeu::MissingRequired, 'name not given' unless present?(name)
104
+
105
+ add_buffers!(name)
106
+ add_cursor!(name)
107
+ add_focusable!(name)
106
108
 
107
109
  attributes = { client: client(&block), name: name }
108
110
 
@@ -199,6 +201,29 @@ module Vedeu
199
201
 
200
202
  private
201
203
 
204
+ # Registers a set of buffers for the interface unless already registered,
205
+ # and also adds interface's name to list of focussable interfaces.
206
+ #
207
+ # @see Vedeu::Buffer
208
+ # @return [void]
209
+ def add_buffers!(name)
210
+ Vedeu::Buffer.new(name: name).store
211
+ end
212
+
213
+ # Registers a new cursor for the interface unless already registered.
214
+ #
215
+ # @return [void]
216
+ def add_cursor!(name)
217
+ Vedeu::Cursor.new(name: name).store
218
+ end
219
+
220
+ # Registers interface name in focus list unless already registered.
221
+ #
222
+ # @return [void]
223
+ def add_focusable!(name)
224
+ Vedeu.focusable.add(name) unless Vedeu.focusable.registered?(name)
225
+ end
226
+
202
227
  # Returns the client object which called the DSL method.
203
228
  #
204
229
  # @param block [Proc]
@@ -118,6 +118,13 @@ module Vedeu
118
118
  # @return [Vedeu::Menus]
119
119
  def_delegators Vedeu::Menus, :menus
120
120
 
121
+ # Manipulate the internal flags.
122
+ #
123
+ # @!method ready?
124
+ # @!method ready!
125
+ # @return [Boolean]
126
+ def_delegators Vedeu::Flags, :ready?, :ready!
127
+
121
128
  # @example
122
129
  # Vedeu.renderer
123
130
  # Vedeu.renderers
data/lib/vedeu/log/log.rb CHANGED
@@ -97,7 +97,10 @@ module Vedeu
97
97
  def log(message:, force: false, type: :info)
98
98
  output = log_entry(type, message)
99
99
 
100
- logger.debug(output) if enabled? || force
100
+ if (enabled? || force) && (Vedeu::Configuration.log_only.empty? ||
101
+ Vedeu::Configuration.log_only.include?(type))
102
+ logger.debug(output)
103
+ end
101
104
 
102
105
  output
103
106
  end
@@ -135,7 +138,7 @@ module Vedeu
135
138
  # combined.
136
139
  # @return [String]
137
140
  def formatted_message(message)
138
- "#{timestamp}#{message}\n"
141
+ "#{timestamp}#{message}\n" if message
139
142
  end
140
143
 
141
144
  # Returns the message:
@@ -7,15 +7,17 @@ module Vedeu
7
7
  # @!attribute [r] value
8
8
  # @return [String]
9
9
  attr_reader :value
10
- alias_method :to_s, :value
11
- alias_method :to_str, :value
12
10
 
13
11
  # Returns a new instance of Vedeu::Escape.
14
12
  #
15
- # @param value [String]
13
+ # @param attributes [String]
14
+ # @option attributes position [Vedeu::Position|Array<Fixnum>]
15
+ # @option attributes value [String]
16
16
  # @return [Vedeu::Escape]
17
- def initialize(value)
18
- @value = value
17
+ def initialize(attributes = {})
18
+ @attributes = defaults.merge!(attributes)
19
+
20
+ @attributes.each { |key, value| instance_variable_set("@#{key}", value) }
19
21
  end
20
22
 
21
23
  # @return [String]
@@ -41,7 +43,7 @@ module Vedeu
41
43
 
42
44
  # @return [String]
43
45
  def position
44
- ''
46
+ Vedeu::Position.coerce(@position)
45
47
  end
46
48
 
47
49
  # @return [String]
@@ -49,6 +51,22 @@ module Vedeu
49
51
  ''
50
52
  end
51
53
 
54
+ # @return [String]
55
+ def to_s
56
+ "#{position}#{value}"
57
+ end
58
+ alias_method :to_str, :to_s
59
+
60
+ private
61
+
62
+ # @return [Hash]
63
+ def defaults
64
+ {
65
+ position: [1, 1],
66
+ value: '',
67
+ }
68
+ end
69
+
52
70
  end # Escape
53
71
 
54
72
  end # Vedeu
@@ -124,16 +124,14 @@ module Vedeu
124
124
  def render
125
125
  return [] unless visible?
126
126
 
127
- Vedeu.trigger(:_hide_cursor_, name)
128
-
129
127
  output = [
128
+ Vedeu.trigger(:_hide_cursor_, name),
130
129
  Vedeu::Clear::NamedInterface.render(name),
131
130
  Vedeu::Viewport.render(self),
132
131
  Vedeu.borders.by_name(name).render,
132
+ Vedeu.trigger(:_show_cursor_, name)
133
133
  ]
134
134
 
135
- Vedeu.trigger(:_show_cursor_, name)
136
-
137
135
  output
138
136
  end
139
137
 
@@ -150,16 +148,6 @@ module Vedeu
150
148
  Vedeu.buffers.by_name(name).show
151
149
  end
152
150
 
153
- # @return [Vedeu::Interface]
154
- def store
155
- super
156
-
157
- store_new_buffer
158
- store_focusable
159
- store_cursor
160
- store_group
161
- end
162
-
163
151
  private
164
152
 
165
153
  # The default values for a new instance of this class.
@@ -22,35 +22,21 @@ module Vedeu
22
22
  end
23
23
 
24
24
  # @return [NilClass]
25
- def clear
26
- nil
27
- end
28
-
29
- # @return [NilClass]
30
- def hide
25
+ def null(*)
31
26
  nil
32
27
  end
28
+ alias_method :add, :null
29
+ alias_method :clear, :null
30
+ alias_method :hide, :null
31
+ alias_method :render, :null
32
+ alias_method :show, :null
33
+ alias_method :toggle, :null
33
34
 
34
35
  # @return [Boolean]
35
36
  def null?
36
37
  true
37
38
  end
38
39
 
39
- # @return [NilClass]
40
- def render
41
- nil
42
- end
43
-
44
- # @return [NilClass]
45
- def show
46
- nil
47
- end
48
-
49
- # @return [NilClass]
50
- def toggle
51
- nil
52
- end
53
-
54
40
  end # Buffer
55
41
 
56
42
  end # Null
@@ -17,35 +17,24 @@ module Vedeu
17
17
  end
18
18
 
19
19
  # @return [NilClass]
20
- def add(*)
21
- nil
22
- end
23
-
24
- # @return [NilClass]
25
- def colour
20
+ def null(*)
26
21
  nil
27
22
  end
23
+ alias_method :add, :null
24
+ alias_method :colour, :null
25
+ alias_method :parent, :null
26
+ alias_method :style, :null
28
27
 
29
28
  # @return [Boolean]
30
29
  def null?
31
30
  true
32
31
  end
33
32
 
34
- # @return [NilClass]
35
- def parent
36
- nil
37
- end
38
-
39
33
  # @return [Vedeu::Null::Generic]
40
34
  def store
41
35
  self
42
36
  end
43
37
 
44
- # @return [NilClass]
45
- def style
46
- nil
47
- end
48
-
49
38
  # The generic null should not be visible.
50
39
  #
51
40
  # @return [FalseClass]
@@ -35,27 +35,20 @@ module Vedeu
35
35
  end
36
36
 
37
37
  # @return [NilClass]
38
- def hide
38
+ def null
39
39
  nil
40
40
  end
41
+ alias_method :hide, :null
42
+ alias_method :parent, :null
43
+ alias_method :show, :null
44
+ alias_method :toggle, :null
45
+ alias_method :zindex, :null
41
46
 
42
47
  # @return [Boolean]
43
48
  def null?
44
49
  true
45
50
  end
46
51
 
47
- # The null interface should not have a parent.
48
- #
49
- # @return [NilClass]
50
- def parent
51
- nil
52
- end
53
-
54
- # @return [NilClass]
55
- def show
56
- nil
57
- end
58
-
59
52
  # Pretend to store this model in the repository.
60
53
  #
61
54
  # @return [Vedeu::Null::Interface]
@@ -63,11 +56,6 @@ module Vedeu
63
56
  self
64
57
  end
65
58
 
66
- # @return [NilClass]
67
- def toggle
68
- nil
69
- end
70
-
71
59
  # The null interface should not be visible.
72
60
  #
73
61
  # @return [FalseClass]
@@ -113,7 +113,7 @@ module Vedeu
113
113
 
114
114
  # @return [Class]
115
115
  def root
116
- Object.const_get(Vedeu::Configuration.root) if Vedeu::Configuration.root
116
+ Vedeu::Configuration.root if Vedeu::Configuration.root
117
117
  end
118
118
 
119
119
  end # Bootstrap
@@ -0,0 +1,57 @@
1
+ module Vedeu
2
+
3
+ # Home of various runtime flags which Vedeu uses.
4
+ #
5
+ class Flags
6
+
7
+ include Singleton
8
+
9
+ class << self
10
+
11
+ # @return [Boolean]
12
+ def ready!
13
+ instance.options[:ready] = true
14
+ end
15
+
16
+ # @return [Boolean]
17
+ def ready?
18
+ instance.options[:ready]
19
+ end
20
+
21
+ # Reset the flags to the default values.
22
+ #
23
+ # @return [Hash]
24
+ def reset!
25
+ instance.reset!
26
+ end
27
+
28
+ end # Eigenclass
29
+
30
+ # @!attribute [rw]
31
+ # @return [Hash]
32
+ attr_accessor :options
33
+
34
+ # Create a new singleton instance of Vedeu::Flags.
35
+ #
36
+ # @return [Vedeu::Flags]
37
+ def initialize
38
+ self.options = defaults
39
+ end
40
+
41
+ # @return [Hash]
42
+ def reset!
43
+ self.options = defaults
44
+ end
45
+
46
+ private
47
+
48
+ # @return [Hash]
49
+ def defaults
50
+ {
51
+ ready: false,
52
+ }
53
+ end
54
+
55
+ end # Flags
56
+
57
+ end # Vedeu