pry 0.9.0pre3-java → 0.9.4pre2-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/CHANGELOG +84 -6
- data/CONTRIBUTORS +13 -0
- data/README.markdown +23 -183
- data/Rakefile +22 -19
- data/TODO +36 -6
- data/bin/pry +12 -1
- data/lib/pry.rb +60 -12
- data/lib/pry/command_context.rb +21 -0
- data/lib/pry/command_processor.rb +62 -16
- data/lib/pry/command_set.rb +25 -11
- data/lib/pry/commands.rb +0 -3
- data/lib/pry/completion.rb +6 -6
- data/lib/pry/config.rb +25 -5
- data/lib/pry/default_commands/basic.rb +27 -6
- data/lib/pry/default_commands/context.rb +84 -35
- data/lib/pry/default_commands/documentation.rb +69 -31
- data/lib/pry/default_commands/easter_eggs.rb +5 -0
- data/lib/pry/default_commands/input.rb +193 -56
- data/lib/pry/default_commands/introspection.rb +98 -50
- data/lib/pry/default_commands/ls.rb +51 -21
- data/lib/pry/default_commands/shell.rb +57 -13
- data/lib/pry/extended_commands/experimental.rb +0 -32
- data/lib/pry/extended_commands/user_command_api.rb +33 -2
- data/lib/pry/helpers/base_helpers.rb +30 -10
- data/lib/pry/helpers/command_helpers.rb +75 -16
- data/lib/pry/helpers/text.rb +12 -11
- data/lib/pry/history.rb +61 -0
- data/lib/pry/plugins.rb +23 -12
- data/lib/pry/pry_class.rb +51 -50
- data/lib/pry/pry_instance.rb +129 -119
- data/lib/pry/version.rb +1 -1
- data/pry.gemspec +46 -0
- data/test/helper.rb +37 -3
- data/test/test_command_processor.rb +62 -19
- data/test/test_command_set.rb +40 -2
- data/test/test_completion.rb +27 -0
- data/test/test_default_commands/test_context.rb +185 -1
- data/test/test_default_commands/test_documentation.rb +10 -0
- data/test/test_default_commands/test_input.rb +207 -11
- data/test/test_default_commands/test_introspection.rb +20 -1
- data/test/test_default_commands/test_shell.rb +18 -0
- data/test/test_pry.rb +261 -45
- data/test/test_pry_history.rb +82 -0
- data/test/test_pry_output.rb +44 -0
- data/test/test_special_locals.rb +35 -0
- metadata +185 -159
@@ -3,6 +3,41 @@ class Pry
|
|
3
3
|
|
4
4
|
Ls = Pry::CommandSet.new do
|
5
5
|
|
6
|
+
helpers do
|
7
|
+
def should_trim?(target, options)
|
8
|
+
if target.eval('self').is_a? Module
|
9
|
+
options[:e] || target.eval('self') >= Object
|
10
|
+
else
|
11
|
+
options[:e]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def trim_methods(target, options, visibility)
|
16
|
+
if should_trim?(target, options)
|
17
|
+
[]
|
18
|
+
else
|
19
|
+
Object.send("#{visibility}_instance_methods")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def ls_color_map
|
24
|
+
{
|
25
|
+
"local variables" => :bright_red,
|
26
|
+
"instance variables" => :bright_blue,
|
27
|
+
"class variables" => :blue,
|
28
|
+
"global variables" => :bright_magenta,
|
29
|
+
"just singleton methods" => :green,
|
30
|
+
"public methods" => :green,
|
31
|
+
"private methods" => :green,
|
32
|
+
"protected methods" => :green,
|
33
|
+
"public instance methods" => :bright_green,
|
34
|
+
"private instance methods" => :bright_green,
|
35
|
+
"protected instance methods" => :bright_green,
|
36
|
+
"constants" => :red
|
37
|
+
}
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
6
41
|
command "ls", "Show the list of vars and methods in the current scope. Type `ls --help` for more info." do |*args|
|
7
42
|
options = {}
|
8
43
|
# Set target local to the default -- note that we can set a different target for
|
@@ -59,10 +94,14 @@ Shows local and instance variables by default.
|
|
59
94
|
options[:j] = true
|
60
95
|
end
|
61
96
|
|
62
|
-
opts.on("-s", "--super", "Include superclass entries (relevant to constant and methods options).") do
|
97
|
+
opts.on("-s", "--super", "Include superclass entries excluding Object (relevant to constant and methods options).") do
|
63
98
|
options[:s] = true
|
64
99
|
end
|
65
100
|
|
101
|
+
opts.on("-e", "--everything", "Include superclass entries including Object (must be combined with -s switch).") do
|
102
|
+
options[:e] = true
|
103
|
+
end
|
104
|
+
|
66
105
|
opts.on("-a", "--all", "Display all types of entries.") do
|
67
106
|
options[:a] = true
|
68
107
|
end
|
@@ -126,19 +165,19 @@ Shows local and instance variables by default.
|
|
126
165
|
|
127
166
|
info["global variables"] = [Array(target.eval("global_variables")).sort, i += 1] if options[:g] || options[:a]
|
128
167
|
|
129
|
-
info["public methods"] = [Array(target.eval("public_methods(#{options[:s]})")).uniq.sort, i += 1] if (options[:m] && options[:P]) || options[:a]
|
168
|
+
info["public methods"] = [Array(target.eval("public_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :public), i += 1] if (options[:m] && options[:P]) || options[:a]
|
130
169
|
|
131
|
-
info["protected methods"] = [Array(target.eval("protected_methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:r]) || options[:a]
|
170
|
+
info["protected methods"] = [Array(target.eval("protected_methods(#{options[:s]})")).sort - trim_methods(target, options, :protected), i += 1] if (options[:m] && options[:r]) || options[:a]
|
132
171
|
|
133
|
-
info["private methods"] = [Array(target.eval("private_methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:p]) || options[:a]
|
172
|
+
info["private methods"] = [Array(target.eval("private_methods(#{options[:s]})")).sort - trim_methods(target, options, :private), i += 1] if (options[:m] && options[:p]) || options[:a]
|
134
173
|
|
135
|
-
info["just singleton methods"] = [Array(target.eval("methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:j])
|
174
|
+
info["just singleton methods"] = [Array(target.eval("methods(#{options[:s]})")).sort, i += 1] if (options[:m] && options[:j]) && !options[:a]
|
136
175
|
|
137
|
-
info["public instance methods"] = [Array(target.eval("public_instance_methods(#{options[:s]})")).uniq.sort, i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:P]) || options[:a])
|
176
|
+
info["public instance methods"] = [Array(target.eval("public_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :public), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:P]) || options[:a])
|
138
177
|
|
139
|
-
info["protected instance methods"] = [Array(target.eval("protected_instance_methods(#{options[:s]})")).uniq.sort, i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:r]) || options[:a])
|
178
|
+
info["protected instance methods"] = [Array(target.eval("protected_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :protected), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:r]) || options[:a])
|
140
179
|
|
141
|
-
info["private instance methods"] = [Array(target.eval("private_instance_methods(#{options[:s]})")).uniq.sort, i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:p]) || options[:a])
|
180
|
+
info["private instance methods"] = [Array(target.eval("private_instance_methods(#{options[:s]})")).uniq.sort - trim_methods(target, options, :private), i += 1] if target_self.is_a?(Module) && ((options[:M] && options[:p]) || options[:a])
|
142
181
|
|
143
182
|
# dealing with 1.8/1.9 compatibility issues :/
|
144
183
|
csuper = options[:s]
|
@@ -159,11 +198,7 @@ Shows local and instance variables by default.
|
|
159
198
|
if !v.first.empty?
|
160
199
|
text << "#{k}:\n--\n"
|
161
200
|
filtered_list = v.first.grep options[:grep]
|
162
|
-
|
163
|
-
text << CodeRay.scan(Pry.view(filtered_list), :ruby).term + "\n"
|
164
|
-
else
|
165
|
-
text << Pry.view(filtered_list) + "\n"
|
166
|
-
end
|
201
|
+
text << text().bright_green(filtered_list.join(" "))
|
167
202
|
text << "\n\n"
|
168
203
|
end
|
169
204
|
end
|
@@ -176,14 +211,9 @@ Shows local and instance variables by default.
|
|
176
211
|
|
177
212
|
# plain
|
178
213
|
else
|
179
|
-
list = info.
|
180
|
-
list = list.
|
181
|
-
|
182
|
-
if Pry.color
|
183
|
-
text << CodeRay.scan(list.inspect, :ruby).term + "\n"
|
184
|
-
else
|
185
|
-
text << list.inspect + "\n"
|
186
|
-
end
|
214
|
+
list = info.sort_by { |k, v| v.last }.map { |k, v| [k, [v.first.grep(options[:grep])], v.last] }
|
215
|
+
list = list.each { |k, v| text << text().send(ls_color_map[k], v.first.join(" ")); text << " " }
|
216
|
+
|
187
217
|
if !options[:f]
|
188
218
|
stagger_output(text)
|
189
219
|
else
|
@@ -3,7 +3,7 @@ class Pry
|
|
3
3
|
|
4
4
|
Shell = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>") do |cmd|
|
6
|
+
command(/\.(.*)/, "All text following a '.' is forwarded to the shell.", :listing => ".<shell command>", :use_prefix => false) do |cmd|
|
7
7
|
if cmd =~ /^cd\s+(.+)/i
|
8
8
|
dest = $1
|
9
9
|
begin
|
@@ -20,15 +20,15 @@ class Pry
|
|
20
20
|
end
|
21
21
|
|
22
22
|
command "shell-mode", "Toggle shell mode. Bring in pwd prompt and file completion." do
|
23
|
-
case
|
23
|
+
case _pry_.prompt
|
24
24
|
when Pry::SHELL_PROMPT
|
25
|
-
|
26
|
-
|
25
|
+
_pry_.pop_prompt
|
26
|
+
_pry_.custom_completions = Pry::DEFAULT_CUSTOM_COMPLETIONS
|
27
27
|
else
|
28
|
-
|
29
|
-
|
28
|
+
_pry_.push_prompt Pry::SHELL_PROMPT
|
29
|
+
_pry_.custom_completions = Pry::FILE_COMPLETIONS
|
30
30
|
Readline.completion_proc = Pry::InputCompleter.build_completion_proc target,
|
31
|
-
|
31
|
+
_pry_.instance_eval(&Pry::FILE_COMPLETIONS)
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
@@ -37,6 +37,7 @@ class Pry
|
|
37
37
|
command "cat", "Show output of file FILE. Type `cat --help` for more information." do |*args|
|
38
38
|
start_line = 0
|
39
39
|
end_line = -1
|
40
|
+
file_name = nil
|
40
41
|
|
41
42
|
opts = Slop.parse!(args) do |opt|
|
42
43
|
opt.on :s, :start, "Start line (defaults to start of file)Line 1 is the first line.", true, :as => Integer do |line|
|
@@ -47,6 +48,20 @@ class Pry
|
|
47
48
|
end_line = line - 1
|
48
49
|
end
|
49
50
|
|
51
|
+
opt.on :ex, "Show a window of N lines either side of the last exception (defaults to 5).", :optional => true, :as => Integer do |window_size|
|
52
|
+
window_size ||= 5
|
53
|
+
ex = _pry_.last_exception
|
54
|
+
next if !ex
|
55
|
+
start_line = (ex.line - 1) - window_size
|
56
|
+
start_line = start_line < 0 ? 0 : start_line
|
57
|
+
end_line = (ex.line - 1) + window_size
|
58
|
+
if is_core_rbx_path?(ex.file)
|
59
|
+
file_name = rbx_convert_path_to_full(ex.file)
|
60
|
+
else
|
61
|
+
file_name = ex.file
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
50
65
|
opt.on :l, "line-numbers", "Show line numbers."
|
51
66
|
opt.on :t, :type, "The specific file type for syntax higlighting (e.g ruby, python)", true, :as => Symbol
|
52
67
|
opt.on :f, :flood, "Do not use a pager to view text longer than one screen."
|
@@ -57,21 +72,50 @@ class Pry
|
|
57
72
|
|
58
73
|
next if opts.help?
|
59
74
|
|
60
|
-
|
75
|
+
if opts.ex?
|
76
|
+
next output.puts "No Exception or Exception has no associated file." if file_name.nil?
|
77
|
+
next output.puts "Cannot cat exceptions raised in REPL." if Pry.eval_path == file_name
|
78
|
+
else
|
79
|
+
file_name = args.shift
|
80
|
+
end
|
81
|
+
|
61
82
|
if !file_name
|
62
83
|
output.puts "Must provide a file name."
|
63
84
|
next
|
64
85
|
end
|
65
86
|
|
66
|
-
contents,
|
87
|
+
contents, _, _ = read_between_the_lines(file_name, start_line, end_line)
|
88
|
+
contents = syntax_highlight_by_file_type_or_specified(contents, file_name, opts[:type])
|
67
89
|
|
68
|
-
if
|
69
|
-
contents =
|
90
|
+
if opts.l?
|
91
|
+
contents = text.with_line_numbers contents, start_line + 1
|
92
|
+
end
|
93
|
+
|
94
|
+
# add the arrow pointing to line that caused the exception
|
95
|
+
if opts.ex?
|
96
|
+
contents = text.with_line_numbers contents, start_line + 1, :bright_red
|
97
|
+
|
98
|
+
contents = contents.lines.each_with_index.map do |line, idx|
|
99
|
+
l = idx + start_line
|
100
|
+
if l == (_pry_.last_exception.line - 1)
|
101
|
+
" =>#{line}"
|
102
|
+
else
|
103
|
+
" #{line}"
|
104
|
+
end
|
105
|
+
end.join
|
106
|
+
|
107
|
+
# header for exceptions
|
108
|
+
output.puts "\n#{Pry::Helpers::Text.bold('Exception:')} #{_pry_.last_exception.class}: #{_pry_.last_exception.message}\n--"
|
109
|
+
output.puts "#{Pry::Helpers::Text.bold('From:')} #{file_name} @ line #{_pry_.last_exception.line}\n\n"
|
70
110
|
end
|
71
111
|
|
72
112
|
set_file_and_dir_locals(file_name)
|
73
|
-
|
74
|
-
|
113
|
+
|
114
|
+
if opts.f?
|
115
|
+
output.puts contents
|
116
|
+
else
|
117
|
+
stagger_output(contents)
|
118
|
+
end
|
75
119
|
end
|
76
120
|
end
|
77
121
|
|
@@ -3,7 +3,6 @@ class Pry
|
|
3
3
|
|
4
4
|
Experimental = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
|
7
6
|
command "reload-method", "Reload the source specifically for a method", :requires_gem => "method_reload" do |meth_name|
|
8
7
|
if (meth = get_method_object(meth_name, target, {})).nil?
|
9
8
|
output.puts "Invalid method name: #{meth_name}."
|
@@ -12,37 +11,6 @@ class Pry
|
|
12
11
|
|
13
12
|
meth.reload
|
14
13
|
end
|
15
|
-
|
16
|
-
command "play", "Play a string as input" do |*args|
|
17
|
-
Slop.parse!(args) do |opt|
|
18
|
-
opt.banner "Usage: play-method [--replay START..END] [--clear] [--grep PATTERN] [--help]\n"
|
19
|
-
|
20
|
-
opt.on :l, :lines, 'The line (or range of lines) to replay.', true, :as => Range
|
21
|
-
opt.on :m, :method, 'Play a method.', true do |meth_name|
|
22
|
-
if (meth = get_method_object(meth_name, target, {})).nil?
|
23
|
-
output.puts "Invalid method name: #{meth_name}."
|
24
|
-
next
|
25
|
-
end
|
26
|
-
code, code_type = code_and_code_type_for(meth)
|
27
|
-
next if !code
|
28
|
-
|
29
|
-
range = opt.l? ? opt[:l] : (0..-1)
|
30
|
-
|
31
|
-
Pry.active_instance.input = StringIO.new(code[range])
|
32
|
-
end
|
33
|
-
|
34
|
-
opt.on :f, "file", 'The line (or range of lines) to replay.', true do |file_name|
|
35
|
-
text = File.read File.expand_path(file_name)
|
36
|
-
range = opt.l? ? opt[:l] : (0..-1)
|
37
|
-
|
38
|
-
Pry.active_instance.input = StringIO.new(text[range])
|
39
|
-
end
|
40
|
-
|
41
|
-
opt.on :h, :help, "This message." do
|
42
|
-
output.puts opt
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
14
|
end
|
47
15
|
end
|
48
16
|
end
|
@@ -3,11 +3,11 @@ class Pry
|
|
3
3
|
|
4
4
|
UserCommandAPI = Pry::CommandSet.new do
|
5
5
|
|
6
|
-
command "define-command", "
|
6
|
+
command "define-command", "Define a command in the session, use same syntax as `command` method for command API" do |arg|
|
7
7
|
next output.puts("Provide an arg!") if arg.nil?
|
8
8
|
|
9
9
|
prime_string = "command #{arg_string}\n"
|
10
|
-
command_string =
|
10
|
+
command_string = _pry_.r(target, prime_string)
|
11
11
|
|
12
12
|
eval_string.replace <<-HERE
|
13
13
|
_pry_.commands.instance_eval do
|
@@ -17,6 +17,37 @@ class Pry
|
|
17
17
|
|
18
18
|
end
|
19
19
|
|
20
|
+
command "reload-command", "Reload a command. reload-command CMD_NAME CMD_SET" do |command_name, set_name|
|
21
|
+
next output.puts "Must provide command name" if command_name.nil?
|
22
|
+
next output.puts "Must provide command set name" if set_name.nil?
|
23
|
+
|
24
|
+
cmd = Pry.config.commands.commands[command_name]
|
25
|
+
file_name = cmd.block.source_location.first
|
26
|
+
|
27
|
+
silence_warnings do
|
28
|
+
load file_name
|
29
|
+
end
|
30
|
+
Pry.config.commands.import target.eval(set_name)
|
31
|
+
_pry_.commands.import target.eval(set_name)
|
32
|
+
set_file_and_dir_locals(file_name)
|
33
|
+
end
|
34
|
+
|
35
|
+
command "edit-command", "Edit a command. edit-command CMD_NAME CMD_SET" do |command_name, set_name|
|
36
|
+
next output.puts "Must provide command name" if command_name.nil?
|
37
|
+
next output.puts "Must provide a command set name" if set_name.nil?
|
38
|
+
|
39
|
+
cmd = Pry.config.commands.commands[command_name]
|
40
|
+
file_name = cmd.block.source_location.first
|
41
|
+
|
42
|
+
invoke_editor(*cmd.block.source_location)
|
43
|
+
silence_warnings do
|
44
|
+
load file_name
|
45
|
+
end
|
46
|
+
Pry.config.commands.import target.eval(set_name)
|
47
|
+
_pry_.commands.import target.eval(set_name)
|
48
|
+
set_file_and_dir_locals(file_name)
|
49
|
+
end
|
50
|
+
|
20
51
|
end
|
21
52
|
end
|
22
53
|
end
|
@@ -2,6 +2,7 @@ class Pry
|
|
2
2
|
module Helpers
|
3
3
|
|
4
4
|
module BaseHelpers
|
5
|
+
|
5
6
|
module_function
|
6
7
|
|
7
8
|
def silence_warnings
|
@@ -35,10 +36,11 @@ class Pry
|
|
35
36
|
|
36
37
|
def set_file_and_dir_locals(file_name)
|
37
38
|
return if !target
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
39
|
+
_pry_.last_file = File.expand_path(file_name)
|
40
|
+
_pry_.inject_local("_file_", _pry_.last_file, target)
|
41
|
+
|
42
|
+
_pry_.last_dir = File.dirname(_pry_.last_file)
|
43
|
+
_pry_.inject_local("_dir_", _pry_.last_dir, target)
|
42
44
|
end
|
43
45
|
|
44
46
|
def stub_proc(name, options)
|
@@ -63,8 +65,16 @@ class Pry
|
|
63
65
|
end
|
64
66
|
end
|
65
67
|
|
68
|
+
def colorize_code(code)
|
69
|
+
if Pry.color
|
70
|
+
CodeRay.scan(code, :ruby).term
|
71
|
+
else
|
72
|
+
code
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
66
76
|
def highlight(string, regexp, highlight_color=:bright_yellow)
|
67
|
-
|
77
|
+
string.gsub(regexp) { |match| "<#{highlight_color}>#{match}</#{highlight_color}>" }
|
68
78
|
end
|
69
79
|
|
70
80
|
# formatting
|
@@ -77,8 +87,18 @@ class Pry
|
|
77
87
|
27
|
78
88
|
end
|
79
89
|
|
90
|
+
# are we on Jruby platform?
|
91
|
+
def jruby?
|
92
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /jruby/
|
93
|
+
end
|
94
|
+
|
95
|
+
# are we on rbx platform?
|
96
|
+
def rbx?
|
97
|
+
defined?(RUBY_ENGINE) && RUBY_ENGINE =~ /rbx/
|
98
|
+
end
|
99
|
+
|
80
100
|
# a simple pager for systems without `less`. A la windows.
|
81
|
-
def simple_pager(text)
|
101
|
+
def simple_pager(text, output=output())
|
82
102
|
text_array = text.lines.to_a
|
83
103
|
text_array.each_slice(page_size) do |chunk|
|
84
104
|
output.puts chunk.join
|
@@ -93,20 +113,20 @@ class Pry
|
|
93
113
|
# Try to use `less` for paging, if it fails then use
|
94
114
|
# simple_pager. Also do not page if Pry.pager is falsey
|
95
115
|
# FIXME! Another JRuby hack
|
96
|
-
def stagger_output(text)
|
116
|
+
def stagger_output(text, output=output())
|
97
117
|
if text.lines.count < page_size || !Pry.pager
|
98
118
|
output.puts text
|
99
119
|
return
|
100
120
|
end
|
101
121
|
|
102
122
|
# FIXME! Another JRuby hack
|
103
|
-
if
|
104
|
-
simple_pager(text)
|
123
|
+
if jruby?
|
124
|
+
simple_pager(text, output)
|
105
125
|
else
|
106
126
|
lesspipe { |less| less.puts text }
|
107
127
|
end
|
108
128
|
rescue Errno::ENOENT
|
109
|
-
simple_pager(text)
|
129
|
+
simple_pager(text, output)
|
110
130
|
rescue Errno::EPIPE
|
111
131
|
end
|
112
132
|
|
@@ -15,9 +15,9 @@ class Pry
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# if start_line is not false then add line numbers starting with start_line
|
18
|
-
def render_output(should_flood, start_line, text)
|
18
|
+
def render_output(should_flood, start_line, text, color=:blue)
|
19
19
|
if start_line
|
20
|
-
text = Pry::Helpers::Text.with_line_numbers text, start_line
|
20
|
+
text = Pry::Helpers::Text.with_line_numbers text, start_line, color
|
21
21
|
end
|
22
22
|
|
23
23
|
if should_flood
|
@@ -40,11 +40,14 @@ class Pry
|
|
40
40
|
end
|
41
41
|
|
42
42
|
########### RBX HELPERS #############
|
43
|
+
def is_core_rbx_path?(path)
|
44
|
+
rbx? &&
|
45
|
+
path.start_with?("kernel")
|
46
|
+
end
|
47
|
+
|
43
48
|
def rbx_core?(meth)
|
44
|
-
defined?(RUBY_ENGINE) &&
|
45
|
-
RUBY_ENGINE =~ /rbx/ &&
|
46
49
|
meth.source_location &&
|
47
|
-
meth.source_location.first
|
50
|
+
is_core_rbx_path?(meth.source_location.first)
|
48
51
|
end
|
49
52
|
|
50
53
|
def rvm_ruby?(path)
|
@@ -70,6 +73,28 @@ class Pry
|
|
70
73
|
end
|
71
74
|
end
|
72
75
|
|
76
|
+
def rbx_convert_path_to_full(path)
|
77
|
+
if rvm_ruby?(Rubinius::BIN_PATH)
|
78
|
+
rbx_rvm_convert_path_to_full(path)
|
79
|
+
else
|
80
|
+
rbx_std_convert_path_to_full(path)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def rbx_rvm_convert_path_to_full(path)
|
85
|
+
ruby_name = File.dirname(Rubinius::BIN_PATH).split("/").last
|
86
|
+
source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name)
|
87
|
+
file_name = File.join(source_path, path)
|
88
|
+
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
89
|
+
file_name
|
90
|
+
end
|
91
|
+
|
92
|
+
def rbx_std_convert_path_to_full(path)
|
93
|
+
file_name = File.join(Rubinius::BIN_PATH, "..", path)
|
94
|
+
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
95
|
+
file_name
|
96
|
+
end
|
97
|
+
|
73
98
|
def rbx_core_path_line_for(meth)
|
74
99
|
if rvm_ruby?(Rubinius::BIN_PATH)
|
75
100
|
rvm_rbx_core_path_line_for(meth)
|
@@ -79,21 +104,14 @@ class Pry
|
|
79
104
|
end
|
80
105
|
|
81
106
|
def std_rbx_core_path_line_for(meth)
|
82
|
-
file_name
|
83
|
-
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
84
|
-
|
107
|
+
file_name = rbx_std_convert_path_to_full(meth.source_location.first)
|
85
108
|
start_line = meth.source_location.last
|
86
109
|
|
87
110
|
[file_name, start_line]
|
88
111
|
end
|
89
112
|
|
90
113
|
def rvm_rbx_core_path_line_for(meth)
|
91
|
-
|
92
|
-
source_path = File.join(File.dirname(File.dirname(File.dirname(Rubinius::BIN_PATH))), "src", ruby_name)
|
93
|
-
|
94
|
-
file_name = File.join(source_path, meth.source_location.first)
|
95
|
-
raise "Cannot find rbx core source" if !File.exists?(file_name)
|
96
|
-
|
114
|
+
file_name = rbx_rvm_convert_path_to_full(meth.source_location.first)
|
97
115
|
start_line = meth.source_location.last
|
98
116
|
|
99
117
|
[file_name, start_line]
|
@@ -255,7 +273,11 @@ class Pry
|
|
255
273
|
end
|
256
274
|
|
257
275
|
language_detected = file_type if file_type
|
258
|
-
|
276
|
+
if Pry.color
|
277
|
+
CodeRay.scan(contents, language_detected).term
|
278
|
+
else
|
279
|
+
contents
|
280
|
+
end
|
259
281
|
end
|
260
282
|
|
261
283
|
# convert negative line numbers to positive by wrapping around
|
@@ -286,7 +308,7 @@ class Pry
|
|
286
308
|
|
287
309
|
def process_yardoc_tag(comment, tag)
|
288
310
|
in_tag_block = nil
|
289
|
-
|
311
|
+
comment.lines.map do |v|
|
290
312
|
if in_tag_block && v !~ /^\S/
|
291
313
|
Pry::Helpers::Text.strip_color Pry::Helpers::Text.strip_color(v)
|
292
314
|
elsif in_tag_block
|
@@ -328,6 +350,43 @@ class Pry
|
|
328
350
|
code.sub(/\A\s*\/\*.*?\*\/\s*/m, '')
|
329
351
|
end
|
330
352
|
|
353
|
+
def invoke_editor(file, line)
|
354
|
+
if Pry.config.editor.respond_to?(:call)
|
355
|
+
editor_invocation = Pry.config.editor.call(file, line)
|
356
|
+
else
|
357
|
+
editor_invocation = "#{Pry.config.editor} #{start_line_syntax_for_editor(file, line)}"
|
358
|
+
end
|
359
|
+
|
360
|
+
if jruby?
|
361
|
+
require 'spoon'
|
362
|
+
pid = Spoon.spawnp(*editor_invocation.split)
|
363
|
+
Process.waitpid(pid)
|
364
|
+
else
|
365
|
+
run ".#{editor_invocation}"
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
def start_line_syntax_for_editor(file_name, line_number)
|
370
|
+
file_name = file_name.gsub(/\//, '\\') if RUBY_PLATFORM =~ /mswin|mingw/
|
371
|
+
|
372
|
+
case Pry.config.editor
|
373
|
+
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
374
|
+
"+#{line_number} #{file_name}"
|
375
|
+
when /^mate/, /^geany/
|
376
|
+
"-l #{line_number} #{file_name}"
|
377
|
+
when /^uedit32/
|
378
|
+
"#{file_name}/#{line_number}"
|
379
|
+
when /^jedit/
|
380
|
+
"#{file_name} +line:#{line_number}"
|
381
|
+
else
|
382
|
+
if RUBY_PLATFORM =~ /mswin|mingw/
|
383
|
+
"#{file_name}"
|
384
|
+
else
|
385
|
+
"+#{line_number} #{file_name}"
|
386
|
+
end
|
387
|
+
end
|
388
|
+
end
|
389
|
+
|
331
390
|
def prompt(message, options="Yn")
|
332
391
|
opts = options.scan(/./)
|
333
392
|
optstring = opts.join("/") # case maintained
|