vedeu 0.6.21 → 0.6.22

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/bin/vedeu_drb_server +1 -0
  4. data/docs/configuration.md +3 -0
  5. data/docs/events/refresh.md +5 -0
  6. data/docs/events/visibility.md +6 -0
  7. data/examples/hello_worlds.rb +79 -0
  8. data/lib/vedeu/all.rb +2 -2
  9. data/lib/vedeu/bindings/refresh.rb +8 -0
  10. data/lib/vedeu/bindings/visibility.rb +8 -0
  11. data/lib/vedeu/borders/border.rb +1 -1
  12. data/lib/vedeu/borders/render.rb +13 -10
  13. data/lib/vedeu/buffers/buffer.rb +5 -49
  14. data/lib/vedeu/buffers/refresh.rb +33 -15
  15. data/lib/vedeu/configuration/api.rb +32 -3
  16. data/lib/vedeu/configuration/configuration.rb +16 -2
  17. data/lib/vedeu/cursors/refresh.rb +1 -1
  18. data/lib/vedeu/distributed/templates/default_configuration.vedeu +1 -0
  19. data/lib/vedeu/editor/document.rb +1 -3
  20. data/lib/vedeu/logging/debug.rb +11 -8
  21. data/lib/vedeu/logging/timer.rb +18 -4
  22. data/lib/vedeu/models/interface.rb +18 -6
  23. data/lib/vedeu/models/views/view.rb +2 -9
  24. data/lib/vedeu/output/clear/interface.rb +93 -9
  25. data/lib/vedeu/output/direct.rb +0 -2
  26. data/lib/vedeu/output/viewport.rb +18 -16
  27. data/lib/vedeu/runtime/launcher.rb +25 -26
  28. data/lib/vedeu/version.rb +1 -1
  29. data/test/lib/vedeu/bindings/refresh_test.rb +1 -0
  30. data/test/lib/vedeu/bindings/visibility_test.rb +1 -0
  31. data/test/lib/vedeu/borders/border_test.rb +2 -2
  32. data/test/lib/vedeu/borders/render_test.rb +12 -69
  33. data/test/lib/vedeu/buffers/buffer_test.rb +0 -31
  34. data/test/lib/vedeu/buffers/refresh_test.rb +2 -10
  35. data/test/lib/vedeu/cursors/refresh_test.rb +2 -2
  36. data/test/lib/vedeu/editor/document_test.rb +3 -3
  37. data/test/lib/vedeu/logging/debug_test.rb +3 -3
  38. data/test/lib/vedeu/logging/timer_test.rb +24 -6
  39. data/test/lib/vedeu/models/interface_test.rb +4 -8
  40. data/test/lib/vedeu/models/views/view_test.rb +12 -22
  41. data/test/lib/vedeu/output/clear/interface_test.rb +7 -1
  42. data/test/lib/vedeu/output/viewport_test.rb +11 -190
  43. data/test/lib/vedeu/runtime/launcher_test.rb +2 -1
  44. data/test/lib/vedeu_test.rb +18 -19
  45. data/test/support/examples/borders_app.rb +4 -3
  46. data/test/support/examples/drb_app.rb +4 -3
  47. data/test/support/examples/editor_app.rb +3 -7
  48. data/test/support/examples/focus_app.rb +4 -4
  49. data/test/support/examples/hello_world.rb +5 -2
  50. data/test/support/examples/material_colours_app.rb +3 -42
  51. data/test/test_helper.rb +1 -0
  52. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b2bc250678c9728597c333d93e87cc728cbb4767
4
- data.tar.gz: 5be52acf963d8b8db5fdc19a478293b836c7edb8
3
+ metadata.gz: 962d118b37be3f266143bd483c590ea61fcb045b
4
+ data.tar.gz: a10a95a4e722f747a4faa9b07653d1a74ba98ccb
5
5
  SHA512:
