vedeu 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/bin/vedeu_drb_client +6 -0
  3. data/lib/vedeu/all.rb +1 -0
  4. data/lib/vedeu/application.rb +24 -1
  5. data/lib/vedeu/configuration/api.rb +107 -0
  6. data/lib/vedeu/configuration/cli.rb +34 -0
  7. data/lib/vedeu/configuration/configuration.rb +75 -4
  8. data/lib/vedeu/distributed/all.rb +8 -0
  9. data/lib/vedeu/distributed/application.rb +91 -0
  10. data/lib/vedeu/distributed/client.rb +58 -0
  11. data/lib/vedeu/distributed/subprocess.rb +111 -0
  12. data/lib/vedeu/distributed/templates/default_application.vedeu +34 -0
  13. data/lib/vedeu/distributed/templates/default_borders.vedeu +19 -0
  14. data/lib/vedeu/distributed/templates/default_configuration.vedeu +31 -0
  15. data/lib/vedeu/distributed/templates/default_events.vedeu +1 -0
  16. data/lib/vedeu/distributed/templates/default_geometries.vedeu +7 -0
  17. data/lib/vedeu/distributed/templates/default_interfaces.vedeu +4 -0
  18. data/lib/vedeu/distributed/templates/default_keymaps.vedeu +6 -0
  19. data/lib/vedeu/distributed/templates/default_menus.vedeu +3 -0
  20. data/lib/vedeu/distributed/templates/default_views.vedeu +14 -0
  21. data/lib/vedeu/distributed/test_application.rb +99 -0
  22. data/lib/vedeu/distributed/uri.rb +38 -0
  23. data/lib/vedeu/input/mapper.rb +10 -0
  24. data/lib/vedeu/launcher.rb +4 -0
  25. data/lib/vedeu/models/geometry.rb +16 -31
  26. data/lib/vedeu/models/view/char.rb +5 -5
  27. data/lib/vedeu/models/view/interface.rb +2 -1
  28. data/lib/vedeu/output/all.rb +2 -0
  29. data/lib/vedeu/output/output.rb +40 -0
  30. data/lib/vedeu/output/position_index.rb +24 -0
  31. data/lib/vedeu/output/virtual_terminal.rb +87 -0
  32. data/lib/vedeu/support/all.rb +1 -0
  33. data/lib/vedeu/support/limit.rb +33 -0
  34. data/lib/vedeu/support/position.rb +29 -0
  35. data/lib/vedeu/support/terminal.rb +14 -2
  36. data/test/integration/distributed_test.rb +14 -0
  37. data/test/lib/vedeu/application_test.rb +7 -6
  38. data/test/lib/vedeu/buffers/buffer_test.rb +6 -8
  39. data/test/lib/vedeu/configuration/api_test.rb +50 -0
  40. data/test/lib/vedeu/configuration/cli_test.rb +21 -0
  41. data/test/lib/vedeu/configuration/configuration_test.rb +24 -0
  42. data/test/lib/vedeu/cursor/move_cursor_test.rb +5 -7
  43. data/test/lib/vedeu/distributed/application_test.rb +24 -0
  44. data/test/lib/vedeu/distributed/client_test.rb +36 -0
  45. data/test/lib/vedeu/distributed/subprocess_test.rb +20 -0
  46. data/test/lib/vedeu/distributed/test_application_test.rb +26 -0
  47. data/test/lib/vedeu/distributed/uri_test.rb +73 -0
  48. data/test/lib/vedeu/dsl/components/border_test.rb +3 -5
  49. data/test/lib/vedeu/dsl/components/keymap_test.rb +2 -4
  50. data/test/lib/vedeu/dsl/components/menu_test.rb +2 -4
  51. data/test/lib/vedeu/dsl/composition_test.rb +3 -5
  52. data/test/lib/vedeu/dsl/interface_test.rb +3 -5
  53. data/test/lib/vedeu/dsl/line_test.rb +3 -5
  54. data/test/lib/vedeu/dsl/stream_test.rb +3 -5
  55. data/test/lib/vedeu/events/event_test.rb +8 -10
  56. data/test/lib/vedeu/events/trigger_test.rb +4 -6
  57. data/test/lib/vedeu/input/input_test.rb +2 -4
  58. data/test/lib/vedeu/input/key_test.rb +0 -2
  59. data/test/lib/vedeu/input/keymap_test.rb +4 -6
  60. data/test/lib/vedeu/input/mapper_test.rb +5 -7
  61. data/test/lib/vedeu/launcher_test.rb +7 -9
  62. data/test/lib/vedeu/models/collection_test.rb +4 -6
  63. data/test/lib/vedeu/models/geometry_test.rb +40 -13
  64. data/test/lib/vedeu/models/group_test.rb +4 -6
  65. data/test/lib/vedeu/models/menu_test.rb +6 -9
  66. data/test/lib/vedeu/models/view/char_test.rb +7 -9
  67. data/test/lib/vedeu/models/view/chars_test.rb +1 -3
  68. data/test/lib/vedeu/models/view/composition_test.rb +4 -6
  69. data/test/lib/vedeu/models/view/interface_test.rb +10 -12
  70. data/test/lib/vedeu/models/view/interfaces_test.rb +1 -3
  71. data/test/lib/vedeu/models/view/line_test.rb +5 -7
  72. data/test/lib/vedeu/models/view/lines_test.rb +1 -3
  73. data/test/lib/vedeu/models/view/stream_test.rb +6 -8
  74. data/test/lib/vedeu/models/view/streams_test.rb +1 -3
  75. data/test/lib/vedeu/output/border_test.rb +6 -8
  76. data/test/lib/vedeu/output/compositor_test.rb +2 -4
  77. data/test/lib/vedeu/output/output_test.rb +5 -4
  78. data/test/lib/vedeu/output/position_index_test.rb +72 -0
  79. data/test/lib/vedeu/output/viewport_test.rb +2 -4
  80. data/test/lib/vedeu/output/virtual_terminal_test.rb +120 -0
  81. data/test/lib/vedeu/output/wordwrap_test.rb +3 -5
  82. data/test/lib/vedeu/presentation/colour_test.rb +0 -2
  83. data/test/lib/vedeu/presentation/style_test.rb +2 -4
  84. data/test/lib/vedeu/presentation/translator_test.rb +2 -4
  85. data/test/lib/vedeu/repositories/repository_test.rb +3 -5
  86. data/test/lib/vedeu/support/console_test.rb +5 -7
  87. data/test/lib/vedeu/support/content_geometry_test.rb +2 -4
  88. data/test/lib/vedeu/support/coordinate_test.rb +5 -7
  89. data/test/lib/vedeu/support/grid_test.rb +2 -4
  90. data/test/lib/vedeu/support/limit_test.rb +30 -0
  91. data/test/lib/vedeu/support/position_test.rb +8 -4
  92. data/test/lib/vedeu/support/position_validator_test.rb +4 -6
  93. data/test/lib/vedeu/support/read_test.rb +3 -5
  94. data/test/lib/vedeu/support/sentence_test.rb +3 -4
  95. data/test/lib/vedeu/support/trace_test.rb +2 -4
  96. data/test/lib/vedeu/support/visible_test.rb +6 -8
  97. data/test/lib/vedeu/support/write_test.rb +3 -5
  98. data/test/test_helper.rb +6 -2
  99. data/vedeu.gemspec +1 -1
  100. metadata +40 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 54bb0cd0826751a7fb718c0bd4a68aed54a12d1e
