vedeu 0.6.40 → 0.6.41

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/.yardopts +7 -0
  4. data/README.md +10 -0
  5. data/benchmarks/array_vs_range.rb +41 -0
  6. data/docs/api.md +7 -0
  7. data/docs/colours_styles.md +4 -0
  8. data/docs/debugging.md +19 -0
  9. data/docs/template.md +1 -0
  10. data/examples/284_slow_rendering.rb +105 -0
  11. data/lib/vedeu/borders/dsl.rb +2 -1
  12. data/lib/vedeu/borders/repository.rb +2 -1
  13. data/lib/vedeu/buffers/repository.rb +2 -1
  14. data/lib/vedeu/colours/backgrounds.rb +2 -1
  15. data/lib/vedeu/colours/foregrounds.rb +2 -1
  16. data/lib/vedeu/configuration/configuration.rb +3 -1
  17. data/lib/vedeu/cursors/cursor.rb +3 -1
  18. data/lib/vedeu/cursors/repository.rb +4 -2
  19. data/lib/vedeu/distributed/server.rb +5 -2
  20. data/lib/vedeu/dsl/view.rb +4 -1
  21. data/lib/vedeu/editor/document.rb +13 -12
  22. data/lib/vedeu/editor/repository.rb +2 -1
  23. data/lib/vedeu/events/aliases.rb +3 -1
  24. data/lib/vedeu/events/event.rb +6 -2
  25. data/lib/vedeu/events/repository.rb +2 -1
  26. data/lib/vedeu/events/trigger.rb +2 -1
  27. data/lib/vedeu/geometry/dsl.rb +2 -1
  28. data/lib/vedeu/geometry/repository.rb +2 -1
  29. data/lib/vedeu/groups/clear.rb +2 -1
  30. data/lib/vedeu/groups/dsl.rb +2 -1
  31. data/lib/vedeu/groups/group.rb +4 -1
  32. data/lib/vedeu/groups/repository.rb +2 -1
  33. data/lib/vedeu/input/dsl.rb +2 -1
  34. data/lib/vedeu/input/keymaps.rb +2 -1
  35. data/lib/vedeu/input/mapper.rb +2 -1
  36. data/lib/vedeu/interfaces/dsl.rb +2 -1
  37. data/lib/vedeu/interfaces/interface.rb +3 -1
  38. data/lib/vedeu/interfaces/repository.rb +2 -1
  39. data/lib/vedeu/logging/all.rb +1 -0
  40. data/lib/vedeu/logging/debug.rb +2 -1
  41. data/lib/vedeu/logging/ips.rb +57 -0
  42. data/lib/vedeu/logging/log.rb +4 -1
  43. data/lib/vedeu/logging/timer.rb +2 -1
  44. data/lib/vedeu/menus/menu.rb +2 -1
  45. data/lib/vedeu/menus/repository.rb +2 -1
  46. data/lib/vedeu/models/focus.rb +6 -2
  47. data/lib/vedeu/output/clear/interface.rb +46 -4
  48. data/lib/vedeu/output/compressor.rb +1 -1
  49. data/lib/vedeu/output/output.rb +36 -3
  50. data/lib/vedeu/output/renderers/all.rb +3 -1
  51. data/lib/vedeu/runtime/application.rb +2 -1
  52. data/lib/vedeu/runtime/flags.rb +3 -1
  53. data/lib/vedeu/runtime/main_loop.rb +2 -2
  54. data/lib/vedeu/runtime/router.rb +2 -1
  55. data/lib/vedeu/terminal/buffer.rb +27 -8
  56. data/lib/vedeu/terminal/terminal.rb +4 -1
  57. data/lib/vedeu/version.rb +1 -1
  58. data/test/lib/vedeu/editor/document_test.rb +1 -0
  59. data/test/lib/vedeu/output/clear/interface_test.rb +1 -0
  60. data/test/lib/vedeu/output/output_test.rb +45 -1
  61. data/test/lib/vedeu/terminal/buffer_test.rb +11 -0
  62. data/test/lib/vedeu_test.rb +2 -0
  63. data/test/test_helper.rb +21 -0
  64. data/vedeu.gemspec +1 -0
  65. metadata +20 -2
@@ -22,7 +22,8 @@ module Vedeu
22
22
  #
23
23
  # @!method documents
24
24
  # @return [Vedeu::Editor::Repository]
25
- def_delegators Vedeu::Editor::Repository, :documents
25
+ def_delegators Vedeu::Editor::Repository,
26
+ :documents
26
27
 
