2013-04-06 15:50:17 +00:00
|
|
|
# (C) John Mair (banisterfiend) 2013
|
2010-12-08 13:49:28 +00:00
|
|
|
# MIT License
|
2011-10-08 21:12:25 +00:00
|
|
|
#
|
2011-06-08 14:49:35 +00:00
|
|
|
require 'pp'
|
2013-09-03 08:04:25 +00:00
|
|
|
|
|
|
|
require 'pry/input_lock'
|
|
|
|
require 'pry/exceptions'
|
|
|
|
require 'pry/helpers/base_helpers'
|
|
|
|
require 'pry/hooks'
|
2013-12-12 03:01:04 +00:00
|
|
|
require 'forwardable'
|
2013-10-23 23:17:51 +00:00
|
|
|
|
2011-05-20 14:50:55 +00:00
|
|
|
class Pry
|
|
|
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
2011-11-15 13:49:11 +00:00
|
|
|
DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |out, target, _pry_|
|
2012-03-31 21:18:03 +00:00
|
|
|
next if _pry_.quiet?
|
2012-12-18 08:26:51 +00:00
|
|
|
_pry_.run_command("whereami --quiet")
|
2011-10-17 01:09:12 +00:00
|
|
|
end
|
2011-05-20 14:50:55 +00:00
|
|
|
|
2011-09-08 02:17:41 +00:00
|
|
|
# The default print
|
2014-02-05 13:29:25 +00:00
|
|
|
DEFAULT_PRINT = proc do |output, value, _pry_|
|
2014-04-30 09:08:29 +00:00
|
|
|
_pry_.pager.open do |pager|
|
2014-02-05 13:29:25 +00:00
|
|
|
pager.print _pry_.config.output_prefix
|
2013-11-09 20:53:39 +00:00
|
|
|
Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
|
2013-11-04 00:35:33 +00:00
|
|
|
end
|
2011-05-20 14:50:55 +00:00
|
|
|
end
|
|
|
|
|
2011-09-07 07:56:23 +00:00
|
|
|
# may be convenient when working with enormous objects and
|
|
|
|
# pretty_print is too slow
|
|
|
|
SIMPLE_PRINT = proc do |output, value|
|
|
|
|
begin
|
2012-11-08 07:58:18 +00:00
|
|
|
output.puts value.inspect
|
2011-09-07 07:56:23 +00:00
|
|
|
rescue RescuableException
|
2012-11-08 07:58:18 +00:00
|
|
|
output.puts "unknown"
|
2011-09-07 07:56:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-08 03:36:24 +00:00
|
|
|
# useful when playing with truly enormous objects
|
|
|
|
CLIPPED_PRINT = proc do |output, value|
|
2014-03-16 05:58:28 +00:00
|
|
|
output.puts Pry.view_clip(value, id: true)
|
2011-09-08 03:36:24 +00:00
|
|
|
end
|
|
|
|
|
2011-05-20 14:50:55 +00:00
|
|
|
# Will only show the first line of the backtrace
|
2011-09-10 16:39:51 +00:00
|
|
|
DEFAULT_EXCEPTION_HANDLER = proc do |output, exception, _|
|
2013-01-12 19:26:02 +00:00
|
|
|
if UserError === exception && SyntaxError === exception
|
|
|
|
output.puts "SyntaxError: #{exception.message.sub(/.*syntax error, */m, '')}"
|
|
|
|
else
|
|
|
|
output.puts "#{exception.class}: #{exception.message}"
|
|
|
|
output.puts "from #{exception.backtrace.first}"
|
|
|
|
end
|
2011-05-20 14:50:55 +00:00
|
|
|
end
|
|
|
|
|
2012-08-22 19:12:31 +00:00
|
|
|
DEFAULT_PROMPT_NAME = 'pry'
|
|
|
|
|
2011-05-20 14:50:55 +00:00
|
|
|
# The default prompt; includes the target and nesting level
|
|
|
|
DEFAULT_PROMPT = [
|
2011-09-27 14:25:09 +00:00
|
|
|
proc { |target_self, nest_level, pry|
|
2014-04-03 04:37:21 +00:00
|
|
|
"[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}> "
|
2011-09-08 03:36:24 +00:00
|
|
|
},
|
|
|
|
|
2011-09-27 14:25:09 +00:00
|
|
|
proc { |target_self, nest_level, pry|
|
2014-04-03 04:37:21 +00:00
|
|
|
"[#{pry.input_array.size}] #{pry.config.prompt_name}(#{Pry.view_clip(target_self)})#{":#{nest_level}" unless nest_level.zero?}* "
|
2011-09-08 03:36:24 +00:00
|
|
|
}
|
2011-08-29 14:21:51 +00:00
|
|
|
]
|
2011-09-08 03:36:24 +00:00
|
|
|
|
2013-05-04 08:21:16 +00:00
|
|
|
DEFAULT_PROMPT_SAFE_OBJECTS = [String, Numeric, Symbol, nil, true, false]
|
|
|
|
|
2011-05-20 14:50:55 +00:00
|
|
|
# A simple prompt - doesn't display target or nesting level
|
2011-07-26 17:16:25 +00:00
|
|
|
SIMPLE_PROMPT = [proc { ">> " }, proc { " | " }]
|
2011-05-20 14:50:55 +00:00
|
|
|
|
2013-12-12 22:17:21 +00:00
|
|
|
NO_PROMPT = [proc { '' }, proc { '' }]
|
|
|
|
|
2011-05-20 14:50:55 +00:00
|
|
|
SHELL_PROMPT = [
|
2014-04-30 01:04:52 +00:00
|
|
|
proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} $ " },
|
|
|
|
proc { |target_self, _, _pry_| "#{_pry_.config.prompt_name} #{Pry.view_clip(target_self)}:#{Dir.pwd} * " }
|
2011-09-07 07:56:23 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# A prompt that includes the full object path as well as
|
|
|
|
# input/output (_in_ and _out_) information. Good for navigation.
|
|
|
|
NAV_PROMPT = [
|
2014-04-30 01:04:52 +00:00
|
|
|
proc do |_, _, _pry_|
|
|
|
|
tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
|
|
|
|
"[#{_pry_.input_array.count}] (#{_pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}> "
|
2011-09-08 03:36:24 +00:00
|
|
|
end,
|
2014-04-30 01:04:52 +00:00
|
|
|
proc do |_, _, _pry_|
|
|
|
|
tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval("self")) }.join " / "
|
|
|
|
"[#{_pry_.input_array.count}] (#{ _pry_.config.prompt_name}) #{tree}: #{_pry_.binding_stack.size - 1}* "
|
2011-09-08 03:36:24 +00:00
|
|
|
end,
|
|
|
|
]
|
2011-09-07 07:56:23 +00:00
|
|
|
|
2012-12-15 01:23:24 +00:00
|
|
|
# Deal with the ^D key being pressed. Different behaviour in different cases:
|
|
|
|
# 1. In an expression behave like `!` command.
|
|
|
|
# 2. At top-level session behave like `exit` command.
|
|
|
|
# 3. In a nested session behave like `cd ..`.
|
2011-09-27 14:25:09 +00:00
|
|
|
DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
|
|
|
|
if !eval_string.empty?
|
2012-12-15 01:23:24 +00:00
|
|
|
eval_string.replace('') # Clear input buffer.
|
2011-09-27 14:25:09 +00:00
|
|
|
elsif _pry_.binding_stack.one?
|
|
|
|
_pry_.binding_stack.clear
|
|
|
|
throw(:breakout)
|
|
|
|
else
|
2012-06-27 11:54:07 +00:00
|
|
|
# Otherwise, saves current binding stack as old stack and pops last
|
|
|
|
# binding out of binding stack (the old stack still has that binding).
|
2014-01-21 10:11:42 +00:00
|
|
|
_pry_.command_state["cd"] ||= Pry::Config.from_hash({}) # FIXME
|
2012-12-15 01:23:24 +00:00
|
|
|
_pry_.command_state['cd'].old_stack = _pry_.binding_stack.dup
|
2012-06-27 11:54:07 +00:00
|
|
|
_pry_.binding_stack.pop
|
2011-09-27 14:25:09 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-17 12:42:29 +00:00
|
|
|
DEFAULT_SYSTEM = proc do |output, cmd, _|
|
2011-09-17 06:35:17 +00:00
|
|
|
if !system(cmd)
|
|
|
|
output.puts "Error: there was a problem executing system command: #{cmd}"
|
|
|
|
end
|
|
|
|
end
|
2011-05-20 14:50:55 +00:00
|
|
|
|
2012-08-13 05:41:28 +00:00
|
|
|
# Store the current working directory. This allows show-source etc. to work if
|
|
|
|
# your process has changed directory since boot. [Issue #675]
|
|
|
|
INITIAL_PWD = Dir.pwd
|
|
|
|
|
2012-01-23 06:33:34 +00:00
|
|
|
# This is to keep from breaking under Rails 3.2 for people who are doing that
|
|
|
|
# IRB = Pry thing.
|
2013-09-03 08:04:25 +00:00
|
|
|
module ExtendCommandBundle; end
|
2012-04-18 06:18:33 +00:00
|
|
|
end
|
|
|
|
|
2012-08-18 21:18:54 +00:00
|
|
|
require 'method_source'
|
2011-03-02 11:18:26 +00:00
|
|
|
require 'shellwords'
|
2012-08-18 21:18:54 +00:00
|
|
|
require 'stringio'
|
|
|
|
require 'coderay'
|
|
|
|
require 'slop'
|
|
|
|
require 'rbconfig'
|
2012-08-12 00:22:29 +00:00
|
|
|
require 'tempfile'
|
2013-02-18 04:43:07 +00:00
|
|
|
require 'pathname'
|
2011-03-02 11:18:26 +00:00
|
|
|
|
2012-08-18 21:18:54 +00:00
|
|
|
require 'pry/version'
|
2012-12-21 08:02:13 +00:00
|
|
|
require 'pry/repl'
|
2012-08-18 21:18:54 +00:00
|
|
|
require 'pry/rbx_path'
|
|
|
|
require 'pry/code'
|
|
|
|
require 'pry/history_array'
|
|
|
|
require 'pry/helpers'
|
2012-12-25 12:47:33 +00:00
|
|
|
require 'pry/code_object'
|
|
|
|
require 'pry/method'
|
|
|
|
require 'pry/wrapped_module'
|
2012-08-18 21:18:54 +00:00
|
|
|
require 'pry/history'
|
|
|
|
require 'pry/command'
|
|
|
|
require 'pry/command_set'
|
|
|
|
require 'pry/commands'
|
|
|
|
require 'pry/plugins'
|
|
|
|
require 'pry/core_extensions'
|
|
|
|
require 'pry/pry_class'
|
|
|
|
require 'pry/pry_instance'
|
|
|
|
require 'pry/cli'
|
2013-10-29 04:36:00 +00:00
|
|
|
require 'pry/color_printer'
|
2012-08-18 21:18:54 +00:00
|
|
|
require 'pry/pager'
|
2013-01-31 03:14:06 +00:00
|
|
|
require 'pry/terminal'
|
2012-12-29 22:34:59 +00:00
|
|
|
require 'pry/editor'
|
2013-01-08 22:24:53 +00:00
|
|
|
require 'pry/rubygem'
|
2014-01-20 08:20:28 +00:00
|
|
|
require "pry/indent"
|
2014-03-10 00:28:12 +00:00
|
|
|
require "pry/last_exception"
|
2014-03-19 13:06:26 +00:00
|
|
|
require "pry/prompt"
|
2014-03-19 16:13:20 +00:00
|
|
|
require "pry/inspector"
|
2014-04-28 00:28:56 +00:00
|
|
|
require 'pry/object_path'
|
2014-05-01 08:10:10 +00:00
|
|
|
require 'pry/output'
|