4
- data.tar.gz: 06d71adf59c0300bd27812b07593bcfdfb71114a
3
+ metadata.gz: fccb60d2e33924a76f711a5ffccd643c7436a4fe
4
+ data.tar.gz: 03c59bf2a8d7c6265aa164807f9b72af46c7d055
5
5
  SHA512:
6
- metadata.gz: 072569691f768aee22091160266ea4cb944865ecb186eb62eec47617f39a28d30d5629ff72b2c69919f82dbc3c41bb562dbef2afa00daaf91d466db358465a4b
7
- data.tar.gz: 42074a95c54fedb6143ad082188185ca2e5bd6d60d0f092cb9e2d16bf9bfba2b49b40c0e1a7a23b0e218473415128cfe5d2d17bb7923fa3be8e9d5449542be2f
6
+ metadata.gz: 48627364195755fcd4390963bf27188ca813d62b2e1cf14d4c20b824ea087e36669942fbeedcf40df8857171a468e71505af437a0bfb93b0656c9a761a170532
7
+ data.tar.gz: 52c5edb46c2a7e72e11084670829ae1e913a3fb4f96245463a682b6047f9cc45be5a597142a96327e1698a42f75357d6115fbdd7062acf9cadbc8fb16d6646b7
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ client = Vedeu::Distributed::Client.new("druby://localhost:21420")
4
+ client.input('a')
5
+ client.output # => 'some content...'
6
+ client.stop
data/lib/vedeu/all.rb CHANGED
@@ -14,6 +14,7 @@ require 'vedeu/bindings'
14
14
  require 'vedeu/buffers/all'
