mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
fix whereami for (pry) contexts
This commit is contained in:
parent
235c55d9b1
commit
9552cd0e4d
1 changed files with 29 additions and 20 deletions
|
@ -143,37 +143,46 @@ class Pry
|
|||
meth_name = "N/A"
|
||||
end
|
||||
|
||||
if file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e"
|
||||
if file != Pry.eval_path && (file =~ /(\(.*\))|<.*>/ || file == "" || file == "-e")
|
||||
raise CommandError, "Cannot find local context. Did you use `binding.pry`?"
|
||||
end
|
||||
|
||||
set_file_and_dir_locals(file)
|
||||
output.puts "\n#{text.bold('From:')} #{file} @ line #{line_num} in #{klass}##{meth_name}:\n\n"
|
||||
|
||||
unless File.readable?(file)
|
||||
raise CommandError, "Cannot open #{file.inspect} for reading."
|
||||
if file == Pry.eval_path
|
||||
f = Pry.line_buffer[1..-1]
|
||||
else
|
||||
unless File.readable?(file)
|
||||
raise CommandError, "Cannot open #{file.inspect} for reading."
|
||||
end
|
||||
f = File.open(file)
|
||||
end
|
||||
|
||||
# This method inspired by http://rubygems.org/gems/ir_b
|
||||
File.open(file).each_with_index do |line, index|
|
||||
line_n = index + 1
|
||||
next unless line_n > (line_num - i_num - 1)
|
||||
break if line_n > (line_num + i_num)
|
||||
if line_n == line_num
|
||||
code =" =>#{line_n.to_s.rjust(3)}: #{line.chomp}"
|
||||
if Pry.color
|
||||
code = CodeRay.scan(code, :ruby).term
|
||||
begin
|
||||
f.each_with_index do |line, index|
|
||||
line_n = index + 1
|
||||
next unless line_n > (line_num - i_num - 1)
|
||||
break if line_n > (line_num + i_num)
|
||||
if line_n == line_num
|
||||
code =" =>#{line_n.to_s.rjust(3)}: #{line.chomp}"
|
||||
if Pry.color
|
||||
code = CodeRay.scan(code, :ruby).term
|
||||
end
|
||||
output.puts code
|
||||
code
|
||||
else
|
||||
code = "#{line_n.to_s.rjust(6)}: #{line.chomp}"
|
||||
if Pry.color
|
||||
code = CodeRay.scan(code, :ruby).term
|
||||
end
|
||||
output.puts code
|
||||
code
|
||||
end
|
||||
output.puts code
|
||||
code
|
||||
else
|
||||
code = "#{line_n.to_s.rjust(6)}: #{line.chomp}"
|
||||
if Pry.color
|
||||
code = CodeRay.scan(code, :ruby).term
|
||||
end
|
||||
output.puts code
|
||||
code
|
||||
end
|
||||
ensure
|
||||
f.close if f.respond_to?(:close)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue