livecode 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc CHANGED
@@ -22,6 +22,16 @@ Open a new TextMate document and set the language to "Ruby Livecode". You can
22
22
  now press CMD+E to run either the selected text or the current line on
23
23
  the server. Hack away!
24
24
 
25
+ == Multiplayer livecoding
26
+
27
+ Instead of running your own server, you can connect to a remote session by running:
28
+
29
+ livecode connect drb://somewhere.else:123456
30
+
31
+ When you're done, disconnect with:
32
+
33
+ livecode disconnect
34
+
25
35
  == Making your own client
26
36
 
27
37
  ..is fairly simple:
data/Rakefile CHANGED
@@ -11,7 +11,7 @@ begin
11
11
  gem.homepage = "http://github.com/elektronaut/livecode"
12
12
  gem.authors = ["Inge Jørgensen"]
13
13
  gem.add_dependency "daemons"
14
- gem.files.include 'extras/**/*'
14
+ #gem.files.include 'extras/**/*'
15
15
  #gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.7
1
+ 0.0.8
data/bin/livecode CHANGED
@@ -1,68 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
+ require 'livecode_server/command'
4
4
 
5
- require 'pathname'
6
- require 'rubygems'
7
- require 'daemons'
8
- require 'livecode_server'
9
-
10
- class Daemons::Controller
11
- def print_usage
12
- puts "Usage: #{@app_name} <command> <options> -- <application options>"
13
- puts
14
- puts "Server control commands:"
15
- puts " start Start the server"
16
- puts " stop Stop the server"
17
- puts " restart Stop and restart the server"
18
- puts " run Start the server and stay on top"
19
- puts " status Show server status"
20
- #puts " zap set the application to a stopped state"
21
- puts
22
- puts "Tools:"
23
- puts " update_textmate Install or update the TextMate bundle"
24
- puts
25
- puts "* and where <options> may contain several of the following:"
26
- puts @optparse.usage
27
- end
28
- end
29
-
30
- LivecodeServer.make_dir!
31
-
32
- daemon_options = {
33
- :dir_mode => :normal,
34
- :dir => LivecodeServer::CONFIG_DIR
35
- }
36
-
37
- case ARGV.first
38
- when 'update_textmate'
39
- puts "Updating Textmate bundle.."
40
- `sudo mkdir -p /Library/Application\\ Support/TextMate/Bundles`
41
- if File.exists?("/Library/Application Support/TextMate/Bundles/Ruby Livecode.tmbundle")
42
- `sudo rm /Library/Application\\ Support/TextMate/Bundles/Ruby\\ Livecode.tmbundle`
43
- end
44
- bundle_path = Pathname.new(File.join(Gem.cache.find_name('livecode').map{|g| g.full_gem_path}.sort.last, 'extras/textmate/Ruby Livecode.tmbundle')).realpath.to_s
45
- escaped_bundle_path = bundle_path.gsub(/\s/, '\ ')
46
- `sudo ln -s #{escaped_bundle_path} /Library/Application\\ Support/TextMate/Bundles/Ruby\\ Livecode.tmbundle`
47
- `osascript -e 'tell app "TextMate" to reload bundles'`
48
- else
49
- group = Daemons.run_proc(File.basename($0), daemon_options) do
50
- LivecodeServer.make_dir!
51
- unless LivecodeServer.running?
52
- server = LivecodeServer::Daemon.new
53
- DRb.start_service nil, server
54
- LivecodeServer.register_uri DRb.uri
55
- puts "Started Livecode server on #{DRb.uri}"
56
- puts "Press ^C to exit"
57
- trap_proc = proc{
58
- puts "Exiting..."
59
- LivecodeServer.register_shutdown
60
- exit
61
- }
62
- %w{SIGINT TERM}.each{|s| trap s, trap_proc}
63
- DRb.thread.join
64
- else
65
- puts "Livecode server appears to be running on #{LivecodeServer.uri}. Please check your processes."
66
- end
67
- end
68
- end
5
+ LivecodeServer::Command.run!(*ARGV)
@@ -18,6 +18,8 @@ rescue LivecodeServer::ConnectionError =&gt; e
18
18
  puts "Livecode server not running!\n\n"
19
19
  puts '- Press ⌘B to start in daemon mode'
20
20
  puts '- Run in Terminal with "livecode run"'
21
+ rescue DRb::DRbBadURI =&gt; e
22
+ puts "Error! Can't connect to remote server."
21
23
  rescue Exception =&gt; e
22
24
  puts "Error!"
23
25
  puts " #{e.class}: #{e}"