15
15
  require 'vedeu/configuration/all'
16
16
  require 'vedeu/cursor/all'
17
+ require 'vedeu/distributed/all'
17
18
 
18
19
  require 'vedeu/dsl/shared/all'
19
20
  require 'vedeu/dsl/all'
@@ -49,13 +49,19 @@ module Vedeu
49
49
  #
50
50
  # @return [Array] The last output sent to the terminal.
51
51
  def start
52
- Terminal.open do
52
+ distributed_start
53
+
54
+ output = Terminal.open do
53
55
  Terminal.set_cursor_mode
54
56
 
55
57
  Vedeu.trigger(:_initialize_)
56
58
 
57
59
  runner { main_sequence }
58
60
  end
61
+
62
+ distributed_stop
63
+
64
+ output
59
65
  end
60
66
 
61
67
  private
@@ -109,10 +115,27 @@ module Vedeu
109
115
  rescue ModeSwitch
110
116
  Terminal.switch_mode!
111
117
 
118
+ distributed_stop
119
+
112
120
  Application.restart
113
121
 
114
122
  end
115
123
 
124
+ # @return []
125
+ def distributed_start
126
+ distributed.start if configuration.drb?
127
+ end
128
+
129
+ # @return []
130
+ def distributed_stop
131
+ distributed.stop if configuration.drb?
132
+ end
133
+
134
+ # @return [Vedeu::Distributed::Application]
135
+ def distributed
136
+ @distributed ||= Vedeu::Distributed::Application.new(configuration)
137
+ end
138
+
116
139
  # :nocov:
117
140
 
118
141
  end # Application
@@ -105,6 +105,74 @@ module Vedeu
105
105
  end
106
106
  alias_method :run_once, :run_once!
107
107
 
108
+ # Sets boolean to run a DRb server.
109
+ #
110
+ # @example
111
+ # Vedeu.configure do
112
+ # drb!
113
+ # ...
114
+ #
115
+ # @param value [Boolean]
116
+ # @return [Boolean]
117
+ def drb!(value = true)
118
+ Vedeu.log("Configuration::API drb: #{value}")
119
+
120
+ options[:drb] = value
121
+ end
122
+ alias_method :drb, :drb!
123
+
124
+ # Sets the hostname or IP address of the DRb server.
125
+ #
126
+ # @example
127
+ # Vedeu.configure do
128
+ # drb_host 'localhost'
129
+ # ...
130
+ #
131
+ # @param hostname [String]
132
+ # @return [String]
133
+ def drb_host(hostname = '')
134
+ options[:drb_host] = hostname
135
+ end
136
+
137
+ # Sets the port of the DRb server.
138
+ #
139
+ # @example
140
+ # Vedeu.configure do
141
+ # drb_port 12345
142
+ # ...
143
+ #
144
+ # @param port [Fixnum|String]
145
+ # @return [String]
146
+ def drb_port(port = '')
147
+ options[:drb_port] = port
148
+ end
149
+
150
+ # Sets the height of the fake terminal in the DRb server.
151
+ #
152
+ # @example
153
+ # Vedeu.configure do
154
+ # drb_height 25
155
+ # ...
156
+ #
157
+ # @param height [Fixnum]
158
+ # @return [Fixnum]
159
+ def drb_height(height = 25)
160
+ options[:drb_height] = height
161
+ end
162
+
163
+ # Sets the width of the fake terminal in the DRb server.
164
+ #
165
+ # @example
166
+ # Vedeu.configure do
167
+ # drb_width 80
168
+ # ...
169
+ #
170
+ # @param width [Fixnum]
171
+ # @return [Fixnum]
172
+ def drb_width(width = 80)
173
+ options[:drb_width] = width
174
+ end
175
+
108
176
  # Sets the terminal mode to `cooked`. Default terminal mode is `raw`.