27
28
  # :nocov:
28
29
 
@@ -108,6 +108,8 @@ module Vedeu
108
108
  # @see Vedeu::Events::Aliases#bind_alias
109
109
  # @!method unbind_alias
110
110
  # @see Vedeu::Events::Aliases#unbind_alias
111
- def_delegators Vedeu::Events::Aliases, :bind_alias, :unbind_alias
111
+ def_delegators Vedeu::Events::Aliases,
112
+ :bind_alias,
113
+ :unbind_alias
112
114
 
113
115
  end # Vedeu
@@ -126,7 +126,8 @@ module Vedeu
126
126
 
127
127
  extend Forwardable
128
128
 
129
- def_delegators Vedeu::Events::Trigger, :trigger
129
+ def_delegators Vedeu::Events::Trigger,
130
+ :trigger
130
131
 
131
132
  end # Eigenclass
132
133
 
@@ -305,6 +306,9 @@ module Vedeu
305
306
  # @see Vedeu::Events::Event.bound?
306
307
  # @!method unbind
307
308
  # @see Vedeu::Events::Event.unbind
308
- def_delegators Vedeu::Events::Event, :bind, :bound?, :unbind
309
+ def_delegators Vedeu::Events::Event,
310
+ :bind,
311
+ :bound?,
312
+ :unbind
309
313
 
310
314
  end # Vedeu
@@ -34,6 +34,7 @@ module Vedeu
34
34
  #
35
35
  # @!method events
36
36
  # @return [Vedeu::Events::Repository]
37
- def_delegators Vedeu::Events::Repository, :events
37
+ def_delegators Vedeu::Events::Repository,
38
+ :events
38
39
 
39
40
  end # Vedeu
@@ -83,6 +83,7 @@ module Vedeu
83
83
 
84
84
  # @!method trigger
85
85
  # @see Vedeu::Events::Trigger.trigger
86
- def_delegators Vedeu::Events::Trigger, :trigger
86
+ def_delegators Vedeu::Events::Trigger,
87
+ :trigger
87
88
 
88
89
  end # Vedeu
@@ -529,6 +529,7 @@ module Vedeu
529
529
 
530
530
  # @!method geometry
531
531
  # @see Vedeu::Geometry::DSL.geometry
532
- def_delegators Vedeu::Geometry::DSL, :geometry
532
+ def_delegators Vedeu::Geometry::DSL,
533
+ :geometry
533
534
 
534
535
  end # Vedeu
@@ -23,7 +23,8 @@ module Vedeu
23
23
  #
24
24
  # @!method geometries
25
25
  # @return [Vedeu::Geometry::Repository]
26
- def_delegators Vedeu::Geometry::Repository, :geometries
26
+ def_delegators Vedeu::Geometry::Repository,
27
+ :geometries
27
28
 
28
29
  # :nocov:
29
30
 
@@ -56,7 +56,8 @@ module Vedeu
56
56
 
57
57
  # @!method clear_by_group
58
58
  # @see Vedeu::Groups::Clear.render
59
- def_delegators Vedeu::Groups::Clear, :clear_by_group
59
+ def_delegators Vedeu::Groups::Clear,
60
+ :clear_by_group
60
61
 
61
62
  # :nocov:
62
63
 
@@ -94,6 +94,7 @@ module Vedeu
94
94
 
95
95
  # @!method group
96
96
  # @see Vedeu::Groups::DSL.group
97
- def_delegators Vedeu::Groups::DSL, :group
97
+ def_delegators Vedeu::Groups::DSL,
98
+ :group
98
99
 
99
100
  end # Vedeu
@@ -177,7 +177,10 @@ module Vedeu
177
177
  # @see Vedeu::Toggleable::ClassMethods#show
178
178
  # @!method toggle_group
179
179
  # @see Vedeu::Toggleable::ClassMethods#toggle
180
- def_delegators Vedeu::Groups::Group, :hide_group, :show_group, :toggle_group
180
+ def_delegators Vedeu::Groups::Group,
181
+ :hide_group,
182
+ :show_group,
183
+ :toggle_group
181
184
 
182
185
  # :nocov:
183
186
 
@@ -28,6 +28,7 @@ module Vedeu
28
28
  #
29
29
  # @!method groups
30
30
  # @return [Vedeu::Groups::Repository]
31
- def_delegators Vedeu::Groups::Repository, :groups
31
+ def_delegators Vedeu::Groups::Repository,
32
+ :groups
32
33
 
