vedeu 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu/api.rb +3 -1
  3. data/lib/vedeu/application.rb +1 -1
  4. data/lib/vedeu/bindings.rb +68 -101
  5. data/lib/vedeu/cursor/cursor.rb +1 -1
  6. data/lib/vedeu/cursor/move_cursor.rb +77 -1
  7. data/lib/vedeu/cursor/toggle_cursor.rb +2 -0
  8. data/lib/vedeu/distributed/all.rb +7 -0
  9. data/lib/vedeu/distributed/client.rb +23 -11
  10. data/lib/vedeu/distributed/server.rb +8 -0
  11. data/lib/vedeu/distributed/subprocess.rb +0 -24
  12. data/lib/vedeu/distributed/uri.rb +1 -8
  13. data/lib/vedeu/dsl/all.rb +3 -0
  14. data/lib/vedeu/dsl/components/all.rb +4 -4
  15. data/lib/vedeu/dsl/components/geometry.rb +2 -0
  16. data/lib/vedeu/dsl/components/keymap.rb +14 -3
  17. data/lib/vedeu/dsl/group.rb +69 -0
  18. data/lib/vedeu/dsl/interface.rb +9 -8
  19. data/lib/vedeu/dsl/shared/text.rb +3 -1
  20. data/lib/vedeu/events/event.rb +2 -2
  21. data/lib/vedeu/input/keymap.rb +1 -1
  22. data/lib/vedeu/models/geometry.rb +1 -1
  23. data/lib/vedeu/models/group.rb +24 -10
  24. data/lib/vedeu/models/view/lines.rb +1 -0
  25. data/lib/vedeu/output/all.rb +6 -1
  26. data/lib/vedeu/output/border.rb +1 -1
  27. data/lib/vedeu/{support → output}/esc.rb +0 -0
  28. data/lib/vedeu/output/foreground.rb +1 -1
  29. data/lib/vedeu/output/html_char.rb +2 -0
  30. data/lib/vedeu/output/html_renderer.rb +6 -0
  31. data/lib/vedeu/output/output.rb +21 -0
  32. data/lib/vedeu/{support → output}/refresh.rb +1 -1
  33. data/lib/vedeu/output/renderer.rb +3 -0
  34. data/lib/vedeu/{support → output}/text.rb +0 -0
  35. data/lib/vedeu/output/virtual_terminal.rb +2 -0
  36. data/lib/vedeu/support/all.rb +0 -7
  37. data/lib/vedeu/support/coercions.rb +7 -4
  38. data/lib/vedeu/support/terminal.rb +1 -1
  39. data/lib/vedeu/support/trace.rb +1 -1
  40. data/lib/vedeu/support/visible.rb +1 -1
  41. data/test/lib/vedeu/cursor/move_cursor_test.rb +60 -1
  42. data/test/lib/vedeu/distributed/client_test.rb +21 -2
  43. data/test/lib/vedeu/dsl/group_test.rb +52 -0
  44. data/test/lib/vedeu/models/group_test.rb +11 -4
  45. data/test/lib/vedeu/{support → output}/esc_test.rb +0 -0
  46. data/test/lib/vedeu/{support → output}/refresh_test.rb +0 -0
  47. data/test/lib/vedeu/{support → output}/text_test.rb +0 -0
  48. data/test/test_helper.rb +2 -0
  49. data/vedeu.gemspec +2 -1
  50. metadata +28 -24
  51. data/lib/vedeu/output/writer.rb +0 -44
  52. data/lib/vedeu/support/console.rb +0 -90
  53. data/lib/vedeu/support/node.rb +0 -51
  54. data/lib/vedeu/support/read.rb +0 -66
  55. data/lib/vedeu/support/write.rb +0 -86
  56. data/test/lib/vedeu/output/writer_test.rb +0 -32
  57. data/test/lib/vedeu/support/console_test.rb +0 -138
  58. data/test/lib/vedeu/support/read_test.rb +0 -86
  59. data/test/lib/vedeu/support/write_test.rb +0 -158
