2011-02-19 05:21:13 +00:00
|
|
|
# (C) John Mair (banisterfiend) 2011
|
2010-12-08 13:49:28 +00:00
|
|
|
# MIT License
|
|
|
|
|
2011-05-20 14:50:55 +00:00
|
|
|
class Pry
|
|
|
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
|
|
|
DEFAULT_HOOKS = {
|
|
|
|
:before_session => proc do |out, target|
|
|
|
|
# ensure we're actually in a method
|
|
|
|
meth_name = target.eval('__method__')
|
|
|
|
file = target.eval('__FILE__')
|
|
|
|
|
|
|
|
# /unknown/ for rbx
|
|
|
|
if file !~ /(\(.*\))|<.*>/ && file !~ /__unknown__/ && file != "" && file != "-e"
|
|
|
|
Pry.run_command "whereami 5", :output => out, :show_output => true, :context => target, :commands => Pry::Commands
|
|
|
|
end
|
|
|
|
end
|
|
|
|
}
|
|
|
|
|
|
|
|
# The default prints
|
|
|
|
DEFAULT_PRINT = proc do |output, value|
|
|
|
|
if Pry.color
|
|
|
|
output.puts "=> #{CodeRay.scan(Pry.view(value), :ruby).term}"
|
|
|
|
else
|
|
|
|
output.puts "=> #{Pry.view(value)}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Will only show the first line of the backtrace
|
|
|
|
DEFAULT_EXCEPTION_HANDLER = proc do |output, exception|
|
|
|
|
output.puts "#{exception.class}: #{exception.message}"
|
|
|
|
output.puts "from #{exception.backtrace.first}"
|
|
|
|
end
|
|
|
|
|
|
|
|
# The default prompt; includes the target and nesting level
|
|
|
|
DEFAULT_PROMPT = [
|
|
|
|
proc { |target_self, nest_level|
|
|
|
|
if nest_level == 0
|
|
|
|
"pry(#{Pry.view_clip(target_self)})> "
|
|
|
|
else
|
|
|
|
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}> "
|
|
|
|
end
|
|
|
|
},
|
|
|
|
|
|
|
|
proc { |target_self, nest_level|
|
|
|
|
if nest_level == 0
|
|
|
|
"pry(#{Pry.view_clip(target_self)})* "
|
|
|
|
else
|
|
|
|
"pry(#{Pry.view_clip(target_self)}):#{Pry.view_clip(nest_level)}* "
|
|
|
|
end
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
# A simple prompt - doesn't display target or nesting level
|
|
|
|
SIMPLE_PROMPT = [proc { ">> " }, proc { ">* " }]
|
|
|
|
|
|
|
|
SHELL_PROMPT = [
|
|
|
|
proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
|
|
|
|
proc { |target_self, _| "pry #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
|
|
|
|
]
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2010-12-18 11:21:58 +00:00
|
|
|
require "method_source"
|
2011-03-02 11:18:26 +00:00
|
|
|
require 'shellwords'
|
2011-01-10 13:54:17 +00:00
|
|
|
require "readline"
|
2011-02-27 23:00:51 +00:00
|
|
|
require "stringio"
|
2011-03-02 11:18:26 +00:00
|
|
|
require "coderay"
|
2011-04-25 20:58:06 +00:00
|
|
|
require "optparse"
|
|
|
|
require "slop"
|
|
|
|
require "rubygems/dependency_installer"
|
2011-03-02 11:18:26 +00:00
|
|
|
|
|
|
|
if RUBY_PLATFORM =~ /mswin/ || RUBY_PLATFORM =~ /mingw/
|
|
|
|
begin
|
|
|
|
require 'win32console'
|
|
|
|
rescue LoadError
|
2011-04-18 21:31:39 +00:00
|
|
|
$stderr.puts "Need to `gem install win32console`"
|
2011-03-02 11:18:26 +00:00
|
|
|
exit 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-04-24 11:56:47 +00:00
|
|
|
require "pry/version"
|
2011-05-15 09:29:14 +00:00
|
|
|
require "pry/history_array"
|
2011-04-25 20:58:06 +00:00
|
|
|
require "pry/helpers"
|
2011-04-24 14:25:07 +00:00
|
|
|
require "pry/command_set"
|
2011-04-24 11:56:47 +00:00
|
|
|
require "pry/commands"
|
2011-04-25 11:26:25 +00:00
|
|
|
require "pry/command_context"
|
2011-04-24 11:56:47 +00:00
|
|
|
require "pry/custom_completions"
|
|
|
|
require "pry/completion"
|
2011-05-15 09:58:27 +00:00
|
|
|
require "pry/plugins"
|
2011-04-24 11:56:47 +00:00
|
|
|
require "pry/core_extensions"
|
|
|
|
require "pry/pry_class"
|
|
|
|
require "pry/pry_instance"
|