33
34
  end # Vedeu
@@ -116,6 +116,7 @@ module Vedeu
116
116
 
117
117
  # @!method keymap
118
118
  # @see Vedeu::Input::DSL.keymap
119
- def_delegators Vedeu::Input::DSL, :keymap
119
+ def_delegators Vedeu::Input::DSL,
120
+ :keymap
120
121
 
121
122
  end # Vedeu
@@ -21,6 +21,7 @@ module Vedeu
21
21
  #
22
22
  # @!method keymaps
23
23
  # @return [Vedeu::Input::Keymaps]
24
- def_delegators Vedeu::Input::Keymaps, :keymaps
24
+ def_delegators Vedeu::Input::Keymaps,
25
+ :keymaps
25
26
 
26
27
  end # Vedeu
@@ -150,7 +150,8 @@ module Vedeu
150
150
 
151
151
  # @!method keypress
152
152
  # @see Vedeu::Input::Mapper.keypress
153
- def_delegators Vedeu::Input::Mapper, :keypress
153
+ def_delegators Vedeu::Input::Mapper,
154
+ :keypress
154
155
 
155
156
  # :nocov:
156
157
 
@@ -374,6 +374,7 @@ module Vedeu
374
374
 
375
375
  # @!method interface
376
376
  # @see Vedeu::Interfaces::DSL.interface
377
- def_delegators Vedeu::Interfaces::DSL, :interface
377
+ def_delegators Vedeu::Interfaces::DSL,
378
+ :interface
378
379
 
379
380
  end # Vedeu
@@ -137,7 +137,9 @@ module Vedeu
137
137
  # @see Vedeu::Toggleable::ClassMethods#show
138
138
  # @!method toggle_interface
139
139
  # @see Vedeu::Toggleable::ClassMethods#toggle
140
- def_delegators Vedeu::Interfaces::Interface, :hide_interface, :show_interface,
140
+ def_delegators Vedeu::Interfaces::Interface,
141
+ :hide_interface,
142
+ :show_interface,
141
143
  :toggle_interface
142
144
 
143
145
  # :nocov:
@@ -39,6 +39,7 @@ module Vedeu
39
39
  #
40
40
  # @!method interfaces
41
41
  # @return [Vedeu::Interfaces::Repository]
42
- def_delegators Vedeu::Interfaces::Repository, :interfaces
42
+ def_delegators Vedeu::Interfaces::Repository,
43
+ :interfaces
43
44
 
44
45
  end # Vedeu
@@ -12,5 +12,6 @@ end # Vedeu
12
12
  require 'vedeu/logging/lockless_log_device'
13
13
  require 'vedeu/logging/mono_logger'
14
14
  require 'vedeu/logging/log'
15
+ require 'vedeu/logging/ips'
15
16
  require 'vedeu/logging/debug'
16
17
  require 'vedeu/logging/timer'
@@ -95,6 +95,7 @@ module Vedeu
95
95
  #
96
96
  # @!method profile
97
97
  # @return [Vedeu::Logging::Debug]
98
- def_delegators Vedeu::Logging::Debug, :profile
98
+ def_delegators Vedeu::Logging::Debug,
99
+ :profile
99
100
 
100
101
  end # Vedeu
@@ -0,0 +1,57 @@
1
+ require 'benchmark/ips'
2
+
3
+ module Vedeu
4
+
5
+ module Logging
6
+
7
+ module Debug
8
+
9
+ class IPS
10
+
11
+ attr_accessor :samples
12
+ attr_accessor :benchmark
13
+
14
+ def initialize
15
+ @old_stdout = $stdout
16
+ $stdout = StringIO.new
17
+ @samples = {}
18
+ @benchmark = Benchmark::IPS::Job.new
19
+ @count = 0
20
+ end
21
+
22
+ def add_item(label = '', &blk)
23
+ samples[label] = blk
24
+ @count += 1
25
+
26
+ benchmark.item(label, &blk)
27
+ end
28
+
29
+ def execute!
30
+ benchmark.compare!
31
+ benchmark.run_warmup
32
+ benchmark.run
33
+
34
+ $stdout.sync = true
35
+ benchmark.run_comparison
36
+ benchmark.full_report
37
+
38
+ Vedeu.log(type: :debug, message: "IPS:\n#{$stdout.string}")
39
+ $stdout = @old_stdout
40
+
41
+ Vedeu.log(type: :debug, message: "Running: #{key}")
42
+ samples[key].call
43
+ end
44
+
45
+ private
46
+
47
+ def key
48
+ @key ||= samples.keys.sample
49
+ end
50
+
51
+ end # IPS
52
+
53
+ end # Debug
54
+
55
+ end # Logging
56
+
57
+ end # Vedeu
@@ -191,7 +191,10 @@ module Vedeu
191
191
  # @see Vedeu::Logging::Log.log_stdout