@@ -5,4 +5,11 @@ require 'vedeu/distributed/subprocess'
5
5
  require 'vedeu/distributed/test_application'
6
6
 
7
7
  module Vedeu
8
+
9
+ # Provides a mechanism to control a running client application via DRb.
10
+ #
11
+ module Distributed
12
+
13
+ end # Distributed
14
+
8
15
  end # Vedeu
@@ -19,7 +19,7 @@ module Vedeu
19
19
  new(uri).connect
20
20
  end
21
21
 
22
- # @param uri [String]
22
+ # @param uri [Vedeu::Distributed::Uri|String]
23
23
  # @return [Client]
24
24
  def initialize(uri)
25
25
  @uri = uri.to_s
@@ -31,35 +31,37 @@ module Vedeu
31
31
  def connect
32
32
  server.status
33
33
 
34
+ rescue DRb::DRbConnError
35
+ drb_connection_error
36
+
34
37
  rescue DRb::DRbBadURI
35
- puts "Could not connect to DRb server, URI may be bad."
38
+ puts 'Could not connect to DRb server, URI may be bad.'
36
39
 
37
- rescue DRb::DRbConnError
38
- puts "Could not connect to DRb server."
40
+ :drb_bad_uri
39
41
 
40
42
  end
41
43
 
42
44
  # Send input to the DRb server.
43
45
  #
44
46
  # @param data [String|Symbol]
45
- # @return [void]
47
+ # @return [void|Symbol]
46
48
  def input(data)
47
49
  server.input(data)
48
50
 
49
51
  rescue DRb::DRbConnError
50
- puts "Could not connect to DRb server."
52
+ drb_connection_error
51
53
 
52
54
  end
53
55
  alias_method :read, :input
54
56
 
55
57
  # Fetch output from the DRb server.
56
58
  #
57
- # @return [void]
59
+ # @return [void|Symbol]
58
60
  def output
59
61
  server.output
60
62
 
61
63
  rescue DRb::DRbConnError
62
- puts "Could not connect to DRb server."
64
+ drb_connection_error
63
65
 
64
66
  end
65
67
  alias_method :write, :output
@@ -70,17 +72,20 @@ module Vedeu
70
72
  # {Vedeu::Application} will raise StopIteration when its `.stop` method
71
73
  # is called. Here we rescue that to give a clean client exit.
72
74
  #
73
- # @return [void]
75
+ # @return [void|Symbol]
74
76
  def shutdown
75
77
  server.shutdown
76
78
 
77
79
  Process.kill("KILL", server.pid)
78
80
 
79
81
  rescue DRb::DRbConnError
80
- puts "Could not connect to DRb server."
82
+ drb_connection_error
81
83
 
82
84
  rescue Interrupt
83
- puts "Client application exited."
85
+ puts 'Client application exited.'
86
+
87
+ ensure
88
+ :shutdown
84
89
 
85
90
  end
86
91
 
@@ -93,6 +98,13 @@ module Vedeu
93
98
  @server ||= DRbObject.new_with_uri(uri)
94
99
  end
95
100
 
101
+ # @return [Symbol]
102
+ def drb_connection_error
103
+ puts 'Could not connect to DRb server.'
104
+
105
+ :drb_connection_error
106
+ end
107
+
96
108
  end # Client
97
109
 
98
110
  end # Distributed
@@ -69,6 +69,8 @@ module Vedeu
69
69
 
70
70
  # @return [void]
71
71
  def restart
72
+ Vedeu.log(type: :drb, message: 'Attempting to restart')
73
+
72
74
  return not_enabled unless drb?
73
75
 
74
76
  log('Not running') unless drb_running?
@@ -100,6 +102,8 @@ module Vedeu
100
102
 
101
103
  # @return [Vedeu::Distributed::Server]
102
104
  def start
105
+ Vedeu.log(type: :drb, message: 'Attempting to start')
106
+
103
107
  return not_enabled unless drb?
