vedeu 0.8.25 → 0.8.26

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/docs/applications/existing_application.md +4 -0
  3. data/docs/applications/first_application.md +53 -0
  4. data/docs/applications/gem_application.md +31 -0
  5. data/docs/applications/simple_application.md +4 -0
  6. data/docs/cli/commands.md +1 -0
  7. data/docs/getting_started.md +4 -4
  8. data/integrations/dsl_app_geometry_001.rb +67 -0
  9. data/integrations/dsl_app_geometry_002.rb +67 -0
  10. data/integrations/dsl_app_geometry_003.rb +67 -0
  11. data/integrations/dsl_app_geometry_004.rb +67 -0
  12. data/integrations/expected/dsl_app_geometry_001.out +1 -0
  13. data/integrations/expected/dsl_app_geometry_002.out +1 -0
  14. data/integrations/expected/dsl_app_geometry_003.out +1 -0
  15. data/integrations/expected/dsl_app_geometry_004.out +1 -0
  16. data/integrations/test_runner.sh +6 -0
  17. data/lib/vedeu/buffers/all.rb +2 -1
  18. data/lib/vedeu/buffers/refresh.rb +10 -40
  19. data/lib/vedeu/buffers/refresh_content.rb +52 -0
  20. data/lib/vedeu/editor/document.rb +2 -2
  21. data/lib/vedeu/esc/actions.rb +2 -0
  22. data/lib/vedeu/esc/borders.rb +2 -0
  23. data/lib/vedeu/esc/colours.rb +2 -0
  24. data/lib/vedeu/esc/esc.rb +2 -0
  25. data/lib/vedeu/esc/mouse.rb +2 -0
  26. data/lib/vedeu/groups/refresh.rb +9 -8
  27. data/lib/vedeu/interfaces/clear.rb +1 -1
  28. data/lib/vedeu/interfaces/clear_content.rb +4 -2
  29. data/lib/vedeu/repositories/all.rb +1 -0
  30. data/lib/vedeu/repositories/cache.rb +74 -0
  31. data/lib/vedeu/version.rb +1 -1
  32. data/test/lib/vedeu/buffers/all_test.rb +12 -0
  33. data/test/lib/vedeu/buffers/refresh_content_test.rb +53 -0
  34. data/test/lib/vedeu/buffers/refresh_test.rb +5 -37
  35. data/test/lib/vedeu/repositories/cache_test.rb +51 -0
  36. metadata +22 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 977f6bdee8b7a54320de8ac868a677cdea943115
4
- data.tar.gz: 1bb42f91d121a6331b8fd2ee779bd9d2f47a13da
3
+ metadata.gz: ea635bbb37768511d6fc0c6d1131706f1ca8d073
4
+ data.tar.gz: 32c4abf0ee196597027be7c1590c501bff675e99
5
5
  SHA512:
6
- metadata.gz: f8e18b503177a2d2478a057639c480186cd82e6c3bb766d7c918e41c0129a2e0f4f143937650e3b06c567a2fcaaa8179db07215e05f0645909bb563d13ed7624
7
- data.tar.gz: 661116fd7b9a6c3209698c4ffd11248d374d63741560a793ece435c0bdda8d505cb2be806f68adacf5c36e17e0e7077d06d4831993da3e6a51c0840f50bc3d7f
6
+ metadata.gz: 554cc6c3e219e8b128d9d64ce88c6cd2cf991541d1037d37ac185fe4d54a92ced2e2b81ff65e3279d0a6721722cdc8bbe987782d4f0591b4be9c2c4af9d2c130
7
+ data.tar.gz: 3bdffdd88d3c54ddf3698b69162579fa1faf9f06bbeeb88e87c9aed970a4bb115e635e53eb28ce2a9e7eaf8f852481f610f66546dfaae837e56b09a83f7a2b85
@@ -0,0 +1,4 @@
1
+ # @title Incorporating Vedeu into an existing application
2
+ # Incorporating Vedeu into an existing application
3
+
4
+ @todo Add more documentation.
@@ -0,0 +1,53 @@
1
+ # @title Building a simple application using Vedeu
2
+ # Building a simple application using Vedeu
3
+
4
+ In this small tutorial, I hope to guide you through the process of
5
+ building a simple application which uses the Vedeu framework.
6
+
7
+ We're going to build a Slack bot. This bot will simply relay the
8
+ messages sent to a specific channel to your terminal to be displayed.
9
+ In a future episode, I might extend this to be able to send messages
10
+ back too to demonstrate other aspects of Vedeu, but one step at a
11
+ time.
12
+
13
+ If you would like to create a single file application, please see this
14
+ tutorial: {file:docs/application/simple_application}[Simple
15
+ Application].
16
+
17
+ If you would like to create a gem which uses Vedeu, please see this
18
+ tutorial: {file:docs/gem_application}[Gem Application].
19
+
20
+ If you would like to include Vedeu in an existing application, please
21
+ see this tutorial: {file:docs/existing_application}[Existing
22
+ Application].
23
+
24
+ If you would like to create a standalone application, please continue
25
+ reading...
26
+
27
+ ## 1) Getting started.
28
+
29
+ First, install the gem locally:
30
+
31
+ gem install vedeu
32
+
33
+ This will provide a new command to help build your client application.
34
+ Similar to Ruby on Rails, although not nearly as advanced as the Rails
35
+ equivalent, hopefully the `vedeu` command generators will get you off
36
+ the ground:
37
+
38
+ vedeu
39
+
40
+ Running the `vedeu` command with no arguments will give you a list of
41
+ the commands currently supported.
42
+
43
+ We can create a skeleton Vedeu client application using the following
44
+ command:
45
+
46
+ vedeu new your_app_name
47
+
48
+ If `your_app_name` already exists, Vedeu will only write new files
49
+ that do not exist at the file path. The generated files are a skeleton
50
+ Vedeu client application. Let's take a look at these files
51
+ individually.
52
+
53
+ @todo Add more documentation.
@@ -0,0 +1,31 @@
1
+ # @title Building a gem-based application using Vedeu
2
+ # Building a gem-based application using Vedeu
3
+
4
+ In this tutorial, I hope to guide you through the process of
5
+ building a simple application which uses the Vedeu framework as part
6
+ of a gem.
7
+
8
+ We're going to build a Slack bot. This bot will simply relay the
9
+ messages sent to a specific channel to your terminal to be displayed.
10
+ In a future episode, I might extend this to be able to send messages
11
+ back too to demonstrate other aspects of Vedeu, but one step at a
12
+ time.
13
+
14
+ ## 1) Create a gem.
15
+
16
+ Firstly, let's create an empty gem. I'm going to use my name in
17
+ underscored form as the name of my bot; he is just a listener (unlike
18
+ me as I'm usually quite noisy.)
19
+
20
+ bundle gem gavin_laking
21
+
22
+ Next, we edit the `*.gemspec` file to add `vedeu` and
23
+ `simple-slack-bot` as dependencies. You may also what to update other
24
+ aspects of the gemspec file here, but I'll leave that with you.
25
+
26
+ spec.add_dependency 'vedeu'
27
+ spec.add_dependency 'simple-slack-bot'
28
+
29
+ Now, run `bundle`, and we should see the 'Bundle complete!' message.
30
+
31
+ @todo Add more documentation.
@@ -0,0 +1,4 @@
1
+ # @title Building a simple application using Vedeu
2
+ # Building a simple application using Vedeu
3
+
4
+ @todo Add more documentation.
@@ -0,0 +1 @@
1
+ @todo Add more documentation.
@@ -72,10 +72,10 @@ it does much the same, minus the requests.
72
72
 
73
73
  ### app/helpers/
74
74
 
75
- Ruby on Rails has a concept of helpers which are not very
76
- object-oriented, but allow you to share functionality/behaviour across
77
- multiple views. Vedeu uses this concept as it will be familiar to many
78
- Rails developers and might be helpful to beginners.
75
+ 'Ruby on Rails' has a concept of helpers, which although not very
76
+ object-oriented, allow you to share functionality/behaviour across
77
+ multiple views. Vedeu uses this concept too, as it will be familiar to
78
+ many Rails developers and might be helpful to beginners.
79
79
 
80
80
  ### app/models/
81
81
 
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_geometry_001'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
13
+
14
+ Vedeu.configure do
15
+ debug!
16
+ log '/tmp/vedeu_integrations.log'
17
+ renderers [
18
+ Vedeu::Renderers::Terminal.new(
19
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
20
+ write_file: true)
21
+ ]
22
+ run_once!
23
+ standalone!
24
+
25
+ height 12
26
+ width 40
27
+ end
28
+
29
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
30
+
31
+ Vedeu.interface :geometry_interface do
32
+ background '#ff3300'
33
+ border do
34
+ title 'Other'
35
+ colour foreground: '#ff0000'
36
+ end
37
+ geometry do
38
+ x 3
39
+ y 3
40
+ xn 13
41
+ yn 4
42
+ end
43
+ zindex 2
44
+ end
45
+
46
+ Vedeu.render do
47
+ view(:geometry_interface) do
48
+ lines do
49
+ 2.times do
50
+ line (" " * 10)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.start(argv = ARGV)
57
+ Vedeu::Launcher.execute!(argv)
58
+ end
59
+
60
+ end # DSLApp
61
+
62
+ Vedeu.timer('Test') do
63
+ DSLApp.start
64
+ end
65
+
66
+ load File.dirname(__FILE__) + '/test_runner.rb'
67
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_geometry_002'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
13
+
14
+ Vedeu.configure do
15
+ debug!
16
+ log '/tmp/vedeu_integrations.log'
17
+ renderers [
18
+ Vedeu::Renderers::Terminal.new(
19
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
20
+ write_file: true)
21
+ ]
22
+ run_once!
23
+ standalone!
24
+
25
+ height 12
26
+ width 40
27
+ end
28
+
29
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
30
+
31
+ Vedeu.interface :geometry_interface do
32
+ background '#ff3300'
33
+ border do
34
+ title 'Other'
35
+ colour foreground: '#ff0000'
36
+ end
37
+ geometry do
38
+ x 21
39
+ y 3
40
+ xn 31
41
+ yn 4
42
+ end
43
+ zindex 2
44
+ end
45
+
46
+ Vedeu.render do
47
+ view(:geometry_interface) do
48
+ lines do
49
+ 2.times do
50
+ line (" " * 10)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.start(argv = ARGV)
57
+ Vedeu::Launcher.execute!(argv)
58
+ end
59
+
60
+ end # DSLApp
61
+
62
+ Vedeu.timer('Test') do
63
+ DSLApp.start
64
+ end
65
+
66
+ load File.dirname(__FILE__) + '/test_runner.rb'
67
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_geometry_003'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
13
+
14
+ Vedeu.configure do
15
+ debug!
16
+ log '/tmp/vedeu_integrations.log'
17
+ renderers [
18
+ Vedeu::Renderers::Terminal.new(
19
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
20
+ write_file: true)
21
+ ]
22
+ run_once!
23
+ standalone!
24
+
25
+ height 12
26
+ width 40
27
+ end
28
+
29
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
30
+
31
+ Vedeu.interface :geometry_interface do
32
+ background '#ff3300'
33
+ border do
34
+ title 'Other'
35
+ colour foreground: '#ff0000'
36
+ end
37
+ geometry do
38
+ x 3
39
+ y 4
40
+ xn 13
41
+ yn 5
42
+ end
43
+ zindex 2
44
+ end
45
+
46
+ Vedeu.render do
47
+ view(:geometry_interface) do
48
+ lines do
49
+ 2.times do
50
+ line (" " * 10)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.start(argv = ARGV)
57
+ Vedeu::Launcher.execute!(argv)
58
+ end
59
+
60
+ end # DSLApp
61
+
62
+ Vedeu.timer('Test') do
63
+ DSLApp.start
64
+ end
65
+
66
+ load File.dirname(__FILE__) + '/test_runner.rb'
67
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1,67 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'vedeu'
7
+
8
+ TESTCASE = 'dsl_app_geometry_004'
9
+
10
+ class DSLApp
11
+
12
+ Vedeu.bind(:_initialize_) { Vedeu.trigger(:_refresh_) }
13
+
14
+ Vedeu.configure do
15
+ debug!
16
+ log '/tmp/vedeu_integrations.log'
17
+ renderers [
18
+ Vedeu::Renderers::Terminal.new(
19
+ filename: Dir.tmpdir + "/#{TESTCASE}.out",
20
+ write_file: true)
21
+ ]
22
+ run_once!
23
+ standalone!
24
+
25
+ height 12
26
+ width 40
27
+ end
28
+
29
+ load File.dirname(__FILE__) + '/support/test_interface.rb'
30
+
31
+ Vedeu.interface :geometry_interface do
32
+ background '#ff3300'
33
+ border do
34
+ title 'Other'
35
+ colour foreground: '#ff0000'
36
+ end
37
+ geometry do
38
+ x 21
39
+ y 4
40
+ xn 31
41
+ yn 5
42
+ end
43
+ zindex 2
44
+ end
45
+
46
+ Vedeu.render do
47
+ view(:geometry_interface) do
48
+ lines do
49
+ 2.times do
50
+ line (" " * 10)
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ def self.start(argv = ARGV)
57
+ Vedeu::Launcher.execute!(argv)
58
+ end
59
+
60
+ end # DSLApp
61
+
62
+ Vedeu.timer('Test') do
63
+ DSLApp.start
64
+ end
65
+
66
+ load File.dirname(__FILE__) + '/test_runner.rb'
67
+ TestRunner.result(TESTCASE, __FILE__)
@@ -0,0 +1 @@
1
+ (0l(B(0q(B Test (0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0k(B(0x(B(0l(B(0q(B Other (0q(B(0k(B                  (0x(B(0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B                  (0x(B(0x(B                             (0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B
@@ -0,0 +1 @@
1
+ (0l(B(0q(B Test (0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0k(B(0x(B                  (0l(B(0q(B Other (0q(B(0k(B(0x(B(0x(B                  (0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B(0x(B(0x(B                             (0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B
@@ -0,0 +1 @@
1
+ (0l(B(0q(B Test (0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0k(B(0x(B                             (0x(B(0x(B(0l(B(0q(B Other (0q(B(0k(B                  (0x(B(0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B                  (0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B
@@ -0,0 +1 @@
1
+ (0l(B(0q(B Test (0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0k(B(0x(B                             (0x(B(0x(B                  (0l(B(0q(B Other (0q(B(0k(B(0x(B(0x(B                  (0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B(0x(B(0m(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0q(B(0j(B
@@ -48,5 +48,11 @@ cd "$(dirname "$0")"
48
48
  ./dsl_app_border_011.rb # only left
49
49
  ./dsl_app_border_012.rb # border on
50
50
 
51
+ # Test some geometry functionality
52
+ ./dsl_app_geometry_001.rb
53
+ ./dsl_app_geometry_002.rb
54
+ ./dsl_app_geometry_003.rb
55
+ ./dsl_app_geometry_004.rb
56
+
51
57
  # Failing
52
58
  # ./dsl_app_017.rb
@@ -38,7 +38,7 @@ module Vedeu
38
38
 
39
39
  # See {file:docs/events/by_name/refresh_view_content.md}
40
40
  Vedeu.bind(:_refresh_view_content_) do |name|
41
- Vedeu::Buffers::Refresh.refresh_content_by_name(name) if Vedeu.ready?
41
+ Vedeu::Buffers::RefreshContent.by_name(name) if Vedeu.ready?
42
42
  end
43
43
 
44
44
  # :nocov:
@@ -51,4 +51,5 @@ require 'vedeu/buffers/buffer'
51
51
  require 'vedeu/buffers/null'
52
52
  require 'vedeu/buffers/repository'
53
53
  require 'vedeu/buffers/refresh'
54
+ require 'vedeu/buffers/refresh_content'
54
55
  require 'vedeu/buffers/terminal'
@@ -16,40 +16,32 @@ module Vedeu
16
16
  # @param (see #initialize)
17
17
  # @return (see #by_name)
18
18
  def self.by_name(name = Vedeu.focus)
19
- name ||= Vedeu.focus
20
-
21
19
  new(name).by_name
22
20
  end
23
21
 
24
- # {include:file:docs/events/by_name/refresh_view_content.md}
25
- # @param (see #initialize)
26
- # @return (see #by_name)
27
- def self.refresh_content_by_name(name = Vedeu.focus)
28
- name ||= Vedeu.focus
29
-
30
- new(name, content_only: true).by_name
31
- end
32
-
33
22
  # Return a new instance of Vedeu::Buffers::Refresh.
34
23
  #
35
24
  # @macro param_name
36
- # @param options [Hash<Symbol => Boolean>]
37
- # @option options content_only [Boolean]
38
25
  # @return [Vedeu::Buffers::Refresh]
39
- def initialize(name, options = {})
40
- @name = name
41
- @options = options
26
+ def initialize(name = Vedeu.focus)
27
+ @name = name || Vedeu.focus
42
28
  end
43
29
 
44
30
  # @return [Array|Vedeu::Error::ModelNotFound]
45
31
  def by_name
46
- Vedeu.trigger(:_clear_view_content_, name)
32
+ Vedeu.clear_content_by_name(name)
47
33
 
48
34
  buffer.render
49
35
 
50
- Vedeu.trigger(:_refresh_border_, name) unless content_only?
36
+ Vedeu.trigger(:_refresh_border_, name)
51
37
  end
52
38
 
39
+ protected
40
+
41
+ # @!attribute [r] name
42
+ # @macro return_name
43
+ attr_reader :name
44
+
53
45
  private
54
46
 
55
47
  # @macro buffer_by_name
@@ -57,28 +49,6 @@ module Vedeu
57
49
  Vedeu.buffers.by_name(name)
58
50
  end
59
51
 
60
- # @return [Boolean]
61
- def content_only?
62
- truthy?(options[:content_only])
63
- end
64
-
65
- # @return [String|Symbol]
66
- def name
67
- present?(@name) ? @name : Vedeu.focus
68
- end
69
-
70
- # @return [Hash<Symbol => Boolean>]
71
- def options
72
- defaults.merge!(@options)
73
- end
74
-
75
- # @macro defaults_method
76
- def defaults
77
- {
78
- content_only: false,
79
- }
80
- end
81
-
82
52
  end # Refresh
83
53
 
84
54
  end # Buffers
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vedeu
4
+
5
+ module Buffers
6
+
7
+ # Refreshes only the content of the given named interface.
8
+ #
9
+ class RefreshContent
10
+
11
+ include Vedeu::Common
12
+
13
+ # {include:file:docs/events/by_name/refresh_view_content.md}
14
+ # @param (see #initialize)
15
+ # @return (see #by_name)
16
+ def self.by_name(name = Vedeu.focus)
17
+ new(name).by_name
18
+ end
19
+
20
+ # Return a new instance of Vedeu::Buffers::RefreshContent.
21
+ #
22
+ # @macro param_name
23
+ # @return [Vedeu::Buffers::RefreshContent]
24
+ def initialize(name = Vedeu.focus)
25
+ @name = name || Vedeu.focus
26
+ end
27
+
28
+ # @return [Array|Vedeu::Error::ModelNotFound]
29
+ def by_name
30
+ Vedeu.clear_content_by_name(name)
31
+
32
+ buffer.render
33
+ end
34
+
35
+ protected
36
+
37
+ # @!attribute [r] name
38
+ # @macro return_name
39
+ attr_reader :name
40
+
41
+ private
42
+
43
+ # @return [Vedeu::Buffers::Buffer]
44
+ def buffer
45
+ Vedeu.buffers.by_name(name)
46
+ end
47
+
48
+ end # RefreshContent
49
+
50
+ end # Buffers
51
+
52
+ end # Vedeu
@@ -42,7 +42,7 @@ module Vedeu
42
42
 
43
43
  reset!
44
44
 
45
- Vedeu.trigger(:_clear_view_content_, name)
45
+ Vedeu.clear_content_by_name(name) if Vedeu.ready?
46
46
 
47
47
  Vedeu.trigger(:_command_, command)
48
48
 
@@ -148,7 +148,7 @@ module Vedeu
148
148
  def refresh
149
149
  store
150
150
 
151
- Vedeu.trigger(:_clear_view_content_, name)
151
+ Vedeu.clear_content_by_name(name) if Vedeu.ready?
152
152
 
153
153
  Vedeu.buffer_update(output)
154
154
 
@@ -6,6 +6,8 @@ module Vedeu
6
6
 
7
7
  # Provides action related escape sequences.
8
8
  #
9
+ # @api public
10
+ #
9
11
  module Actions
10
12
 
11
13
  extend self
@@ -20,6 +20,8 @@ module Vedeu
20
20
  # Using the '\uXXXX' variant produces gaps in the border, whilst
21
21
  # the '\xXX' renders 'nicely'.
22
22
  #
23
+ # @api public
24
+ #
23
25
  module Borders
24
26
 
25
27
  extend self
@@ -6,6 +6,8 @@ module Vedeu
6
6
 
7
7
  # Provides colour related escape sequences.
8
8
  #
9
+ # @api private
10
+ #
9
11
  module Colours
10
12
 
11
13
  include Vedeu::Common
@@ -7,6 +7,8 @@ module Vedeu
7
7
  # Provides escape sequence strings for setting the cursor position
8
8
  # and various display related functions.
9
9
  #
10
+ # @api public
11
+ #
10
12
  module Esc
11
13
 
12
14
  include Vedeu::Common
@@ -28,6 +28,8 @@ module Vedeu
28
28
  #
29
29
  # - From CONSOLE_CODES(4) (`man console_codes`)
30
30
  #
31
+ # @api public
32
+ #
31
33
  module Mouse
32
34
 
33
35
  extend self
@@ -56,16 +56,17 @@ module Vedeu
56
56
  # @macro raise_missing_required
57
57
  # @return [String]
58
58
  def group_name
59
- return name if present?(name)
60
- return group_from_interface if present?(group_from_interface)
59
+ if present?(name)
60
+ name
61
61
 
62
- raise Vedeu::Error::MissingRequired,
63
- 'Cannot refresh group with an empty group name.'
64
- end
62
+ elsif present?(interface.group)
63
+ interface.group
64
+
65
+ else
66
+ raise Vedeu::Error::MissingRequired,
67
+ 'Cannot refresh group with an empty group name.'
65
68
 
66
- # @return [String|Symbol]
67
- def group_from_interface
68
- @_group_name ||= interface.group
69
+ end
69
70
  end
70
71
 
71
72
  # @macro interface_by_name
@@ -37,7 +37,7 @@ module Vedeu
37
37
 
38
38
  # @return [Array<Array<Vedeu::Cells::Char>>]
39
39
  def render
40
- Vedeu.render_output(output)
40
+ Vedeu.render_output(output) if Vedeu.ready?
41
41
  end
42
42
 
43
43
  protected
@@ -33,9 +33,11 @@ module Vedeu
33
33
 
34
34
  # @return [Vedeu::Buffers::View]
35
35
  def render
36
- Vedeu.direct_write(optimised_output)
36
+ if Vedeu.ready?
37
+ Vedeu.direct_write(optimised_output)
37
38
 
38
- Vedeu.buffer_update(output)
39
+ Vedeu.buffer_update(output)
40
+ end
39
41
  end
40
42
 
41
43
  protected
@@ -10,6 +10,7 @@ module Vedeu
10
10
 
11
11
  end # Vedeu
12
12
 
13
+ require 'vedeu/repositories/cache'
13
14
  require 'vedeu/repositories/storage'
14
15
  require 'vedeu/repositories/assemblage'
15
16
  require 'vedeu/repositories/collection'
@@ -0,0 +1,74 @@
1
+ module Vedeu
2
+
3
+ module Repositories
4
+
5
+ # @api private
6
+ #
7
+ class Cache
8
+
9
+ # @return [Vedeu::Repositories::Cache]
10
+ def initialize
11
+ @cache ||= {}
12
+ @lock = Mutex.new
13
+ end
14
+
15
+ # Add a new resource to the cache.
16
+ #
17
+ # @param resource [void]
18
+ # @param options [Hash]
19
+ # @option options value [void] The value to be cached.
20
+ # @option options expires [Fixnum] The number of seconds after
21
+ # which the resource will have expired.
22
+ # @return [void]
23
+ def add(resource, options = {})
24
+ value = options[:value]
25
+ expires = options.fetch(:expires, 600)
26
+
27
+ @lock.synchronize do
28
+ @cache[resource] = {
29
+ value: value,
30
+ expires_at: (Time.now + expires)
31
+ }
32
+ end
33
+ end
34
+
35
+ # Remove all cached resources.
36
+ #
37
+ # @return [Hash]
38
+ def clear
39
+ @cache = {}
40
+ end
41
+
42
+ # Read the cached resource if it exists.
43
+ #
44
+ # @param resource [void]
45
+ # @return [void]
46
+ def read(resource)
47
+ resource = @cache[resource]
48
+
49
+ return unless resource
50
+ return if resource[:expires_at] < Time.now
51
+
52
+ resource[:value]
53
+ end
54
+
55
+ # Remove the cached resource if it exists.
56
+ #
57
+ # @param resource [void]
58
+ # @return [Boolean]
59
+ def remove(resource)
60
+ if @cache.key?(resource)
61
+ @cache.delete(resource)
62
+ true
63
+
64
+ else
65
+ false
66
+
67
+ end
68
+ end
69
+
70
+ end # Cache
71
+
72
+ end # Repositories
73
+
74
+ end # Vedeu
@@ -3,6 +3,6 @@
3
3
  module Vedeu
4
4
 
5
5
  # The current version of Vedeu.
6
- VERSION = '0.8.25'
6
+ VERSION = '0.8.26'
7
7
 
8
8
  end # Vedeu
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ describe 'Bindings' do
8
+ it { Vedeu.bound?(:_refresh_view_).must_equal(true) }
9
+ it { Vedeu.bound?(:_refresh_view_content_).must_equal(true) }
10
+ end
11
+
12
+ end # Vedeu
@@ -0,0 +1,53 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+
5
+ module Vedeu
6
+
7
+ module Buffers
8
+
9
+ describe RefreshContent do
10
+
11
+ let(:described) { Vedeu::Buffers::RefreshContent }
12
+ let(:instance) { described.new(_name) }
13
+ let(:_name) { :vedeu_buffers_refresh }
14
+ let(:ready) { true }
15
+ let(:buffer) { mock('Vedeu::Buffers::Buffer', render: nil) }
16
+
17
+ before do
18
+ Vedeu.stubs(:clear_content_by_name).with(_name)
19
+ Vedeu.stubs(:trigger).with(:_refresh_border_, _name)
20
+ end
21
+
22
+ describe '#initialize' do
23
+ it { instance.must_be_instance_of(described) }
24
+ it { instance.instance_variable_get('@name').must_equal(_name) }
25
+ end
26
+
27
+ describe '.by_name' do
28
+ before do
29
+ Vedeu.buffers.stubs(:by_name).with(_name).returns(buffer)
30
+ end
31
+
32
+ subject { described.by_name(_name) }
33
+
34
+ it do
35
+ Vedeu.expects(:clear_content_by_name).with(_name)
36
+ subject
37
+ end
38
+
39
+ it do
40
+ Vedeu.buffers.expects(:by_name).with(_name).returns(buffer)
41
+ subject
42
+ end
43
+ end
44
+
45
+ describe '#by_name' do
46
+ it { instance.must_respond_to(:by_name) }
47
+ end
48
+
49
+ end # RefreshContent
50
+
51
+ end # Buffers
52
+
53
+ end # Vedeu
@@ -4,36 +4,24 @@ require 'test_helper'
4
4
 
5
5
  module Vedeu
6
6
 
7
- describe 'Bindings' do
8
- it { Vedeu.bound?(:_refresh_view_).must_equal(true) }
9
- it { Vedeu.bound?(:_refresh_view_content_).must_equal(true) }
10
- end
11
-
12
7
  module Buffers
13
8
 
14
9
  describe Refresh do
15
10
 
16
11
  let(:described) { Vedeu::Buffers::Refresh }
17
- let(:instance) { described.new(_name, options) }
12
+ let(:instance) { described.new(_name) }
18
13
  let(:_name) { :vedeu_buffers_refresh }
19
- let(:options) {
20
- {
21
- content_only: content_only,
22
- }
23
- }
24
- let(:content_only) { false }
25
- let(:ready) { true }
26
- let(:buffer) { mock('Vedeu::Buffers::Buffer', render: nil) }
14
+ let(:ready) { true }
15
+ let(:buffer) { mock('Vedeu::Buffers::Buffer', render: nil) }
27
16
 
28
17
  before do
29
- Vedeu.stubs(:trigger).with(:_clear_view_content_, _name)
18
+ Vedeu.stubs(:clear_content_by_name).with(_name)
30
19
  Vedeu.stubs(:trigger).with(:_refresh_border_, _name)
31
20
  end
32
21
 
33
22
  describe '#initialize' do
34
23
  it { instance.must_be_instance_of(described) }
35
24
  it { instance.instance_variable_get('@name').must_equal(_name) }
36
- it { instance.instance_variable_get('@options').must_equal(options) }
37
25
  end
38
26
 
39
27
  describe '.by_name' do
@@ -44,7 +32,7 @@ module Vedeu
44
32
  subject { described.by_name(_name) }
45
33
 
46
34
  it do
47
- Vedeu.expects(:trigger).with(:_clear_view_content_, _name)
35
+ Vedeu.expects(:clear_content_by_name).with(_name)
48
36
  subject
49
37
  end
50
38
 
@@ -59,26 +47,6 @@ module Vedeu
59
47
  end
60
48
  end
61
49
 
62
- describe '.refresh_content_by_name' do
63
- let(:content_only) { true }
64
-
65
- before do
66
- Vedeu.buffers.stubs(:by_name).with(_name).returns(buffer)
67
- end
68
-
69
- subject { described.refresh_content_by_name(_name) }
70
-
71
- it do
72
- Vedeu.expects(:trigger).with(:_clear_view_content_, _name)
73
- subject
74
- end
75
-
76
- it do
77
- Vedeu.buffers.expects(:by_name).with(_name).returns(buffer)
78
- subject
79
- end
80
- end
81
-
82
50
  describe '#by_name' do
83
51
  it { instance.must_respond_to(:by_name) }
84
52
  end
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Repositories
6
+
7
+ describe Cache do
8
+
9
+ let(:described) { Vedeu::Repositories::Cache }
10
+ let(:instance) { described.new }
11
+
12
+ describe '#initialize' do
13
+ it { instance.must_be_instance_of(described) }
14
+ end
15
+
16
+ describe '#add' do
17
+ let(:resource) {}
18
+ let(:options) { {} }
19
+
20
+ subject { instance.add(resource, options) }
21
+
22
+ it { instance.must_respond_to(:add) }
23
+ end
24
+
25
+ describe '#clear' do
26
+ subject { instance.clear }
27
+
28
+ it { instance.must_respond_to(:clear) }
29
+ end
30
+
31
+ describe '#read' do
32
+ let(:resource) {}
33
+
34
+ subject { instance.read(resource) }
35
+
36
+ it { instance.must_respond_to(:read) }
37
+ end
38
+
39
+ describe '#remove' do
40
+ let(:resource) {}
41
+
42
+ subject { instance.remove(resource) }
43
+
44
+ it { instance.must_respond_to(:remove) }
45
+ end
46
+
47
+ end # Cache
48
+
49
+ end # Repositories
50
+
51
+ end # Vedeu
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.25
4
+ version: 0.8.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -237,10 +237,15 @@ files:
237
237
  - bin/vedeu_test
238
238
  - config/rubocop_enabled.yml
239
239
  - docs/api.md
240
+ - docs/applications/existing_application.md
241
+ - docs/applications/first_application.md
242
+ - docs/applications/gem_application.md
243
+ - docs/applications/simple_application.md
240
244
  - docs/borders.md
241
245
  - docs/buffer.md
242
246
  - docs/cell.md
243
247
  - docs/chars.md
248
+ - docs/cli/commands.md
244
249
  - docs/colours_styles.md
245
250
  - docs/configuration.md
246
251
  - docs/configuration/background.md
@@ -573,6 +578,10 @@ files:
573
578
  - integrations/dsl_app_border_010.rb
574
579
  - integrations/dsl_app_border_011.rb
575
580
  - integrations/dsl_app_border_012.rb
581
+ - integrations/dsl_app_geometry_001.rb
582
+ - integrations/dsl_app_geometry_002.rb
583
+ - integrations/dsl_app_geometry_003.rb
584
+ - integrations/dsl_app_geometry_004.rb
576
585
  - integrations/expected/342_streams.out
577
586
  - integrations/expected/dsl_app_001.out
578
587
  - integrations/expected/dsl_app_002.out
@@ -607,6 +616,10 @@ files:
607
616
  - integrations/expected/dsl_app_border_010.out
608
617
  - integrations/expected/dsl_app_border_011.out
609
618
  - integrations/expected/dsl_app_border_012.out
619
+ - integrations/expected/dsl_app_geometry_001.out
620
+ - integrations/expected/dsl_app_geometry_002.out
621
+ - integrations/expected/dsl_app_geometry_003.out
622
+ - integrations/expected/dsl_app_geometry_004.out
610
623
  - integrations/support/test_interface.rb
611
624
  - integrations/support/test_interface_021.rb
612
625
  - integrations/support/test_interface_022.rb
@@ -634,6 +647,7 @@ files:
634
647
  - lib/vedeu/buffers/empty.rb
635
648
  - lib/vedeu/buffers/null.rb
636
649
  - lib/vedeu/buffers/refresh.rb
650
+ - lib/vedeu/buffers/refresh_content.rb
637
651
  - lib/vedeu/buffers/repository.rb
638
652
  - lib/vedeu/buffers/terminal.rb
639
653
  - lib/vedeu/buffers/view.rb
@@ -842,6 +856,7 @@ files:
842
856
  - lib/vedeu/renderers/text.rb
843
857
  - lib/vedeu/repositories/all.rb
844
858
  - lib/vedeu/repositories/assemblage.rb
859
+ - lib/vedeu/repositories/cache.rb
845
860
  - lib/vedeu/repositories/collection.rb
846
861
  - lib/vedeu/repositories/defaults.rb
847
862
  - lib/vedeu/repositories/model.rb
@@ -896,9 +911,11 @@ files:
896
911
  - test/lib/vedeu/borders/refresh_test.rb
897
912
  - test/lib/vedeu/borders/repository_test.rb
898
913
  - test/lib/vedeu/borders/title_test.rb
914
+ - test/lib/vedeu/buffers/all_test.rb
899
915
  - test/lib/vedeu/buffers/buffer_test.rb
900
916
  - test/lib/vedeu/buffers/empty_test.rb
901
917
  - test/lib/vedeu/buffers/null_test.rb
918
+ - test/lib/vedeu/buffers/refresh_content_test.rb
902
919
  - test/lib/vedeu/buffers/refresh_test.rb
903
920
  - test/lib/vedeu/buffers/repository_test.rb
904
921
  - test/lib/vedeu/buffers/terminal_test.rb
@@ -1068,6 +1085,7 @@ files:
1068
1085
  - test/lib/vedeu/renderers/terminal_test.rb
1069
1086
  - test/lib/vedeu/renderers/text_test.rb
1070
1087
  - test/lib/vedeu/repositories/assemblage_test.rb
1088
+ - test/lib/vedeu/repositories/cache_test.rb
1071
1089
  - test/lib/vedeu/repositories/collection_test.rb
1072
1090
  - test/lib/vedeu/repositories/defaults_test.rb
1073
1091
  - test/lib/vedeu/repositories/model_test.rb
@@ -1160,9 +1178,11 @@ test_files:
1160
1178
  - test/lib/vedeu/borders/refresh_test.rb
1161
1179
  - test/lib/vedeu/borders/repository_test.rb
1162
1180
  - test/lib/vedeu/borders/title_test.rb
1181
+ - test/lib/vedeu/buffers/all_test.rb
1163
1182
  - test/lib/vedeu/buffers/buffer_test.rb
1164
1183
  - test/lib/vedeu/buffers/empty_test.rb
1165
1184
  - test/lib/vedeu/buffers/null_test.rb
1185
+ - test/lib/vedeu/buffers/refresh_content_test.rb
1166
1186
  - test/lib/vedeu/buffers/refresh_test.rb
1167
1187
  - test/lib/vedeu/buffers/repository_test.rb
1168
1188
  - test/lib/vedeu/buffers/terminal_test.rb
@@ -1332,6 +1352,7 @@ test_files:
1332
1352
  - test/lib/vedeu/renderers/terminal_test.rb
1333
1353
  - test/lib/vedeu/renderers/text_test.rb
1334
1354
  - test/lib/vedeu/repositories/assemblage_test.rb
1355
+ - test/lib/vedeu/repositories/cache_test.rb
1335
1356
  - test/lib/vedeu/repositories/collection_test.rb
1336
1357
  - test/lib/vedeu/repositories/defaults_test.rb
1337
1358
  - test/lib/vedeu/repositories/model_test.rb