109
177
  #
110
178
  # @example
@@ -223,6 +291,45 @@ module Vedeu
223
291
  options[:log] = filename
224
292
  end
225
293
 
294
+ # Sets the value of STDIN.
295
+ #
296
+ # @example
297
+ # Vedeu.configure do
298
+ # stdin IO.console
299
+ # ...
300
+ #
301
+ # @param io [File|IO]
302
+ # @return [File|IO]
303
+ def stdin(io)
304
+ options[:stdin] = io
305
+ end
306
+
307
+ # Sets the value of STDOUT.
308
+ #
309
+ # @example
310
+ # Vedeu.configure do
311
+ # stdout IO.console
312
+ # ...
313
+ #
314
+ # @param io [File|IO]
315
+ # @return [File|IO]
316
+ def stdout(io)
317
+ options[:stdout] = io
318
+ end
319
+
320
+ # Sets the value of STDERR.
321
+ #
322
+ # @example
323
+ # Vedeu.configure do
324
+ # stderr IO.console
325
+ # ...
326
+ #
327
+ # @param io [File|IO]
328
+ # @return [File|IO]
329
+ def stderr(io)
330
+ options[:stderr] = io
331
+ end
332
+
226
333
  # Sets the key used to exit the client application. The default is `q`.
227
334
  #
228
335
  # @example
@@ -114,6 +114,40 @@ module Vedeu
114
114
 
115
115
  options[:log] = filename
116
116
  end
117
+
118
+ opts.on('--drb', 'Run application with DRb on.') do
119
+ Vedeu.log("Configuration::CLI drb: true")
120
+
121
+ options[:drb] = true
122
+ end
123
+
124
+ opts.on('--drb-host', 'Set the hostname/IP for the DRb server.') do |hostname|
125
+ Vedeu.log("Configuration::CLI drb_host: #{hostname}")
126
+
127
+ #options[:drb] = true
128
+ options[:drb_host] = hostname
129
+ end
130
+
131
+ opts.on('--drb-port', 'Set the port for the DRb server.') do |port|
132
+ Vedeu.log("Configuration::CLI drb_port: #{port}")
133
+
134
+ #options[:drb] = true
135
+ options[:drb_port] = port
136
+ end
137
+
138
+ opts.on('--drb-height', 'Set the height for fake terminal of the DRb server.') do |height|
139
+ Vedeu.log("Configuration::CLI drb_height: #{height}")
140
+
141
+ #options[:drb] = true
142
+ options[:drb_height] = height
143
+ end
144
+
145
+ opts.on('--drb-width', 'Set the width for fake terminal of the DRb server.') do |width|
146
+ Vedeu.log("Configuration::CLI drb_width: #{width}")
147
+
148
+ #options[:drb] = true
149
+ options[:drb_width] = width
150
+ end
117
151
  end
118
152
 
119
153
  parser.parse!(args)
@@ -30,11 +30,15 @@ module Vedeu
30
30
  # arguments provided.
31
31
  #