104
108
 
105
109
  if drb_running?
@@ -116,6 +120,8 @@ module Vedeu
116
120
 
117
121
  # @return [Symbol]
118
122
  def status
123
+ Vedeu.log(type: :drb, message: 'Fetching status')
124
+
119
125
  return not_enabled unless drb?
120
126
 
121
127
  if drb_running?
@@ -133,6 +139,8 @@ module Vedeu
133
139
 
134
140
  # @return [void]
135
141
  def stop
142
+ Vedeu.log(type: :drb, message: 'Attempting to stop')
143
+
136
144
  return not_enabled unless drb?
137
145
 
138
146
  if drb_running?
@@ -1,29 +1,5 @@
1
- require 'pty'
2
1
  require 'vedeu/distributed/test_application'
3
2
 
4
- # app_config = Vedeu::TestApplication.build
5
- # timestamp = Time.now.to_i
6
- # file = File.new("/tmp/foo_#{timestamp}", "w")
7
- # file.write(app_config)
8
- # file.close
9
-
10
- # cmd = "ruby #{file.path}"
11
- # begin
12
- # PTY.spawn(cmd) do |stdin, stdout, pid|
13
- # begin
14
- # # Do stuff with the output here. Just printing to show it works
15
- # stdin.each { |line| print line }
16
- # rescue Errno::EIO
17
- # puts "Errno:EIO error, but this probably just means " +
18
- # "that the process has finished giving output"
19
- # end
20
- # end
21
- # rescue PTY::ChildExited
22
- # puts "The child process exited!"
23
- # ensure
24
- # File.unlink("/tmp/foo_#{timestamp}")
25
- # end
26
-
27
3
  module Vedeu
28
4
 
29
5
  # @example
@@ -22,14 +22,7 @@ module Vedeu
22
22
  #
23
23
  # @return [String] The host and port as a single value.
24
24
  def to_s
25
- [scheme, host, ':', port].join
26
- end
27
-
28
- private
29
-
30
- # @return [String]
31
- def scheme
32
- 'druby://'
25
+ ['druby://', host, ':', port].join
33
26
  end
34
27
 
35
28
  end # Uri
data/lib/vedeu/dsl/all.rb CHANGED
@@ -2,6 +2,7 @@ require 'vedeu/dsl/components/all'
2
2
  require 'vedeu/dsl/shared/all'
3
3
 
4
4
  require 'vedeu/dsl/composition'
5
+ require 'vedeu/dsl/group'
5
6
  require 'vedeu/dsl/interface'
6
7
  require 'vedeu/dsl/line'
7
8
  require 'vedeu/dsl/stream'
@@ -13,6 +14,8 @@ module Vedeu
13
14
  #
14
15
  module DSL
15
16
 
17
+ private
18
+
16
19
  # Attempts to find the missing method on the client object.
17
20
  #
18
21
  # @param method [Symbol] The name of the method sought.
@@ -1,7 +1,7 @@
1
- require 'vedeu/dsl/components/border'
2
- require 'vedeu/dsl/components/geometry'
3
- require 'vedeu/dsl/components/keymap'
4
- require 'vedeu/dsl/components/menu'
1
+ require_relative 'border'
2
+ require_relative 'geometry'
3
+ require_relative 'keymap'
4
+ require_relative 'menu'
5
5
 
6
6
  module Vedeu
7
7
  end # Vedeu
@@ -32,6 +32,8 @@ module Vedeu
32
32
  # Returns an instance of DSL::Geometry.
33
33
  #
34
34
  # @param model [Geometry]
35
+ # @param client [Object]
36
+ # @return [Vedeu::DSL::Geometry]
35
37
  def initialize(model, client = nil)
36
38
  @model = model
37
39
  @client = client
@@ -25,15 +25,26 @@ module Vedeu
25
25
  #
26
26
  # Vedeu.interface 'my_interface' do
27
27
  # keymap do