@@ -18,6 +18,8 @@ rescue LivecodeServer::ConnectionError =&gt; e
18
18
  puts "Livecode server not running!\n\n"
19
19
  puts '- Press ⌘B to start in daemon mode'
20
20
  puts '- Run in Terminal with "livecode run"'
21
+ rescue DRb::DRbBadURI =&gt; e
22
+ puts "Error! Can't connect to remote server."
21
23
  rescue Exception =&gt; e
22
24
  puts "Error!"
23
25
  puts " #{e.class}: #{e}"
@@ -18,6 +18,8 @@ rescue LivecodeServer::ConnectionError =&gt; e
18
18
  puts "Livecode server not running!\n\n"
19
19
  puts '- Press ⌘B to start in daemon mode'
20
20
  puts '- Run in Terminal with "livecode run"'
21
+ rescue DRb::DRbBadURI =&gt; e
22
+ puts "Error! Can't connect to remote server."
21
23
  rescue Exception =&gt; e
22
24
  puts "Error!"
23
25
  puts " #{e.class}: #{e}"
@@ -1,7 +1,18 @@
1
1
  module LivecodeServer
2
- class ConnectionError < StandardError; end
2
+
3
+ # Connection error, raised when trying to connect while the server isn't running.
4
+ class ConnectionError < StandardError
5
+ end
3
6
 
7
+ # Livecode server client
8
+ #
9
+ # Usage:
10
+ # client = LivecodeServer::Client.new
11
+ # client.run 'puts "Hello world"'
12
+
4
13
  class Client
14
+
15
+ # Daemon connection, connects to it if necessary.
5
16
  def server
6
17
  unless @server
7
18
  if LivecodeServer.running?
@@ -14,6 +25,7 @@ module LivecodeServer
14
25
  @server
15
26
  end
16
27
 
28
+ # Runs code on the server.
17
29
  def run(code)
18
30
  server.run code
19
31
  end