32
32
  # @param args [Array]
33
+ # @param opts [Hash]
34
+ # @option opts stdin [File|IO]
35
+ # @option opts stdout [File|IO]
36
+ # @option opts stderr [File|IO]
33
37
  # @param block [Proc]
34
38
  # @raise [InvalidSyntax] When the required block is not given.
35
39
  # @return [Hash]
36
- def configure(args = [], &block)
37
- instance.configure(args, &block)
40
+ def configure(args = [], opts = {}, &block)
41
+ instance.configure(args, opts, &block)
38
42
  end
39
43
 
40
44
  # Returns the configuration singleton.
@@ -60,6 +64,42 @@ module Vedeu
60
64
  end
61
65
  alias_method :debug, :debug?
62
66
 
67
+ # Returns whether the DRb server is enabled or disabled. Default is false.
68
+ #
69
+ # @return [Boolean]
70
+ def drb?
71
+ instance.options[:drb]
72
+ end
73
+ alias_method :drb, :drb?
74
+
75
+ # Returns the hostname for the DRb server.
76
+ #
77
+ # @return [String]
78
+ def drb_host
79
+ instance.options[:drb_host]
80
+ end
81
+
82
+ # Returns the port for the DRb server.
83
+ #
84
+ # @return [String]
85
+ def drb_port
86
+ instance.options[:drb_port]
87
+ end
88
+
89
+ # Returns the height for the fake terminal in the DRb server.
90
+ #
91
+ # @return [Fixnum]
92
+ def drb_height
93
+ instance.options[:drb_height]
94
+ end
95
+
96
+ # Returns the width for the fake terminal in the DRb server.
97
+ #
98
+ # @return [Fixnum]
99
+ def drb_width
100
+ instance.options[:drb_width]
101
+ end
102
+
63
103
  # Returns whether the application is interactive (required user input) or
64
104
  # standalone (will run until terminates of natural causes.) Default is
65
105
  # true; meaning the application will require user input.
@@ -87,7 +127,28 @@ module Vedeu
87
127
  end
88
128
  alias_method :once, :once?
89
129
 
90
- # Returns
130
+ # Returns the redefined setting for STDIN.
131
+ #
132
+ # @return [File|IO]
133
+ def stdin
134
+ instance.options[:stdin]
135
+ end
136
+
137
+ # Returns the redefined setting for STDOUT.
138
+ #
139
+ # @return [File|IO]
140
+ def stdout
141
+ instance.options[:stdout]
142
+ end
143
+
144
+ # Returns the redefined setting for STDERR.
145
+ #
146
+ # @return [File|IO]
147
+ def stderr
148
+ instance.options[:stderr]
149
+ end
150
+
151
+ # Returns the redefined system keys for vital Vedeu functions.
91
152
  #
92
153
  # @return [Hash]
93
154
  def system_keys
@@ -156,7 +217,9 @@ module Vedeu
156
217
  # @param args [Array]
157
218
  # @param block [Proc]
158
219
  # @return [Hash]
159
- def configure(args = [], &block)
220
+ def configure(args = [], opts = {}, &block)
221
+ @options.merge!(opts)
222
+
160
223
  @options.merge!(Config::API.configure(&block)) if block_given?
161
224
 
162
225
  @options.merge!(Config::CLI.configure(args)) if args.any?