6
- metadata.gz: b0210cec1fa8d31b42f9dcb8deb71697e09b2925120274524bcb185da446481dede13465795ef86ebb1b6b5d44d228d36667ac11733ba87d7a6702c9e87b14e8
7
- data.tar.gz: 6e9b739f5ee331a20e1df15c4e97880313f9491067edc82d487c553757eafd134bc14861c9ecf5a384ed314d79253e62b3ec07dcb2db16e0dcbabb2235a62ed3
6
+ metadata.gz: 658eae376a443bde02be432fd0c91c46f972c59da102ea7f198198831b0dc2371776566cb74545829ba4b2a7c3a3f0e8196993be1faadaa3ec195f87db24cbf8
7
+ data.tar.gz: 3950ca1569a8e8ebf80fe8b14692fcf0796fa61d5eb9d9267ed7606a654ecde8519ac79c4f6d591166f988aad10e8fbee74bbb22ee29c2a3eff23353e28cd2db
data/.rubocop.yml CHANGED
@@ -21,6 +21,7 @@ AllCops:
21
21
  - '**/Cheffile'
22
22
  - '**/Vagabondfile'
23
23
  Exclude:
24
+ - 'examples/**/*'
24
25
  - 'test/**/*'
25
26
  - 'vendor/**/*'
26
27
  # By default, the rails cops are not run. Override in project or home
data/bin/vedeu_drb_server CHANGED
@@ -12,6 +12,7 @@ class VedeuTestApplication
12
12
  colour_mode 16_777_216
13
13
  log '/tmp/vedeu_test_helper.log'
14
14
  debug!
15
+ profile!
15
16
  drb!
16
17
  drb_host 'localhost'
17
18
  drb_port 21_420
@@ -57,6 +57,9 @@ reason, simply ask for it:
57
57
  ### log_only