@@ -0,0 +1,243 @@
1
+ require 'rubygems'
2
+ require 'optparse'
3
+ require 'pathname'
4
+ require 'daemons'
5
+
6
+ require 'livecode_server'
7
+
8
+ module LivecodeServer
9
+ class Command
10
+ class << self
11
+
12
+ def version
13
+ "Livecode server " + File.read(File.join(File.dirname(__FILE__), '../../VERSION'))
14
+ end
15
+
16
+ # Run command
17
+ def run!(*args)
18
+ options = {}
19
+ optparse = OptionParser.new do |opts|
20
+ opts.banner = "Usage: #{File.basename($0)} [command] [options]\n\n"
21
+ opts.banner += " Server control commands:\n"
22
+ opts.banner += " start Start the server as a daemon\n"
23
+ opts.banner += " stop Stop the server\n"
24
+ opts.banner += " restart Restart the server\n"
25
+ opts.banner += " run Start the server and stay on top\n"
26
+ opts.banner += " status Show server status\n"
27
+ opts.banner += "\n"
28
+ opts.banner += " Client control commands:\n"
29
+ opts.banner += " connect Connect to remote server\n"
30
+ opts.banner += " disconnect Disconnect from remote server\n"
31
+ opts.banner += "\n"
32
+ opts.banner += " Other commands:\n"
33
+ opts.banner += " update_textmate Update TextMate bundle\n"
34
+ opts.banner += "\n"
35
+ opts.banner += " Options:"
36
+ opts.on('-h', '--help', 'Show this message') do
37
+ puts opts
38
+ exit
39
+ end
40
+ opts.on('-v', '--version', 'Show version') do
41
+ puts self.version
42
+ exit
43
+ end
44
+ end
45
+ optparse.parse!
46
+
47
+ if ARGV.length > 0
48
+ command = self.new(options)
49
+ run_command = ARGV.shift
50
+ unless command.dispatch!(run_command, *ARGV)
51
+ puts "ERROR! Invalid command: #{run_command}\n\n"
52
+ puts optparse
53
+ end
54
+ else
55
+ puts optparse
56
+ end
57
+ end
58
+ end
59
+
60
+ protected
61
+
62
+ def daemon_group
63
+ daemon_options = {
64
+ :mode => :proc,
65
+ :multiple => false,
66
+ :ontop => @options[:ontop] ? true : false,
67
+ :dir_mode => :normal,
68
+ :dir => LivecodeServer::CONFIG_DIR
69
+ }
70
+ daemon_options[:proc] = proc do
71
+ LivecodeServer.make_dir!
72
+ server = LivecodeServer::Daemon.new
73
+ DRb.start_service nil, server
74
+ LivecodeServer.register_uri DRb.uri
75
+ puts "Started Livecode server on #{DRb.uri}"
76
+ puts "Press ^C to exit"
77
+ trap_proc = proc{
78
+ puts "Exiting..."
79
+ LivecodeServer.register_shutdown
80
+ exit
81
+ }
82
+ %w{SIGINT TERM}.each{|s| trap s, trap_proc}
83
+ DRb.thread.join
84
+ end
85
+ unless @daemon_group
86
+ @daemon_group = Daemons::ApplicationGroup.new(@app_name, daemon_options)
87
+ @daemon_group.setup
88
+ end
89
+ @daemon_group
90
+ end
91
+
92
+ def server_running?
93
+ (daemon_group.applications.length > 0) ? true : false
94
+ end
95
+
96
+ public
97
+
98
+ def initialize(options)
99
+ @app_name = "livecode"
100
+ @options = {}.merge(options)
101
+ end
102
+
103
+ # Dispatch a command
104
+ def dispatch!(command, *args)
105
+ if (self.public_methods - Object.methods - ['dispatch!']).include?(command)
106
+ begin
107
+ self.send(command.to_sym, *args)
108
+ rescue ArgumentError => e
109
+ puts "Error: #{e}"
110
+ end
111
+ return command
112
+ else
113
+ return nil
114
+ end
115
+ end
116
+
117
+ # Start the server
118
+ def start(*args)
119
+ if server_running?
120
+ puts "Livecode server is already running on #{LivecodeServer.uri}"
121
+ else
122
+ daemon_group.new_application.start
123
+ sleep(2)
124
+ puts "Started Livecode server on #{LivecodeServer.uri}"
125
+ end
126
+ end
127
+
128
+ # Start the server and stay on top
129
+ def run(*args)
130
+ @options[:ontop] = true
131
+ if server_running?
132
+ puts "Livecode server is already running on #{LivecodeServer.uri}"
133
+ else
134
+ daemon_group.new_application.start
135
+ end
136
+ end
137
+
138
+ # Stop the server
139
+ def stop(*args)
140
+ if server_running?
141
+ daemon_group.stop_all
142
+ puts "Livecode server stopped."
143
+ else
144
+ puts "Livecode server isn't running, nothing to stop."
145
+ end
146
+ end
147
+
148
+ # Restart the server
149
+ def restart
150
+ if server_running?
151
+ puts "Restarting server.."
152
+ daemon_group.stop_all
153
+ sleep(1)
154
+ daemon_group.start_all
155
+ sleep(2)
156
+ puts "Livecode server is now running on #{LivecodeServer.uri}"
157
+ else
158
+ puts "Livecode server isn't running, nothing to restart."
159
+ end
160
+ end
161
+
162
+ # Show server status
163
+ def status
164
+ if server_running?
165
+ puts "Livecode server is running on #{LivecodeServer.uri}"
166
+ elsif LivecodeServer.running?
167
+ puts "Remote connected to server on #{LivecodeServer.uri}"
168
+ else
169
+ puts "Livecode server isn't running."
170
+ end
171
+ end
172
+
173
+ # Connect to a remote server
174
+ def connect(url, *args)
175
+ if url =~ /^drb:\/\/.+/
176
+ if server_running?
177
+ daemon_group.stop_all
178
+ sleep(1)
179
+ end
180
+ LivecodeServer.register_uri url
181
+ puts "Now connected to server on #{url}"
182
+ else
183
+ puts "Error: Not a valid server url"
184
+ end
185
+ end
186
+
187
+ # Disconnect from remote server
188
+ def disconnect
189
+ if server_running?
190
+ puts "Livecode server running as daemon, shutdown to disconnect."
191
+ elsif LivecodeServer.running?
192
+ puts "Livecode server disconnected."
193
+ LivecodeServer.register_shutdown
194
+ else
195
+ puts "Not connected to any Livecode servers."
196
+ end
197
+ end
198
+
199
+ # Update TextMate bundle
200
+ def update_textmate
201
+ update_bundle = true
202
+ bundle_path = File.join(File.dirname(__FILE__), '../../extras/textmate/Ruby Livecode.tmbundle')
203
+ bundle_path = Pathname.new(bundle_path).realpath.to_s
204
+ escaped_bundle_path = bundle_path.gsub(/\s/, '\ ')
205
+ target_path = '/Library/Application Support/TextMate/Bundles/Ruby Livecode.tmbundle'
206
+ escaped_target_path = target_path.gsub(/\s/, '\ ')
207
+
208
+ # Handle existing files
209
+ if File.exists?(target_path)
210
+ if File.symlink?(target_path)
211
+ if Pathname.new(target_path).realpath.to_s == bundle_path
212
+ puts "TextMate bundle is already up to date."
213
+ update_bundle = false
214
+ else
215
+ puts "Existing symlink found:\n\n"
216
+ puts "- " + Pathname.new(target_path).realpath.to_s
217
+ puts "+ " + bundle_path
218
+ print "\nReplace? [y/n] "
219
+ end
220
+ else
221
+ print "Existing bundle found, are you sure you want to replace it? [y/n] "
222
+ end
223
+ if update_bundle
224
+ if STDIN.readline.chomp =~ /^y/i
225
+ `sudo rm -rf #{escaped_target_path}`
226
+ else
227
+ update_bundle = false
228
+ end
229
+ end
230
+ end
231
+
232
+ if update_bundle
233
+ unless File.exists?("/Library/Application Support/TextMate/Bundles")
234
+ `sudo mkdir -p /Library/Application\\ Support/TextMate/Bundles`
235
+ end
236
+ puts "Updating Textmate bundle.."
237
+ `sudo ln -s #{escaped_bundle_path} #{escaped_target_path}`
238
+ `osascript -e 'tell app "TextMate" to reload bundles'`
239
+ end
240
+ end
241
+
242
+ end
243
+ end
@@ -1,4 +1,6 @@
1
1
  module LivecodeServer