@@ -183,9 +246,17 @@ module Vedeu
183
246
  {
184
247
  colour_mode: detect_colour_mode,
185
248
  debug: false,
249
+ drb: false,
250
+ drb_host: nil,
251
+ drb_port: nil,
252
+ drb_height: 25,
253
+ drb_width: 80,
186
254
  interactive: true,
187
255
  log: '/tmp/vedeu.log',
188
256
  once: false,
257
+ stdin: nil,
258
+ stdout: nil,
259
+ stderr: nil,
189
260
  system_keys: Configuration.default_system_keys,
190
261
  terminal_mode: :raw,
191
262
  trace: false,
@@ -0,0 +1,8 @@
1
+ require 'vedeu/distributed/uri'
2
+ require 'vedeu/distributed/client'
3
+ require 'vedeu/distributed/application'
4
+ require 'vedeu/distributed/subprocess'
5
+ require 'vedeu/distributed/test_application'
6
+
7
+ module Vedeu
8
+ end # Vedeu
@@ -0,0 +1,91 @@
1
+ require 'drb'
2
+
3
+ module Vedeu
4
+
5
+ module Distributed
6
+
7
+ # Orchestrates the running of the main application loop via the DRb server.
8
+ #
9
+ # @example
10
+ # app = Vedeu::Distributed::Application.start(configuration)
11
+ # app.input('a')
12
+ # app.output # => some output
13
+ # app.stop
14
+ #
15
+ # @api private
16
+ class Application
17
+
18
+ class << self
19
+
20
+ # @param configuration [Vedeu::Configuration]
21
+ # @return []
22
+ def start(configuration)
23
+ new(configuration).start
24
+ end
25
+
26
+ end
27
+
28
+ # @param configuration [Vedeu::Configuration]
29
+ # @return []
30
+ def initialize(configuration)
31
+ @configuration = configuration
32
+
33
+ # $SAFE = 1 # stop eval and friends
34
+ end
35
+
36
+ # @return []
37
+ def start
38
+ Vedeu.bind(:_output_) { |data| self.output(data) }
39
+
40
+ Vedeu.log("Started distributed server: '#{uri}'")
41
+
42
+ DRb.start_service(uri, self)
43
+
44
+ self
45
+ end
46
+
47
+ # @param data []
48
+ # @return []
49
+ def input(data)
50
+ Vedeu.log("<<< DRb Input")
51
+
52
+ Vedeu.trigger(:_keypress_, data)
53
+ end
54
+ alias_method :read, :input
55
+
56
+ # @param data []
57
+ # @return []
58
+ def output(data = nil)
59
+ Vedeu.log(">>> DRb Output")
60
+
61
+ data
62
+ end
63
+ alias_method :write, :output
64
+
65
+ # @return []
66
+ def stop
67
+ Vedeu.log("Stopping distributed server: '#{uri}'")
68
+
69
+ DRb.stop_service
70
+
71
+ DRb.thread.join
72
+ rescue NoMethodError # raised when #join is called on NilClass.
73
+ # ...
74
+
75
+ end
76
+
77
+ private
78
+
79
+ attr_reader :configuration
80
+
81
+ # @return [String]
82
+ def uri
83
+ Vedeu::Distributed::Uri.new(configuration.drb_host,
84
+ configuration.drb_port).to_s
85
+ end
86
+
87
+ end # Application
88
+
89
+ end # Distributed
90
+
91
+ end # Vedeu
@@ -0,0 +1,58 @@
1
+ require 'drb'
2
+
3
+ module Vedeu
4
+
5
+ module Distributed
6
+
7
+ # @example
8
+ # client = Vedeu::Distributed::Client.new("druby://localhost:21420")
9
+ # client.input('a')
10
+ # client.output # => 'some content...'
11
+ # client.stop
12
+ #
13
+ class Client
14
+
15
+ # @param uri [String]
16
+ # @return [Client]
17
+ def initialize(uri)
18
+ @uri = uri.to_s
19
+ end
20
+
21
+ # @param data [String|Symbol]
22
+ # @return []
23
+ def input(data)
24
+ server.input(data)
25
+ end
26
+ alias_method :read, :input
27
+
28
+ # @return []
29
+ def output
30
+ server.output
31
+ end
32
+ alias_method :write, :output
33
+
34
+ # @return []
35
+ def start
36
+ # client should be able to start a server, but what if one already
37
+ # exists?
38
+ end
39
+
40
+ # @return []
41
+ def stop
42
+ server.stop
43
+ end
44
+
45
+ private
46
+
47
+ attr_reader :uri
48
+
49
+ # @return []
50
+ def server
51
+ @server ||= DRbObject.new_with_uri(uri)
52
+ end
53
+
54
+ end # Client
55
+
56
+ end # Distributed
57
+
58
+ end # Vedeu
@@ -0,0 +1,111 @@
1
+ require 'pty'
2
+ require 'vedeu/distributed/test_application'
3
+
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
+ module Vedeu
28
+
29
+ # @example
30
+ # Vedeu::TestApplication.build
31
+ #
32
+ class Subprocess
33
+
34
+ # @param application [Vedeu::TestApplication]
35
+ # @return []
36
+ def self.execute!(application)
37
+ new(application).execute!
38
+ end
39
+
40
+ # @param application [Vedeu::TestApplication]
41
+ # @return [Vedeu::Subprocess]
42
+ def initialize(application)
43
+ @application = application
44
+ end
45
+
46
+ # @return []
47
+ def execute!
48
+ file_open && file_write && file_close
49
+
50
+ begin
51
+ PTY.spawn(command) do |stdin, stdout, pid|
52
+ begin
53
+ stdin.each { |line| print line }
54
+
55
+ rescue Errno::EIO
56
+ puts 'Errno::EIO: Process may have stopped giving output.'
57
+
58
+ end
59
+ end
60
+ rescue PTY::ChildExited
61
+ puts 'PTY::ChildExited: Process exited.'
62
+
63
+ ensure
64
+ file_unlink
65
+
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ attr_reader :application
72
+
73
+ # @return [String]
74
+ def command
75
+ "ruby #{file_path}"
76
+ end
77
+
78
+ # @return []
79
+ def file_write
80
+ file.write(application)
81
+ end
82
+
83
+ # @return []
84
+ def file_close
85
+ file.close
86
+ end
87
+
88
+ # @return []
89
+ def file_unlink
90
+ File.unlink("/tmp/foo_#{timestamp}")
91
+ end
92
+
93
+ # return [String]
94
+ def file_path
95
+ file.path
96
+ end
97
+
98
+ # @return []
99
+ def file_open
100
+ @file ||= File.new("/tmp/foo_#{timestamp}", "w")
101
+ end
102
+ alias_method :file, :file_open
103
+
104
+ # return [Fixnum]
105
+ def timestamp
106
+ @timestamp ||= Time.now.to_i
107
+ end
108
+
109
+ end # Subprocess
110
+
111
+ end # Vedeu
@@ -0,0 +1,34 @@
1
+ lib_dir = "<%= @object.lib_dir %>"
2
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
3
+
4
+ require 'vedeu'
5
+
6
+ class VedeuTestApplication
7
+ # include Vedeu
8
+
9
+ <%= @object.configuration -%>
10
+
11
+ <%= @object.events -%>
12
+
13
+ <%= @object.borders -%>
14
+
15
+ <%= @object.geometries -%>
16
+
17
+ <%= @object.interfaces -%>
18
+
19
+ <%= @object.keymaps -%>
20
+
21
+ <%= @object.menus -%>
22
+
23
+ <%= @object.views -%>
24
+
25
+ def self.start(argv = ARGV,
26
+ stdin = STDIN,
27
+ stdout = STDOUT,
28
+ stderr = STDERR,
29
+ kernel = Kernel)
30
+ Vedeu::Launcher.new(argv, stdin, stdout, stderr, kernel).execute!
31
+ end
32
+ end
33
+
34
+ VedeuTestApplication.start(ARGV)
@@ -0,0 +1,19 @@
1
+ Vedeu.border 'test_interface' do
2
+ # Define colour and style of border
3
+ colour foreground: '#ffff00', background: '#0000ff'
4
+ style 'normal'
5
+
6
+ # Define visibility of border
7
+ show_bottom!
8
+ show_left!
9
+ show_right!
10
+ show_top!
11
+
12
+ # Define characters used to draw border
13
+ bottom_right '+'
14
+ bottom_left '+'
15
+ horizontal '-'
16
+ top_right '+'
17
+ top_left '+'
18
+ vertical '|'
19
+ end