28
- # ...
28
+ # # ...
29
29
  #
30
30
  # @param name [String] The name of the interface which this keymap relates
31
31
  # to.
32
32
  # @param block [Proc]
33
33
  #
34
34
  # @example
35
- # keymap 'my_interface' do
36
- # ...
35
+ # Vedeu.keymap 'my_interface' do
36
+ # # ...
37
+ #
38
+ # Vedeu.keys 'my_interface' do
39
+ # # ...
40
+ #
41
+ # Vedeu.interface 'my_interface' do
42
+ # keymap do
43
+ # # ...
44
+ #
45
+ # Vedeu.interface 'my_interface' do
46
+ # keys do
47
+ # # ...
37
48
  #
38
49
  # @raise [InvalidSyntax] The required block was not given.
39
50
  # @return [Keymap]
@@ -0,0 +1,69 @@
1
+ require 'vedeu/models/group'
2
+
3
+ module Vedeu
4
+
5
+ module DSL
6
+
7
+ # DSL for adding interfaces to a group.
8
+ #
9
+ class Group
10
+
11
+ include Vedeu::DSL
12
+
13
+ # Specify a new group of interfaces with a simple DSL.
14
+ #
15
+ # The example below resembles 'vim' (the popular terminal-based text
16
+ # editor):
17
+ #
18
+ # @example
19
+ # Vedeu.group 'title_screen' do
20
+ # add 'welcome_interface'
21
+ # # ...
22
+ #
23
+ # Vedeu.group 'main_screen' do
24
+ # add 'editor_interface'
25
+ # add 'status_interface'
26
+ # add 'command_interface'
27
+ # # ...
28
+ #
29
+ # @note
30
+ # Creating a group with the same name as an existing group overwrites
31
+ # the existing group.
32
+ #
33
+ # @param name [String] The name of this group.
34
+ # @param block [Proc]
35
+ # @raise [InvalidSyntax] The required block was not given.
36
+ # @return [Vedeu::Group]
37
+ def self.group(name, &block)
38
+ fail InvalidSyntax, 'block not given' unless block_given?
39
+
40
+ Vedeu::Group.build({ name: name }, &block).store
41
+ end
42
+
43
+ # Returns an instance of DSL::Group.
44
+ #
45
+ # @param model [Group]
46
+ # @param client [Object]
47
+ # @return [Vedeu::DSL::Group]
48
+ def initialize(model, client = nil)
49
+ @model = model
50
+ @client = client
51
+ end
52
+
53
+ # Add the named interface to this group.
54
+ #
55
+ # @param interface_name [String]
56
+ # @return [void]
57
+ def add(interface_name)
58
+ model.add(interface_name)
59
+ end
60
+
61
+ private
62
+
63
+ attr_reader :client, :model
64
+
65
+ end # Group
66
+
67
+ end # DSL
68
+
69
+ end # Vedeu
@@ -135,28 +135,29 @@ module Vedeu
135
135
  # targetted together; for example you may want to refresh multiple
136
136
  # interfaces at once.
137
137
  #
138
- # @param value [String] The name for the group of interfaces.
139
- #
140
138
  # @example
141
139
  # interface 'my_interface' do
142
140
  # group 'main_screen'
143
141
  # # ...
144
142
  #
143
+ # @param name [String] The name of the group to which this interface
144
+ # should belong.
145
145
  # @return [String]
146
- def group(value)
147
- return false unless defined_value?(value)
146
+ def group(name)
147
+ return false unless defined_value?(name)
148
148
 
149
149
  if defined_value?(model.name)
150
- if Vedeu.groups.registered?(value)
151
- Vedeu.groups.find(value).add(model.name)
150
+ if Vedeu.groups.registered?(name)
151
+ Vedeu.groups.find(name).add(model.name)
152
152
 
153
153
  else
154
- Vedeu::Group.new(value, model.name).store
154
+ new_group = Vedeu::Group.new({ name: name })
155
+ new_group.add(model.name)
155
156
 