2
+
3
+ # LivecodeServer daemon
2
4
  class Daemon
3
5
  attr_reader :scope
4
6
 
data/livecode.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{livecode}
8
- s.version = "0.0.7"
8
+ s.version = "0.0.8"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Inge J\303\270rgensen"]
12
- s.date = %q{2009-10-22}
12
+ s.date = %q{2009-10-23}
13
13
  s.default_executable = %q{livecode}
14
14
  s.description = %q{A toolkit for livecoding using Ruby and TextMate on OSX}
15
15
  s.email = %q{inge@elektronaut.no}
@@ -27,22 +27,16 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "bin/livecode",
29
29
  "extras/textmate/Ruby Livecode.tmbundle/Commands/Execute Document.tmCommand",
30
- "extras/textmate/Ruby Livecode.tmbundle/Commands/Execute Document.tmCommand",
31
- "extras/textmate/Ruby Livecode.tmbundle/Commands/Execute Selection:Line.tmCommand",
32
30
  "extras/textmate/Ruby Livecode.tmbundle/Commands/Execute Selection:Line.tmCommand",
33
31
  "extras/textmate/Ruby Livecode.tmbundle/Commands/Execute Selection:Scope.tmCommand",
34
- "extras/textmate/Ruby Livecode.tmbundle/Commands/Execute Selection:Scope.tmCommand",
35
- "extras/textmate/Ruby Livecode.tmbundle/Commands/Start.tmCommand",
36
32
  "extras/textmate/Ruby Livecode.tmbundle/Commands/Start.tmCommand",
37
33
  "extras/textmate/Ruby Livecode.tmbundle/Commands/Stop.tmCommand",
38
- "extras/textmate/Ruby Livecode.tmbundle/Commands/Stop.tmCommand",
39
- "extras/textmate/Ruby Livecode.tmbundle/Syntaxes/Ruby Livecode.tmLanguage",
40
34
  "extras/textmate/Ruby Livecode.tmbundle/Syntaxes/Ruby Livecode.tmLanguage",
41
35
  "extras/textmate/Ruby Livecode.tmbundle/info.plist",
42
- "extras/textmate/Ruby Livecode.tmbundle/info.plist",
43
36
  "lib/livecode.rb",
44
37
  "lib/livecode_server.rb",
45
38
  "lib/livecode_server/client.rb",
39
+ "lib/livecode_server/command.rb",
46
40
  "lib/livecode_server/daemon.rb",
47
41
  "lib/livecode_server/scope.rb",
48
42
  "livecode.gemspec",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: livecode
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Inge J\xC3\xB8rgensen"
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-22 00:00:00 +02:00
12
+ date: 2009-10-23 00:00:00 +02:00
13
13
  default_executable: livecode
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -49,6 +49,7 @@ files:
49
49
  - lib/livecode.rb
50
50
  - lib/livecode_server.rb
51
51
  - lib/livecode_server/client.rb
52
+ - lib/livecode_server/command.rb
52
53
  - lib/livecode_server/daemon.rb
53
54
  - lib/livecode_server/scope.rb
54
55
  - livecode.gemspec