58
58
  {include:Vedeu::Config::API#log_only}
59
59
 
60
+ ### profile / profile!
61
+ {include:Vedeu::Config::API#profile}
62
+
60
63
  ### raw / raw!
61
64
  {include:Vedeu::Config::API#raw}
62
65
 
@@ -29,3 +29,8 @@ Will cause all interfaces in the named group to refresh.
29
29
  Will cause the named view to refresh.
30
30
 
31
31
  Vedeu.trigger(:_refresh_view_, name)
32
+
33
+ ### :_refresh_view_content_
34
+ Will cause only the content of the named view to refresh.
35
+
36
+ Vedeu.trigger(:_refresh_view_content_, name)
@@ -23,6 +23,12 @@ Clears the named view/interface area.
23
23
  Vedeu.trigger(:_clear_view_, name)
24
24
  Vedeu.clear_by_name(name)
25
25
 
26
+ ### :_clear_view_content_
27
+ Clears only the content of the named view/interface area.
28
+
29
+ Vedeu.trigger(:_clear_view_content_, name)
30
+ Vedeu.clear_content_by_name(name)
31
+
26
32
  ### :_hide_cursor_
27
33
  Hide the cursor of the named interface or when a name is not given,
28
34
  the interface currently in focus.
@@ -0,0 +1,79 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'vedeu'
5
+
6
+ # An example application to demonstrate 'Hello World' and a minimum of
7
+ # interactivity. It uses the DSL-style of vedeu (not the full-flegded
8
+ # MVC-approach).
9
+ #
10
+ # If you have cloned this repository from GitHub, you can run this example:
11
+ #
12
+ # bundle exec ./examples/hello_worlds.rb
13
+ #
14
+ class HelloWorldsApp
15
+
16
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
17
+
18
+ Vedeu.configure do
19
+ # Empty configure block is needed.
20
+ end
21
+
22
+ Vedeu.interface :hello do
23
+ # Define all of the interface in one place.
24
+ background '#000000'
25
+ foreground '#00ff00'
26
+ geometry do
27
+ centred!
28
+ height 5
29
+ width 24
30
+ end
31
+ # (You usually specify the views outside the interface block).
32
+ Vedeu.views do
33
+ view :hello do
34
+ lines do
35
+ line { centre 'Hello Worlds!', width: 24 }
36
+ line
37
+ line { centre "Press 'q' to exit,", width: 24 }
38
+ line { centre " 'w' to switch worlds.", width: 24 }
39
+ end
40
+ end
41
+ end
42
+ keymap do
43
+ key('q') { Vedeu.exit }
44
+ key('w') { HelloWorldsApp.render_world }
45
+ end
46
+ end
47
+
48
+ def self.start(argv = ARGV)
49
+ Vedeu::Launcher.execute!(argv)
50
+ end
51
+
52
+ private
53
+
54
+ def self.render_world
55
+ # Immediately render this to screen.
56
+ Vedeu.render do
57
+ view :hello do
58
+ geometry do
59
+ centred!
60
+ height 5 + 2
61
+ width 24 + 2
62
+ end
63
+ border do
64
+ colour foreground: ["#00ff00", "#000033", "#cddc39", "#03a9f4"].sample
65
+ title ["atlantis", "oceania", "utopia", "midgard", "middle-earth"].sample
66
+ end
67
+ lines do
68
+ line { centre 'Hello Worlds!', width: 24 }
69
+ line
70
+ line { centre "Press 'q' to exit,", width: 24 }
71
+ line { centre " 'w' to switch worlds.", width: 24 }
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ end # HelloWorldsApp
78
+
79
+ HelloWorldsApp.start(ARGV)
data/lib/vedeu/all.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'vedeu/logging/all'
2
1
  require 'vedeu/version'
2
+
3
+ require 'vedeu/logging/all'
3
4
  require 'vedeu/options'
4
5
 
5
6
  require 'vedeu/error'
6
7
  require 'vedeu/common'
7
- require 'vedeu/logging/all'
8
8
  require 'vedeu/runtime/all'
9
9
 
10
10
  require 'vedeu/configuration/api'
@@ -17,6 +17,7 @@ module Vedeu
17
17
  refresh_cursor!
18
18
  refresh_group!
19
19
  refresh_view!
20
+ refresh_view_content!
20
21
  end
21
22
 
22
23
  private
@@ -49,6 +50,13 @@ module Vedeu
49
50
  end
50
51
  end
51
52
 
53
+ # See {file:docs/events/refresh.md#\_refresh_view_content_}
54
+ def refresh_view_content!
55
+ Vedeu.bind(:_refresh_view_content_) do |name|
56
+ Vedeu::Buffers::Refresh.refresh_content_by_name(name)
57
+ end
58
+ end
59
+
52
60
  # :nocov:
53
61
 
54
62
  end # Refresh
@@ -17,6 +17,7 @@ module Vedeu
17
17
  clear!
18
18
  clear_group!
19
19
  clear_view!
20
+ clear_view_content!
20
21
  hide_cursor!
21
22
  hide_group!
22
23
  hide_interface!
@@ -54,6 +55,13 @@ module Vedeu
54
55
  Vedeu.bind(:_clear_view_) { |name| Vedeu.clear_by_name(name) }
55
56
  end
56
57
 
58
+ # See {file:docs/events/visibility.md#\_clear_view_content_}
59
+ def clear_view_content!
60
+ Vedeu.bind(:_clear_view_content_) do |name|
61
+ Vedeu.clear_content_by_name(name)
62
+ end
63
+ end
64
+
57
65
  # See {file:docs/events/visibility.md#\_hide_cursor_}
58
66
  def hide_cursor!
59
67
  Vedeu.bind(:_hide_cursor_) { |name| Vedeu.hide_cursor(name) }
@@ -172,7 +172,7 @@ module Vedeu
172
172
 
173
173
  # @return [Array<Array<Vedeu::Views::Char>>]
174
174
  def render
175
- Vedeu::Borders::Render.with(self)
175
+ Vedeu::Borders::Render.render(self)
176
176
  end
177
177
 
178
178
  private
@@ -41,7 +41,7 @@ module Vedeu
41
41
 
42
42
  # @return [Array<Array<Vedeu::Views::Char>>]
43
43
  # @param (see #initialize)
44
- def self.with(border)
44
+ def self.render(border)
45
45
  new(border).render
46
46
  end
47
47
 
@@ -55,15 +55,7 @@ module Vedeu
55
55
 
56
56
  # @return [Array<Array<Vedeu::Views::Char>>]
57
57
  def render
58
- return [] unless enabled?
59
-
60
- Vedeu.timer("Bordering: '#{name}'") do
61
- out = [top, bottom]
62
-
63
- height.times { |y| out << [left(y), right(y)] }
64
-
65
- out.flatten
66
- end
58
+ Vedeu::Output::Output.render(output) if enabled?
67
59
  end
68
60
 
69
61
  protected
@@ -74,6 +66,17 @@ module Vedeu
74
66
 
75
67
  private
76
68
 
69
+ # @return [Array<Array<Vedeu::Views::Char>>]
70
+ def output
71
+ Vedeu.timer("Bordering: '#{name}'") do
72
+ out = [top, bottom]
73
+
74
+ height.times { |y| out << [left(y), right(y)] }
75
+
76
+ out.flatten
77
+ end
78
+ end
79
+
77
80
  # @param value [String]
78
81
  # @param type [Symbol|NilClass]
79
82
  # @param iy [Fixnum]
@@ -94,24 +94,7 @@ module Vedeu
94
94
  true
95
95
  end
96
96
 
97
- # Hide this buffer.
98
- #
99
- # @example
100
- # Vedeu.trigger(:_hide_interface_, name)
101
- # Vedeu.hide_interface(name)
102
- #
103
- # Will hide the named interface. If the interface is currently
104
- # visible, it will be cleared- rendered blank. To show the
105
- # interface, the ':_show_interface_' event should be triggered.
106
- # Triggering the ':_hide_group_' event to which this named
107
- # interface belongs will also hide the interface.
108
- #
109
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
110
- def hide
111
- Vedeu.trigger(:_clear_view_, name)
112
- end
113
-
114
- # Return the content for this buffer.
97
+ # Retrieve the latest content from the buffer.
115
98
  #
116
99
  # - If we have new content (i.e. content on 'back') to be shown,
117
100
  # we first clear the area occupied by the previous content,
@@ -126,46 +109,19 @@ module Vedeu
126
109
  #
127
110
  # @return [Array<Array<Array<Vedeu::Views::Char>>>]
128
111
  def render
129
- Vedeu::Output::Output.render(buffer)
130
- end
131
-
132
- # Show this buffer.
133
- #
134
- # @example
135
- # Vedeu.trigger(:_show_interface_, name)
136
- # Vedeu.show_interface(name)
137
- #
138
- # Will show the named interface. If the interface is currently
139
- # invisible, it will be shown- rendered with its latest content.
140
- # To hide the interface, the ':_hide_interface_' event should be
141
- # triggered. Triggering the ':_show_group_' event to which this
142
- # named interface belongs will also show the interface.
143
- #
144
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
145
- def show
146
- Vedeu::Output::Output.render(buffer)
147
- end
148
-
149
- private
150
-
151
- # Retrieve the latest content from the buffer.
152
- #
153
- # @return [Array<Array<Array<Vedeu::Views::Char>>>]
154
- def buffer
155
112
  swap if back?
156
113
 
157
114
  if front?
158
- [front.render]
115
+ front.render
159
116
 
160
117
  elsif previous?
161
- [previous.render]
162
-
163
- else
164
- []
118
+ previous.render
165
119
 
166
120
  end
167
121
  end
168
122
 
123
+ private
124
+
169
125
  # Returns the default options/attributes for this class.
170
126
  #
171
127
  # @return [Hash<Symbol => NilClass, String>]
@@ -4,32 +4,45 @@ module Vedeu
4
4
 
5
5
  # Refreshes the given named interface.
6
6
  #
7
- # @example
8
- # Vedeu.trigger(:_refresh_view_, name)
9
- #
10
7
  class Refresh
11
8
 
12
9
  include Vedeu::Common
13
10
 
11
+ # @example
12
+ # Vedeu.trigger(:_refresh_view_, name)
13
+ #
14
14
  # @param (see #initialize)
15
15
  # @return (see #by_name)
16
16
  def self.by_name(name)
17
17
  new(name).by_name
18
18
  end
19
19
 
20
+ # @example
21
+ # Vedeu.trigger(:_refresh_view_content_, name)
22
+ #
23
+ # @param (see #initialize)
24
+ # @return (see #by_name)
25
+ def self.refresh_content_by_name(name)
26
+ new(name, content_only: true).by_name
27
+ end
28
+
20
29
  # Return a new instance of Vedeu::Buffers::Refresh.
21
30
  #
22
31
  # @param name [String|Symbol] The name of the interface to be refreshed
23
32
  # using the named buffer.
33
+ # @param options [Hash]
34
+ # @option options content_only [Boolean]
24
35
  # @return [Vedeu::Buffers::Refresh]
25
- def initialize(name)
26
- @name = name
36
+ def initialize(name, options = {})
37
+ @name = name
38
+ @options = options
27
39
  end
28
40
 
29
41
  # @return [Array|Vedeu::Error::ModelNotFound]
30
42
  def by_name
31
- Vedeu.timer("Refresh Buffer: '#{buffer_name}'") do
32
- Vedeu.buffers.by_name(buffer_name).render
43
+ Vedeu.timer("Refresh Buffer: '#{name}'") do
44
+ Vedeu.buffers.by_name(name).render
45
+ Vedeu.borders.by_name(name).render unless content_only?
33
46
  end if Vedeu.ready?
34
47
  end
35
48
 
@@ -39,16 +52,21 @@ module Vedeu
39
52
  # @return [String|Symbol]
40
53
  attr_reader :name
41
54
 
42
- private
55
+ # @return [Boolean]
56
+ def content_only?
57
+ options[:content_only] == true
58
+ end
43
59
 
44
- # @raise [Vedeu::Error::MissingRequired] When the name is empty
45
- # or nil.
46
- # @return [String|Symbol]
47
- def buffer_name
48
- return name if present?(name)
60
+ # @return [Hash<Symbol => Boolean>]
61
+ def options
62
+ defaults.merge!(@options)
63
+ end
49
64
 
50
- fail Vedeu::Error::MissingRequired,
51
- 'Cannot refresh interface with an empty interface name.'
65
+ # @return [Hash<Symbol => Boolean>]
66
+ def defaults
67
+ {
68
+ content_only: false,
69
+ }
52
70
  end
53
71
 
54
72
  end # Refresh
@@ -221,9 +221,8 @@ module Vedeu
221
221
  # setting is for debugging to be disabled. Using `debug!` or
222
222
  # setting `debug` to true will enable debugging.
223
223
  #
224
- # @note
225
- # Be aware that running an application with debugging enabled
226
- # will affect performance.
224
+ # At this time, debugging only toggles between viewing a full
225
+ # backtrace (true) upon exception or only its top line (false).
227
226
  #
228
227
  # Vedeu.configure do
229
228
  # debug!
@@ -310,6 +309,36 @@ module Vedeu
310
309
  options[:log_only] = types
311
310
  end
312
311
 
312
+ # Sets boolean to enable/disable profiling. Vedeu's default
313
+ # setting is for profiling to be disabled. Using `profile!` or
314
+ # setting `profile` to true will enable profiling.
315
+ #
316
+ # Profile uses 'ruby-prof' to write a 'profile.html' file to
317
+ # the /tmp directory which contains a call trace of the running
318
+ # application. Upon exit, this file can be examined to ascertain
319
+ # certain behaviours of Vedeu.
320
+ #
321
+ # @note
322
+ # Be aware that running an application with profiling enabled
323
+ # will affect performance.
324
+ #
325
+ # Vedeu.configure do
326
+ # profile!
327
+ # # ...
328
+ # end
329
+ #
330
+ # Vedeu.configure do
331
+ # profile false
332
+ # # ...
333
+ # end
334
+ #
335
+ # @param value [Boolean]
336
+ # @return [Boolean]
337
+ def profile!(value = true)
338
+ options[:profile] = value
339
+ end
340
+ alias_method :profile, :profile!
341
+
313
342
  # Sets the renderers for Vedeu. Each renderer added must have
314
343
  # the class method '.render' defined as this will be called when
315
344
  # rendering content.