156
157
  end
157
158
  end
158
159
 
159
- model.group = value
160
+ model.group = name
160
161
  end
161
162
 
162
163
  # @see Vedeu::DSL::Keymap.keymap
@@ -1,4 +1,6 @@
1
- require 'vedeu/support/text'
1
+ require 'vedeu/output/text'
2
+ require 'vedeu/models/view/line'
3
+ require 'vedeu/models/view/stream'
2
4
 
3
5
  module Vedeu
4
6
 
@@ -41,8 +41,8 @@ module Vedeu
41
41
  # Register an event by name with optional delay (throttling) which when
42
42
  # triggered will execute the code contained within the passed block.
43
43
  #
44
- # @param name [Symbol] The name of the event which will be triggered later.
45
- # @param [Hash] options The options to register the event with.
44
+ # @param name [Symbol] The name of the event which will be triggered later.
45
+ # @param options [Hash] The options to register the event with.
46
46
  # @option options :delay [Fixnum|Float] Limits the execution of the
47
47
  # triggered event to only execute when first triggered, with subsequent
48
48
  # triggering being ignored until the delay has expired.
@@ -1,6 +1,6 @@
1
1
  require 'vedeu/exceptions'
2
2
  require 'vedeu/models/model'
3
- require 'vedeu/dsl/components/keymap'
3
+ require 'vedeu/dsl/components/all'
4
4
 
5
5
  module Vedeu
6
6
 
@@ -1,4 +1,4 @@
1
- require 'vedeu/dsl/components/geometry'
1
+ require 'vedeu/dsl/components/all'
2
2
  require 'vedeu/models/model'
3
3
 
4
4
  require 'vedeu/geometry/limit'
@@ -7,17 +7,23 @@ module Vedeu
7
7
 
8
8
  include Vedeu::Model
9
9
 
10
- attr_reader :name
10
+ attr_accessor :name
11
11
 
12
12
  # Return a new instance of Group.
13
13
  #
14
- # @param name [String] The name of the group.
15
- # @param members [Array]
14
+ # @param attributes [Hash]
15
+ # @option attributes members [Array] A collection of names of interfaces
16
+ # belonging to this group.
17
+ # @option attributes name [String] The name of the group.
18
+ # @option attributes repository [Vedeu::Repository] The storage for all
19
+ # Group models.
16
20
  # @return [Group]
17
- def initialize(name, members = [])
18
- @name = name
19
- @members = Array(members)
20
- @repository = Vedeu.groups
21
+ def initialize(attributes = {})
22
+ @attributes = defaults.merge!(attributes)
23
+
24
+ @members = Array(@attributes[:members])
25
+ @name = @attributes[:name]
26
+ @repository = @attributes[:repository]
21
27
  end
22
28
 
23
29
  # Add a member to the group by name.
@@ -25,7 +31,7 @@ module Vedeu
25
31
  # @param member [String]
26
32
  # @return [Group]
27
33
  def add(member)
28
- Group.new(name, members.add(member)).store
34
+ Group.new({ name: name, members: members.add(member) }).store
29
35
  end
30
36
 
31
37
  # Return the members as a Set.
@@ -40,18 +46,26 @@ module Vedeu
40
46
  # @param member [String]
41
47
  # @return [Group]
42
48
  def remove(member)
43
- Group.new(name, members.delete(member)).store
49
+ Group.new({ name: name, members: members.delete(member) }).store
44
50
  end
45
51
 
46
52
  # Remove all members from the group.
47
53
  #
48
54
  # @return [Group]
49
55
  def reset
50
- Group.new(name).store
56
+ Group.new(defaults.merge!({ name: name })).store
51
57
  end
52
58
 
53
59
  private
54
60
 
61
+ def defaults
62
+ {
63
+ members: [],
64
+ name: '',
65
+ repository: Vedeu.groups,
66
+ }
67
+ end
68
+
55
69
  end # Group
56
70
 
57
71
  end # Vedeu