192
192
  # @!method log_stderr
193
193
  # @see Vedeu::Logging::Log.log_stderr
194
- def_delegators Vedeu::Logging::Log, :log, :log_stdout, :log_stderr
194
+ def_delegators Vedeu::Logging::Log,
195
+ :log,
196
+ :log_stdout,
197
+ :log_stderr
195
198
 
196
199
  # :nocov:
197
200
 
@@ -91,6 +91,7 @@ module Vedeu
91
91
  #
92
92
  # @!method timer
93
93
  # @see Vedeu::Logging::Timer.timer
94
- def_delegators Vedeu::Logging::Timer, :timer
94
+ def_delegators Vedeu::Logging::Timer,
95
+ :timer
95
96
 
96
97
  end # Vedeu
@@ -201,6 +201,7 @@ module Vedeu
201
201
 
202
202
  # @!method menu
203
203
  # @see Vedeu::Menus::DSL.menu
204
- def_delegators Vedeu::Menus::DSL, :menu
204
+ def_delegators Vedeu::Menus::DSL,
205
+ :menu
205
206
 
206
207
  end # Vedeu
@@ -22,7 +22,8 @@ module Vedeu
22
22
  #
23
23
  # @!method menus
24
24
  # @return [Vedeu::Menus::Repository]
25
- def_delegators Vedeu::Menus::Repository, :menus
25
+ def_delegators Vedeu::Menus::Repository,
26
+ :menus
26
27
 
27
28
  # :nocov:
28
29
 
@@ -262,8 +262,12 @@ module Vedeu
262
262
  # @see Vedeu::Models::Focus#focus_next
263
263
  # @!method focus_previous
264
264
  # @see Vedeu::Models::Focus#focus_previous
265
- def_delegators Vedeu::Models::Focus, :focus, :focus_by_name, :focussed?,
266
- :focus_next, :focus_previous
265
+ def_delegators Vedeu::Models::Focus,
266
+ :focus,
267
+ :focus_by_name,
268
+ :focussed?,
269
+ :focus_next,
270
+ :focus_previous
267
271
 
268
272
  # :nocov:
269
273
 
@@ -37,7 +37,7 @@ module Vedeu
37
37
  def clear_content_by_name(name = Vedeu.focus)
38
38
  name || Vedeu.focus
39
39
 
40
- new(name, content_only: true).render
40
+ new(name, content_only: true, direct: true).render
41
41
  end
42
42
 
43
43
  end # Eigenclass
@@ -49,6 +49,11 @@ module Vedeu
49
49
  # @param options [Hash]
50
50
  # @option options content_only [Boolean] Only clear the content
51
51
  # not the border as well. Defaults to false.
52
+ # @option options direct [Boolean] Write the content directly
53
+ # to the terminal using a faster mechanism. The virtual buffer
54
+ # will still be updated. This improves the refresh time for
55
+ # Vedeu as we will not be building a grid of
56
+ # {Vedeu::Views::Char} objects.
52
57
  # @return [Vedeu::Clear::Interface]
53
58
  def initialize(name, options = {})
54
59
  @name = present?(name) ? name : Vedeu.focus
@@ -57,7 +62,15 @@ module Vedeu
57
62
 
58
63
  # @return [Array<Array<Vedeu::Views::Char>>]
59
64
  def render
60
- Vedeu.render_output(output)
65
+ if direct?
66
+ Vedeu.direct_write(optimised_output)
67
+
68
+ Vedeu::Terminal::Buffer.update(output)
69
+
70
+ else
71
+ Vedeu.render_output(output)
72
+
73
+ end
61
74
  end
62
75
 
63
76
  protected
@@ -87,9 +100,15 @@ module Vedeu
87
100
  def defaults
88
101
  {
89
102
  content_only: false,
103
+ direct: false,
90
104
  }
91
105
  end
92
106
 
107
+ # @return [Boolean]
108
+ def direct?
109
+ options[:direct]
110
+ end
111
+
93
112
  # @see Vedeu::Geometry::Repository#by_name
94
113
  def geometry
