coderunner 0.11.0
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/.document +5 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +20 -0
- data/README.md +4 -0
- data/README.rdoc +19 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/coderunner.rb +419 -0
- data/lib/coderunner/class_methods.rb +727 -0
- data/lib/coderunner/fortran_namelist.rb +1281 -0
- data/lib/coderunner/graphs_and_films.rb +744 -0
- data/lib/coderunner/heuristic_run_methods.rb +202 -0
- data/lib/coderunner/instance_methods.rb +1741 -0
- data/lib/coderunner/interactive_methods.rb +776 -0
- data/lib/coderunner/long_regexen.rb +201 -0
- data/lib/coderunner/merged_code_runner.rb +40 -0
- data/lib/coderunner/run.rb +1000 -0
- data/test/helper.rb +18 -0
- data/test/test_coderunner.rb +7 -0
- metadata +139 -0
@@ -0,0 +1,776 @@
|
|
1
|
+
class CodeRunner
|
2
|
+
|
3
|
+
module InteractiveMethods
|
4
|
+
COMMANDS.each do |command|
|
5
|
+
eval("def #{command[1]}(*args)
|
6
|
+
# if args[-1].kind_of?
|
7
|
+
CodeRunner.send(#{command[0].to_sym.inspect}, *args)
|
8
|
+
end")
|
9
|
+
end
|
10
|
+
def up
|
11
|
+
ObjectSpace.each_object{|obj| obj.update if obj.class.to_s =~ /CodeRunner$/}
|
12
|
+
nil
|
13
|
+
end
|
14
|
+
def cd(dirct)
|
15
|
+
Dir.chdir(dirct)
|
16
|
+
end
|
17
|
+
def setup_interactive
|
18
|
+
@runner = CodeRunner.fetch_runner(CodeRunner::DEFAULT_COMMAND_OPTIONS.dup) unless CodeRunner::DEFAULT_COMMAND_OPTIONS[:q]
|
19
|
+
@r = @runner
|
20
|
+
end
|
21
|
+
def pwd
|
22
|
+
puts Dir.pwd
|
23
|
+
end
|
24
|
+
def runs
|
25
|
+
CodeRunner.runner.run_list
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
|
32
|
+
INTERACTIVE_METHODS = <<EOF
|
33
|
+
|
34
|
+
|
35
|
+
include CodeRunner::InteractiveMethods
|
36
|
+
setup_interactive
|
37
|
+
module Kernel
|
38
|
+
|
39
|
+
alias_method(:shell_do, "`".to_sym)
|
40
|
+
def `(cmd)
|
41
|
+
c =caller
|
42
|
+
if c[0] =~ /irb_binding/
|
43
|
+
system(cmd)
|
44
|
+
else
|
45
|
+
shell_do(cmd)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
EOF
|
50
|
+
|
51
|
+
end # module InteractiveMethods
|
52
|
+
|
53
|
+
def CodeRunner.interactive_mode(copts={})
|
54
|
+
process_command_options(copts)
|
55
|
+
unless false and FileTest.exist? (ENV['HOME'] + '/code_runner_interactive_options.rb')
|
56
|
+
File.open(ENV['HOME'] + '/.code_runner_interactive_options.rb', 'w') do |file|
|
57
|
+
file.puts <<EOF
|
58
|
+
$has_put_startup_message_for_code_runner = true #please leave!
|
59
|
+
$code_runner_interactive_mode = true #please leave!
|
60
|
+
require 'yaml'
|
61
|
+
|
62
|
+
def reset
|
63
|
+
Dispatcher.reset_application!
|
64
|
+
end
|
65
|
+
|
66
|
+
IRB.conf[:AUTO_INDENT] = true
|
67
|
+
IRB.conf[:USE_READLINE] = true
|
68
|
+
IRB.conf[:LOAD_MODULES] = [] unless IRB.conf.key?(:LOAD_MODULES)
|
69
|
+
unless IRB.conf[:LOAD_MODULES].include?('irb/completion')
|
70
|
+
IRB.conf[:LOAD_MODULES] << 'irb/completion'
|
71
|
+
end
|
72
|
+
|
73
|
+
|
74
|
+
require 'irb/completion'
|
75
|
+
require 'irb/ext/save-history'
|
76
|
+
require 'socket'
|
77
|
+
unless ENV['CODE_RUNNER_SYSTEM'] == 'macosx'
|
78
|
+
prompt_start = "\001#{Terminal::LIGHT_GREEN}\002CodeRunner\001#{Terminal::RESET}\002 v#{CODE_RUNNER_VERSION} - \001#{Terminal::CYAN}\002#\{ENV['USER']\}@#\{Socket::gethostname\}:#\{File.basename(Dir.pwd)}\001#{Terminal::RESET}\002 timemarker\n"
|
79
|
+
prompt_start = "\001#{Terminal::LIGHT_GREEN}\002CodeRunner\001#{Terminal::RESET}\002 v#{CODE_RUNNER_VERSION} - \001#{Terminal::CYAN}\002#\{Socket::gethostname\}:#\{File.basename(Dir.pwd)}\001#{Terminal::RESET}\002 timemarker %02n,%i \n"
|
80
|
+
else
|
81
|
+
prompt_start = "CodeRunner #\{File.basename(Dir.pwd)}"
|
82
|
+
end
|
83
|
+
IRB.conf[:PROMPT][:CODE_RUNNER] = {:PROMPT_I=>"#\{prompt_start}>> %02n,%i >> ", :PROMPT_N=>"#\{prompt_start}>> %02n:%i > ", :PROMPT_S=>"#\{prompt_start}>> %02n:%i (%l)> ", :PROMPT_C=>"#\{prompt_start}>> %02n:%i >> ", :RETURN=>""}
|
84
|
+
IRB.conf[:PROMPT][:CODE_RUNNER] = {:PROMPT_I=>"#\{prompt_start}>> ", :PROMPT_N=>"#\{prompt_start}> ", :PROMPT_S=>"#\{prompt_start}(%l)> ", :PROMPT_C=>"#\{prompt_start}>> ", :RETURN=>""}
|
85
|
+
# IRB.conf[:PROMPT][:CODE_RUNNER] = {:PROMPT_I=>"#\{prompt_start} %02n,%i>> ", :PROMPT_N=>"#\{prompt_start} %02n:%i> ", :PROMPT_S=>"#\{prompt_start} %02n:%i (%l)> ", :PROMPT_C=>"#\{prompt_start} %02n:%i>> ", :RETURN=>""}
|
86
|
+
|
87
|
+
|
88
|
+
IRB.conf[:PROMPT_MODE] = :CODE_RUNNER
|
89
|
+
IRB.conf[:SAVE_HISTORY] = 400
|
90
|
+
IRB.conf[:HISTORY_FILE] = "\#\{Dir.pwd}/.code-runner-irb-save-history"
|
91
|
+
IRB.conf[:INSPECT_MODE] = false
|
92
|
+
|
93
|
+
|
94
|
+
EOF
|
95
|
+
end # File.open
|
96
|
+
end # unless
|
97
|
+
File.open(".int.tmp.rb", 'w')do |file|
|
98
|
+
file.puts "#{copts.inspect}.each do |key, val|
|
99
|
+
CodeRunner::DEFAULT_COMMAND_OPTIONS[key] = val
|
100
|
+
end"
|
101
|
+
file.puts CodeRunner::InteractiveMethods::INTERACTIVE_METHODS
|
102
|
+
end
|
103
|
+
# asdfa
|
104
|
+
exec %[#{Config::CONFIG['bindir']}/irb#{Config::CONFIG['ruby_install_name'].sub(/ruby/, '')} -f -I '#{Dir.pwd}' -I '#{SCRIPT_FOLDER}' -I '#{ENV['HOME']}' -r '.code_runner_interactive_options' -r 'coderunner' -r .int.tmp ]
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
require "readline"
|
112
|
+
|
113
|
+
|
114
|
+
module IRB
|
115
|
+
|
116
|
+
COMMANDS = ENV['PATH'].split(':').inject([]) do |comms,dir|
|
117
|
+
# ep dir
|
118
|
+
begin
|
119
|
+
dir = dir.sub(/~/, ENV['HOME'])
|
120
|
+
Dir.entries(dir).each do |file|
|
121
|
+
file = "#{dir}/#{file}"
|
122
|
+
# ep file
|
123
|
+
comms.push(File.basename(file)) if FileTest.executable? file #and File.file? file
|
124
|
+
end
|
125
|
+
rescue
|
126
|
+
end
|
127
|
+
comms
|
128
|
+
end
|
129
|
+
COMMANDS.delete_if{|com| com =~ /^\./}
|
130
|
+
# ep 'COMMANDS', COMMANDS
|
131
|
+
|
132
|
+
module InputCompletor
|
133
|
+
|
134
|
+
def self.complete_files(receiver, message)
|
135
|
+
# files = message.split(/\s+/)
|
136
|
+
# message = files.pop
|
137
|
+
dir = message.sub(/[^\/]*$/, '')
|
138
|
+
message = message.sub(Regexp.new("#{Regexp.escape(dir)}"), '')
|
139
|
+
dir.sub!(/^~/, ENV['HOME'])
|
140
|
+
short_dir = dir
|
141
|
+
dir = Dir.pwd + '/' + dir unless dir =~ /^\//
|
142
|
+
#$stderr.puts "Dir to scan: #{dir}"
|
143
|
+
|
144
|
+
files = Dir.entries(dir)
|
145
|
+
|
146
|
+
#$stderr.puts "entries", files
|
147
|
+
Dir.chdir(dir){files= files.map{|file| FileTest.directory?(file) ? file + "/" : file}}
|
148
|
+
#$stderr.puts "entries - directories", files
|
149
|
+
|
150
|
+
candidates = message.size > 0 ? files.find_all{|com| com[0...message.size] == message} : files
|
151
|
+
return candidates.map{|com| receiver + short_dir + com}
|
152
|
+
|
153
|
+
|
154
|
+
old_dir = message.sub(/[^\/]*$/, '')
|
155
|
+
dir = old_dir.chomp("/")
|
156
|
+
message = message.sub(Regexp.new("#{Regexp.escape(dir)}\\/"), '')
|
157
|
+
if dir.size > 0
|
158
|
+
# eputs 'dir', dir
|
159
|
+
# unless old_dir ~= /^\//
|
160
|
+
dir = Dir.pwd + '/' + dir
|
161
|
+
# end
|
162
|
+
# eputs 'dir', dir, FileTest.directory?(dir)
|
163
|
+
if FileTest.directory? dir
|
164
|
+
files = Dir.entries(dir)
|
165
|
+
else
|
166
|
+
files = []
|
167
|
+
end
|
168
|
+
else
|
169
|
+
dir = Dir.pwd
|
170
|
+
files = Dir.entries(dir)
|
171
|
+
end
|
172
|
+
# ep files
|
173
|
+
# ep 'mess', message
|
174
|
+
Dir.chdir(dir){files= files.map{|file| FileTest.directory?(file) ? file + "/" : file}}
|
175
|
+
# ep dir, files
|
176
|
+
candidates = message.size > 0 ? files.find_all{|com| com[0...message.size] == message} : files
|
177
|
+
candidates.map{|com| receiver + old_dir + com}
|
178
|
+
rescue
|
179
|
+
return []
|
180
|
+
end
|
181
|
+
|
182
|
+
@RCS_ID='-$Id: completion.rb 23233 2009-04-19 13:35:47Z yugui $-'
|
183
|
+
|
184
|
+
|
185
|
+
CodeRunnerCompletionProc = proc do |input|
|
186
|
+
bind = IRB.conf[:MAIN_CONTEXT].workspace.binding
|
187
|
+
Readline.completion_append_character = nil
|
188
|
+
# eputs "\n\ninput: #{input}"
|
189
|
+
|
190
|
+
|
191
|
+
case input
|
192
|
+
when Regexp.new("^(#{/\w+\b.*(?:\s|,)(?::p\s+\=\>|p:)\s+\[?\s*/}(?:#{Regexp.quoted_string}\\s*,\\s*)*#{/'\{(?:[^}]*\s)?:?/})(\\w+)$")
|
193
|
+
# matches CodeRunner parameter list.... command [stuff] p: '{var: value, var
|
194
|
+
receiver = $1
|
195
|
+
message = $2
|
196
|
+
# ep 'mess', message
|
197
|
+
if CodeRunner.runner and CodeRunner.runner.run_class
|
198
|
+
candidates = CodeRunner.runner.run_class.rcp.variables.map{|var| var.to_s}.find_all{|var| var[0...message.size] == message}.map{|var| receiver + var}
|
199
|
+
else
|
200
|
+
candidates = []
|
201
|
+
end
|
202
|
+
when /^('(?:(?:\\ |[^'\s])*\s+)*)((?:\\ |[^'\s])*)$/, Regexp.new("^((?:[^']|#{Regexp.quoted_string})*')([^']*)$")
|
203
|
+
#filename in a single quoted string
|
204
|
+
receiver = "#$1" # "`" #$~[1]
|
205
|
+
message = "#$2" #Regexp.quote($~[2]) # $2 #Regexp.quote($2)
|
206
|
+
# ep 'mess', message
|
207
|
+
complete_files(receiver, message)
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
when /^(\`\w+\s+(?:\S+\s+)*)([^`\s]*)$/, /^([^`]*`\w+\s+)([^`]*)$/
|
212
|
+
#shell command with an executable
|
213
|
+
receiver = $1 # "`" #$~[1]
|
214
|
+
message = $2 #Regexp.quote($~[2]) # $2 #Regexp.quote($2)
|
215
|
+
complete_files(receiver, message)
|
216
|
+
# files = Dir.entries(File.dirname(message))
|
217
|
+
# candidates = message.size > 0 ? files.find_all{|com| com[0...message.size] == message} : files
|
218
|
+
# candidates.map{|com| receiver + com}
|
219
|
+
|
220
|
+
when /^(\`)([^`]*)$/, /^([^`]*`)([^`]*)$/
|
221
|
+
#shell command without an excutable
|
222
|
+
|
223
|
+
# p $~
|
224
|
+
receiver = $1 # "`" #$~[1]
|
225
|
+
message = $2 #Regexp.quote($~[2]) # $2 #Regexp.quote($2)
|
226
|
+
# ep "message is", message
|
227
|
+
# ep COMMANDS.grep(//)
|
228
|
+
candidates = message.size > 0 ? COMMANDS.find_all{|com| com[0...message.size] == message} : COMMANDS
|
229
|
+
candidates.map{|com| receiver + com}
|
230
|
+
#.grep(Regexp.new("^#{message}")) #("^#{Regexp.escape(message)}")) #.map{|com| "#{com}"} #.map{|com| receiver + com}
|
231
|
+
# ep candidates
|
232
|
+
# select_message(receiver, message, COMMANDS)
|
233
|
+
|
234
|
+
when /^([^\/]*\/[^\/]*\/)\.([^.]*)$/
|
235
|
+
# Regexp
|
236
|
+
receiver = $1
|
237
|
+
message = Regexp.quote($2)
|
238
|
+
|
239
|
+
candidates = Regexp.instance_methods.collect{|m| m.to_s}
|
240
|
+
select_message(receiver, message, candidates)
|
241
|
+
|
242
|
+
when /^([^\]]*\])\.([^.]*)$/
|
243
|
+
# Array
|
244
|
+
receiver = $1
|
245
|
+
message = Regexp.quote($2)
|
246
|
+
|
247
|
+
candidates = Array.instance_methods.collect{|m| m.to_s}
|
248
|
+
select_message(receiver, message, candidates)
|
249
|
+
|
250
|
+
when /([^\}]*\})\.([^.]*)$/
|
251
|
+
# Proc or Hash
|
252
|
+
receiver = $1
|
253
|
+
message = Regexp.quote($2)
|
254
|
+
|
255
|
+
candidates = Proc.instance_methods.collect{|m| m.to_s}
|
256
|
+
candidates |= Hash.instance_methods.collect{|m| m.to_s}
|
257
|
+
select_message(receiver, message, candidates)
|
258
|
+
|
259
|
+
|
260
|
+
when /^((?:(::)?[A-Z][^:.(]*)+)\.help :(\w*)$/
|
261
|
+
# CodeRunner help method
|
262
|
+
receiver = $1
|
263
|
+
message = Regexp.quote($3)
|
264
|
+
begin
|
265
|
+
candidates = eval("(#{receiver}.constants - Object.constants).collect{|m| m.to_s}", bind)
|
266
|
+
candidates |= eval("(#{receiver}.methods - Object.methods).collect{|m| m.to_s}", bind)
|
267
|
+
begin
|
268
|
+
candidates |= eval("(#{receiver}.instance_methods - Object.instance_methods).collect{|m| m.to_s}", bind)
|
269
|
+
rescue
|
270
|
+
end
|
271
|
+
rescue Exception
|
272
|
+
candidates = []
|
273
|
+
end
|
274
|
+
candidates.grep(/^#{message}/).collect{|e| receiver + '.help :' + e}
|
275
|
+
|
276
|
+
when /^((?:.*[^:])?:[^:.]*)$/
|
277
|
+
# eputs 'found symbol'
|
278
|
+
# Symbol
|
279
|
+
if Symbol.respond_to?(:all_symbols)
|
280
|
+
sym = $1
|
281
|
+
candidates = Symbol.all_symbols.collect{|s| ":" + s.id2name}
|
282
|
+
candidates.grep(/^#{sym}/)
|
283
|
+
else
|
284
|
+
[]
|
285
|
+
end
|
286
|
+
|
287
|
+
when /^(.*\s)?(((::)?[A-Z][^:.(]*)+)(::|\.)([^:.]*)$/
|
288
|
+
# Constant or class methods
|
289
|
+
# p "CCC"
|
290
|
+
start = $1
|
291
|
+
receiver = $2
|
292
|
+
message = Regexp.quote($6)
|
293
|
+
joiner = "#$5"
|
294
|
+
begin
|
295
|
+
candidates = eval("#{receiver}.constants.collect{|m| m.to_s}", bind)
|
296
|
+
candidates |= eval("#{receiver}.methods.collect{|m| m.to_s}", bind)
|
297
|
+
rescue Exception
|
298
|
+
candidates = []
|
299
|
+
end
|
300
|
+
candidates.grep(/^#{message}/).collect{|e| (start or "") + receiver + (joiner or "::") + e}
|
301
|
+
|
302
|
+
|
303
|
+
when /^(.*)(\b[A-Z][^:\.\(]*)$/
|
304
|
+
# Absolute Constant or class methods
|
305
|
+
receiver = $1
|
306
|
+
message = $2
|
307
|
+
candidates = Object.constants.collect{|m| m.to_s}
|
308
|
+
candidates.grep(/^#{message}/).collect{|e| receiver + e}
|
309
|
+
|
310
|
+
|
311
|
+
|
312
|
+
when /^(.*-?(0[dbo])?[0-9_]+(\.[0-9_]+)?([eE]-?[0-9]+)?)\.([^.]*)$/
|
313
|
+
# Numeric
|
314
|
+
receiver = $1
|
315
|
+
message = Regexp.quote($5)
|
316
|
+
|
317
|
+
begin
|
318
|
+
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
319
|
+
rescue Exception
|
320
|
+
candidates = []
|
321
|
+
end
|
322
|
+
select_message(receiver, message, candidates)
|
323
|
+
|
324
|
+
when /^(.*-?0x[0-9a-fA-F_]+)\.([^.]*)$/
|
325
|
+
# Numeric(0xFFFF)
|
326
|
+
receiver = $1
|
327
|
+
message = Regexp.quote($2)
|
328
|
+
|
329
|
+
begin
|
330
|
+
candidates = eval(receiver, bind).methods.collect{|m| m.to_s}
|
331
|
+
rescue Exception
|
332
|
+
candidates = []
|
333
|
+
end
|
334
|
+
select_message(receiver, message, candidates)
|
335
|
+
|
336
|
+
when /^(.*[\s\{\[])?(\$[^.]*)$/
|
337
|
+
regmessage = Regexp.new(Regexp.quote($1))
|
338
|
+
candidates = global_variables.collect{|m| m.to_s}.grep(regmessage)
|
339
|
+
|
340
|
+
# when /^(\$?(\.?[^.]+)+)\.([^.]*)$/
|
341
|
+
when /^((\.?[^.]+)+)\.([^.]*)$/
|
342
|
+
# variable
|
343
|
+
receiver = $1
|
344
|
+
message = Regexp.quote($3)
|
345
|
+
|
346
|
+
gv = eval("global_variables", bind).collect{|m| m.to_s}
|
347
|
+
lv = eval("local_variables", bind).collect{|m| m.to_s}
|
348
|
+
cv = eval("self.class.constants", bind).collect{|m| m.to_s}
|
349
|
+
|
350
|
+
if (gv | lv | cv).include?(receiver)
|
351
|
+
# foo.func and foo is local var.
|
352
|
+
candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
|
353
|
+
elsif /^[A-Z]/ =~ receiver and /\./ !~ receiver
|
354
|
+
# Foo::Bar.func
|
355
|
+
begin
|
356
|
+
candidates = eval("#{receiver}.methods", bind).collect{|m| m.to_s}
|
357
|
+
rescue Exception
|
358
|
+
candidates = []
|
359
|
+
end
|
360
|
+
else
|
361
|
+
# func1.func2
|
362
|
+
candidates = []
|
363
|
+
ObjectSpace.each_object(Module){|m|
|
364
|
+
begin
|
365
|
+
name = m.name
|
366
|
+
rescue Exception
|
367
|
+
name = ""
|
368
|
+
end
|
369
|
+
next if name != "IRB::Context" and
|
370
|
+
/^(IRB|SLex|RubyLex|RubyToken)/ =~ name
|
371
|
+
candidates.concat m.instance_methods(false).collect{|x| x.to_s}
|
372
|
+
}
|
373
|
+
candidates.sort!
|
374
|
+
candidates.uniq!
|
375
|
+
end
|
376
|
+
select_message(receiver, message, candidates)
|
377
|
+
|
378
|
+
when /^\.([^.]*)$/
|
379
|
+
# unknown(maybe String)
|
380
|
+
|
381
|
+
receiver = ""
|
382
|
+
message = Regexp.quote($1)
|
383
|
+
|
384
|
+
candidates = String.instance_methods(true).collect{|m| m.to_s}
|
385
|
+
select_message(receiver, message, candidates)
|
386
|
+
|
387
|
+
else
|
388
|
+
candidates = eval("methods | private_methods | local_variables | self.class.constants", bind).collect{|m| m.to_s}
|
389
|
+
|
390
|
+
(candidates|ReservedWords).grep(/^#{Regexp.quote(input)}/)
|
391
|
+
|
392
|
+
end
|
393
|
+
end
|
394
|
+
|
395
|
+
end
|
396
|
+
|
397
|
+
def self.select_message(receiver, message, candidates)
|
398
|
+
candidates.grep(/^#{message}/).collect do |e|
|
399
|
+
if receiver =~ /^.*`/
|
400
|
+
receiver + e
|
401
|
+
else
|
402
|
+
case e
|
403
|
+
when /^[a-zA-Z_]/
|
404
|
+
receiver + "." + e
|
405
|
+
when /^[0-9]/
|
406
|
+
when *Operators
|
407
|
+
|
408
|
+
|
409
|
+
#receiver + " " + e
|
410
|
+
end
|
411
|
+
end
|
412
|
+
end
|
413
|
+
end
|
414
|
+
class InputMethod
|
415
|
+
end
|
416
|
+
class ReadlineInputMethod < InputMethod
|
417
|
+
include Readline
|
418
|
+
def gets
|
419
|
+
Readline.input = @stdin
|
420
|
+
Readline.output = @stdout
|
421
|
+
prompt_end = Time.now.to_s[11...16]
|
422
|
+
begin
|
423
|
+
memsize = `ps ax -o pid,rss | grep -E "^[[:space:]]*#{Process::pid}"`.chomp.split(/\s+/).map {|s| s.strip.to_i}[1].to_i/1000
|
424
|
+
prompt_end += " #{memsize}k"
|
425
|
+
rescue
|
426
|
+
end
|
427
|
+
prompt_end +=" (#{CodeRunner::SETUP_RUN_CLASSES.join(",")})"
|
428
|
+
if l = readline(@prompt.gsub(/timemarker/, prompt_end) , false)
|
429
|
+
#HISTORY.push(l) if !l.empty? and (HISTORY.size ==0 or l != HISTORY[-1])
|
430
|
+
HISTORY.push(l) if !l.empty? and (HISTORY.size ==0 or l != HISTORY[-1])
|
431
|
+
|
432
|
+
i = 0
|
433
|
+
loop do
|
434
|
+
break if HISTORY.size == 1
|
435
|
+
(HISTORY.delete_at(i); i-=1) if HISTORY[i] == l
|
436
|
+
i+=1
|
437
|
+
#ep "i: #{i}, HS: #{HISTORY.size}"
|
438
|
+
break if i >= HISTORY.size - 1
|
439
|
+
end
|
440
|
+
#HISTORY.reverse!
|
441
|
+
#HISTORY.uniq!
|
442
|
+
#HISTORY.reverse!
|
443
|
+
#HISTORY.push(l) if !l.empty? and (HISTORY.size ==0 or !HISTORY.include? l)
|
444
|
+
@line[@line_no += 1] = l + "\n"
|
445
|
+
else
|
446
|
+
@eof = true
|
447
|
+
l
|
448
|
+
end
|
449
|
+
end
|
450
|
+
end
|
451
|
+
|
452
|
+
end #module IRB
|
453
|
+
|
454
|
+
if Readline.respond_to?("basic_word_break_characters=")
|
455
|
+
Readline.basic_word_break_characters= "\t\n><=;|&("
|
456
|
+
end
|
457
|
+
Readline.completion_append_character = "BB"
|
458
|
+
Readline.completion_proc = IRB::InputCompletor::CodeRunnerCompletionProc
|
459
|
+
|
460
|
+
begin
|
461
|
+
if Readline.respond_to?("basic_quote_characters=")
|
462
|
+
Readline.basic_quote_characters= "\"'`"
|
463
|
+
end
|
464
|
+
rescue NotImplementedError
|
465
|
+
end
|
466
|
+
|
467
|
+
module Kernel
|
468
|
+
|
469
|
+
end
|
470
|
+
|
471
|
+
require 'rdoc'
|
472
|
+
require 'rdoc/ri/driver'
|
473
|
+
|
474
|
+
class RDoc::RI::Driver
|
475
|
+
def run
|
476
|
+
if(@list_doc_dirs)
|
477
|
+
puts @doc_dirs.join("\n")
|
478
|
+
elsif @names.empty? then
|
479
|
+
@display.list_known_classes class_cache.keys.sort
|
480
|
+
else
|
481
|
+
|
482
|
+
@names.each do |name|
|
483
|
+
if class_cache.key? name then
|
484
|
+
method_map = display_class name
|
485
|
+
if(@interactive)
|
486
|
+
method_name = @display.get_class_method_choice(method_map)
|
487
|
+
|
488
|
+
if(method_name != nil)
|
489
|
+
method = lookup_method "#{name}#{method_name}", name
|
490
|
+
display_method method
|
491
|
+
end
|
492
|
+
end
|
493
|
+
elsif name =~ /::|\#|\./ then
|
494
|
+
klass, = parse_name name
|
495
|
+
|
496
|
+
orig_klass = klass
|
497
|
+
orig_name = name
|
498
|
+
|
499
|
+
loop do
|
500
|
+
method = lookup_method name, klass
|
501
|
+
|
502
|
+
break method if method
|
503
|
+
|
504
|
+
ancestor = lookup_ancestor klass, orig_klass
|
505
|
+
|
506
|
+
break unless ancestor
|
507
|
+
|
508
|
+
name = name.sub klass, ancestor
|
509
|
+
klass = ancestor
|
510
|
+
end
|
511
|
+
|
512
|
+
# return unless method
|
513
|
+
|
514
|
+
raise NotFoundError, orig_name unless method
|
515
|
+
|
516
|
+
display_method method
|
517
|
+
else
|
518
|
+
methods = select_methods(/#{name}/)
|
519
|
+
|
520
|
+
if methods.size == 0
|
521
|
+
return
|
522
|
+
raise NotFoundError, name
|
523
|
+
elsif methods.size == 1
|
524
|
+
display_method methods[0]
|
525
|
+
else
|
526
|
+
if(@interactive)
|
527
|
+
@display.display_method_list_choice methods
|
528
|
+
else
|
529
|
+
@display.display_method_list methods
|
530
|
+
end
|
531
|
+
end
|
532
|
+
end
|
533
|
+
end
|
534
|
+
end
|
535
|
+
# rescue NotFoundError => e
|
536
|
+
# eputs e
|
537
|
+
# return
|
538
|
+
end
|
539
|
+
|
540
|
+
def self.process_args(argv)
|
541
|
+
options = default_options
|
542
|
+
|
543
|
+
opts = OptionParser.new do |opt|
|
544
|
+
opt.program_name = File.basename $0
|
545
|
+
opt.version = RDoc::VERSION
|
546
|
+
opt.release = nil
|
547
|
+
opt.summary_indent = ' ' * 4
|
548
|
+
|
549
|
+
directories = [
|
550
|
+
RDoc::RI::Paths::SYSDIR,
|
551
|
+
RDoc::RI::Paths::SITEDIR,
|
552
|
+
RDoc::RI::Paths::HOMEDIR
|
553
|
+
]
|
554
|
+
|
555
|
+
if RDoc::RI::Paths::GEMDIRS then
|
556
|
+
Gem.path.each do |dir|
|
557
|
+
directories << "#{dir}/doc/*/ri"
|
558
|
+
end
|
559
|
+
end
|
560
|
+
|
561
|
+
opt.banner = <<-EOT
|
562
|
+
Usage: #{opt.program_name} [options] [names...]
|
563
|
+
|
564
|
+
Where name can be:
|
565
|
+
|
566
|
+
Class | Class::method | Class#method | Class.method | method
|
567
|
+
|
568
|
+
All class names may be abbreviated to their minimum unambiguous form. If a name
|
569
|
+
is ambiguous, all valid options will be listed.
|
570
|
+
|
571
|
+
The form '.' method matches either class or instance methods, while #method
|
572
|
+
matches only instance and ::method matches only class methods.
|
573
|
+
|
574
|
+
For example:
|
575
|
+
|
576
|
+
#{opt.program_name} Fil
|
577
|
+
#{opt.program_name} File
|
578
|
+
#{opt.program_name} File.new
|
579
|
+
#{opt.program_name} zip
|
580
|
+
|
581
|
+
Note that shell quoting may be required for method names containing
|
582
|
+
punctuation:
|
583
|
+
|
584
|
+
#{opt.program_name} 'Array.[]'
|
585
|
+
#{opt.program_name} compact\\!
|
586
|
+
|
587
|
+
By default ri searches for documentation in the following directories:
|
588
|
+
|
589
|
+
#{directories.join "\n "}
|
590
|
+
|
591
|
+
Specifying the --system, --site, --home, --gems or --doc-dir options will
|
592
|
+
limit ri to searching only the specified directories.
|
593
|
+
|
594
|
+
Options may also be set in the 'RI' environment variable.
|
595
|
+
EOT
|
596
|
+
|
597
|
+
opt.separator nil
|
598
|
+
opt.separator "Options:"
|
599
|
+
opt.separator nil
|
600
|
+
|
601
|
+
opt.on("--fmt=FORMAT", "--format=FORMAT", "-f",
|
602
|
+
RDoc::RI::Formatter::FORMATTERS.keys,
|
603
|
+
"Format to use when displaying output:",
|
604
|
+
" #{RDoc::RI::Formatter.list}",
|
605
|
+
"Use 'bs' (backspace) with most pager",
|
606
|
+
"programs. To use ANSI, either disable the",
|
607
|
+
"pager or tell the pager to allow control",
|
608
|
+
"characters.") do |value|
|
609
|
+
options[:formatter] = RDoc::RI::Formatter.for value
|
610
|
+
end
|
611
|
+
|
612
|
+
opt.separator nil
|
613
|
+
|
614
|
+
opt.on("--doc-dir=DIRNAME", "-d", Array,
|
615
|
+
"List of directories from which to source",
|
616
|
+
"documentation in addition to the standard",
|
617
|
+
"directories. May be repeated.") do |value|
|
618
|
+
value.each do |dir|
|
619
|
+
unless File.directory? dir then
|
620
|
+
raise OptionParser::InvalidArgument, "#{dir} is not a directory"
|
621
|
+
end
|
622
|
+
|
623
|
+
options[:extra_doc_dirs] << File.expand_path(dir)
|
624
|
+
end
|
625
|
+
end
|
626
|
+
|
627
|
+
opt.separator nil
|
628
|
+
|
629
|
+
opt.on("--[no-]use-cache",
|
630
|
+
"Whether or not to use ri's cache.",
|
631
|
+
"True by default.") do |value|
|
632
|
+
options[:use_cache] = value
|
633
|
+
end
|
634
|
+
|
635
|
+
opt.separator nil
|
636
|
+
|
637
|
+
opt.on("--no-standard-docs",
|
638
|
+
"Do not include documentation from",
|
639
|
+
"the Ruby standard library, site_lib,",
|
640
|
+
"installed gems, or ~/.rdoc.",
|
641
|
+
"Equivalent to specifying",
|
642
|
+
"the options --no-system, --no-site, --no-gems,",
|
643
|
+
"and --no-home") do
|
644
|
+
options[:use_system] = false
|
645
|
+
options[:use_site] = false
|
646
|
+
options[:use_gems] = false
|
647
|
+
options[:use_home] = false
|
648
|
+
end
|
649
|
+
|
650
|
+
opt.separator nil
|
651
|
+
|
652
|
+
opt.on("--[no-]system",
|
653
|
+
"Include documentation from Ruby's standard",
|
654
|
+
"library. Defaults to true.") do |value|
|
655
|
+
options[:use_system] = value
|
656
|
+
end
|
657
|
+
|
658
|
+
opt.separator nil
|
659
|
+
|
660
|
+
opt.on("--[no-]site",
|
661
|
+
"Include documentation from libraries",
|
662
|
+
"installed in site_lib.",
|
663
|
+
"Defaults to true.") do |value|
|
664
|
+
options[:use_site] = value
|
665
|
+
end
|
666
|
+
|
667
|
+
opt.separator nil
|
668
|
+
|
669
|
+
opt.on("--[no-]gems",
|
670
|
+
"Include documentation from RubyGems.",
|
671
|
+
"Defaults to true.") do |value|
|
672
|
+
options[:use_gems] = value
|
673
|
+
end
|
674
|
+
|
675
|
+
opt.separator nil
|
676
|
+
|
677
|
+
opt.on("--[no-]home",
|
678
|
+
"Include documentation stored in ~/.rdoc.",
|
679
|
+
"Defaults to true.") do |value|
|
680
|
+
options[:use_home] = value
|
681
|
+
end
|
682
|
+
|
683
|
+
opt.separator nil
|
684
|
+
|
685
|
+
opt.on("--list-doc-dirs",
|
686
|
+
"List the directories from which ri will",
|
687
|
+
"source documentation on stdout and exit.") do
|
688
|
+
options[:list_doc_dirs] = true
|
689
|
+
end
|
690
|
+
|
691
|
+
opt.separator nil
|
692
|
+
|
693
|
+
opt.on("--no-pager", "-T",
|
694
|
+
"Send output directly to stdout,",
|
695
|
+
"rather than to a pager.") do
|
696
|
+
options[:use_stdout] = true
|
697
|
+
end
|
698
|
+
|
699
|
+
opt.on("--interactive", "-i",
|
700
|
+
"This makes ri go into interactive mode.",
|
701
|
+
"When ri is in interactive mode it will",
|
702
|
+
"allow the user to disambiguate lists of",
|
703
|
+
"methods in case multiple methods match",
|
704
|
+
"against a method search string. It also",
|
705
|
+
"will allow the user to enter in a method",
|
706
|
+
"name (with auto-completion, if readline",
|
707
|
+
"is supported) when viewing a class.") do
|
708
|
+
options[:interactive] = true
|
709
|
+
end
|
710
|
+
|
711
|
+
opt.separator nil
|
712
|
+
|
713
|
+
opt.on("--width=WIDTH", "-w", OptionParser::DecimalInteger,
|
714
|
+
"Set the width of the output.") do |value|
|
715
|
+
options[:width] = value
|
716
|
+
end
|
717
|
+
end
|
718
|
+
|
719
|
+
argv = ENV['RI'].to_s.split.concat argv
|
720
|
+
|
721
|
+
opts.parse! argv
|
722
|
+
|
723
|
+
options[:names] = argv
|
724
|
+
|
725
|
+
options[:formatter] ||= RDoc::RI::Formatter.for('plain')
|
726
|
+
options[:use_stdout] ||= !$stdout.tty?
|
727
|
+
options[:use_stdout] ||= options[:interactive]
|
728
|
+
options[:width] ||= 72
|
729
|
+
|
730
|
+
options
|
731
|
+
|
732
|
+
rescue OptionParser::InvalidArgument, OptionParser::InvalidOption => e
|
733
|
+
puts opts
|
734
|
+
puts
|
735
|
+
puts e
|
736
|
+
# exit 1
|
737
|
+
end
|
738
|
+
|
739
|
+
end
|
740
|
+
|
741
|
+
|
742
|
+
class Object
|
743
|
+
# def help
|
744
|
+
# CodeRunner.ri(self.to_s)
|
745
|
+
# end
|
746
|
+
def self.help(meth_or_const=nil)
|
747
|
+
join = ""
|
748
|
+
if meth_or_const
|
749
|
+
if self.constants.include? meth_or_const.to_sym
|
750
|
+
join = "::"
|
751
|
+
elsif self.methods.include? meth_or_const.to_sym
|
752
|
+
join = "."
|
753
|
+
elsif self.instance_methods.include? meth_or_const.to_sym
|
754
|
+
join = "#"
|
755
|
+
end
|
756
|
+
end
|
757
|
+
CodeRunner.reference("#{self.to_s}#{join}#{meth_or_const}")
|
758
|
+
end
|
759
|
+
end
|
760
|
+
|
761
|
+
class Module
|
762
|
+
|
763
|
+
def help(meth_or_const=nil)
|
764
|
+
join = ""
|
765
|
+
if meth_or_const
|
766
|
+
if self.constants.include? meth_or_const.to_sym
|
767
|
+
join = "::"
|
768
|
+
elsif self.methods.include? meth_or_const.to_sym
|
769
|
+
join = "."
|
770
|
+
elsif self.instance_methods.include? meth_or_const.to_sym
|
771
|
+
join = "#"
|
772
|
+
end
|
773
|
+
end
|
774
|
+
CodeRunner.reference("#{self.to_s}#{join}#{meth_or_const}")
|
775
|
+
end
|
776
|
+
end
|