95
114
  @geometry ||= Vedeu.geometries.by_name(name)
@@ -112,6 +131,27 @@ module Vedeu
112
131
  defaults.merge!(@options)
113
132
  end
114
133
 
134
+ # @return [String]
135
+ def optimised_output
136
+ Vedeu.timer("Optimised clearing #{clearing}: '#{name}'".freeze) do
137
+ output = ''
138
+
139
+ @y = y
140
+ @x = x
141
+ @colour = colour.to_s
142
+ @chars = (' ' * width).freeze
143
+
144
+ height.times do |iy|
145
+ output << Vedeu::Geometry::Position.new(@y + iy, @x).to_s
146
+ output << @colour
147
+ output << @chars
148
+ end
149
+
150
+ output << Vedeu::Geometry::Position.new(@y, @x).to_s
151
+ output
152
+ end
153
+ end
154
+
115
155
  # For each visible line of the interface, set the foreground and
116
156
  # background colours to those specified when the interface was
117
157
  # defined, then starting write space characters over the area
@@ -170,11 +210,13 @@ module Vedeu
170
210
 
171
211
  # @!method clear_by_name
172
212
  # @see Vedeu::Clear::Interface.render
173
- def_delegators Vedeu::Clear::Interface, :clear_by_name
213
+ def_delegators Vedeu::Clear::Interface,
214
+ :clear_by_name
174
215
 
175
216
  # @!method clear_content_by_name
176
217
  # @see Vedeu::Clear::Interface.clear_content_by_name
177
- def_delegators Vedeu::Clear::Interface, :clear_content_by_name
218
+ def_delegators Vedeu::Clear::Interface,
219
+ :clear_content_by_name
178
220
 
179
221
  # :nocov:
180
222
 
@@ -56,7 +56,7 @@ module Vedeu
56
56
 
57
57
  # @return [String]
58
58
  def compress
59
- Vedeu.timer('Compression'.freeze) do
59
+ Vedeu.timer("Compression for #{content.size} characters".freeze) do
60
60
  out = ''
61
61
 
62
62
  content.each do |cell|
@@ -9,10 +9,29 @@ module Vedeu
9
9
  #
10
10
  class Output
11
11
 
12
+ # @param output [Array<Array<Vedeu::Views::Char>>|
13
+ # NilClass|Vedeu::Models::Escape]
14
+ # @return [Array]
15
+ def self.buffer_write(output)
16
+ return nil if output.nil?
17
+
18
+ new(output).buffer_write
19
+ end
20
+
21
+ # @param output [Array<Array<Vedeu::Views::Char>>|
22
+ # NilClass|Vedeu::Models::Escape]
23
+ # @return [Array<String>]
24
+ def self.direct_write(output)
25
+ return nil if output.nil?
26
+
27
+ new(output).direct_write
28
+ end
29
+
12
30
  # Writes output to the defined renderers.
13
31
  #
32
+ # @param output [Array<Array<Vedeu::Views::Char>>|
33
+ # NilClass|Vedeu::Models::Escape]
14
34
  # @return [Array|NilClass|String]
15
- # @see #initialize
16
35
  def self.render_output(output)
17
36
  return nil if output.nil?
18
37
 
@@ -21,12 +40,23 @@ module Vedeu
21
40
 
22
41
  # Return a new instance of Vedeu::Output::Output.
23
42
  #
24
- # @param output [Array<Array<Vedeu::Views::Char>>]
43
+ # @param output [Array<Array<Vedeu::Views::Char>>|
44
+ # NilClass|Vedeu::Models::Escape]
25
45
  # @return [Vedeu::Output::Output]
26
46
  def initialize(output)
27
47
  @output = output
28
48
  end
29
49
 
50
+ # @return [Array]
51
+ def buffer_write
52
+ buffer_write!
53
+ end
54
+
55
+ # @return [Array<String>]
56
+ def direct_write
57
+ direct_write!
58
+ end
59
+
30
60
  # Send the view to the renderers. If the output is a
31
61
  # {Vedeu::Models::Escape} object (typical when showing or
32
62
  # hiding the cursor) then we bypass the
@@ -80,6 +110,9 @@ module Vedeu
80
110
  #
81
111
  # @!method render_output
82
112
  # @return [Array|NilClass]
83
- def_delegators Vedeu::Output::Output, :render_output
113
+ def_delegators Vedeu::Output::Output,
114
+ :render_output,
115
+ :buffer_write,
116
+ :direct_write
84
117
 
85
118
  end # Vedeu