2011-06-08 10:49:35 -04:00
|
|
|
require 'pp'
|
2017-06-03 06:53:14 -04:00
|
|
|
require 'pry/forwardable'
|
2013-09-03 04:04:25 -04:00
|
|
|
require 'pry/input_lock'
|
|
|
|
require 'pry/exceptions'
|
|
|
|
require 'pry/helpers/base_helpers'
|
|
|
|
require 'pry/hooks'
|
2013-10-23 19:17:51 -04:00
|
|
|
|
2011-05-20 10:50:55 -04:00
|
|
|
class Pry
|
|
|
|
# The default hooks - display messages when beginning and ending Pry sessions.
|
2018-11-11 07:22:03 -05:00
|
|
|
DEFAULT_HOOKS = Pry::Hooks.new.add_hook(:before_session, :default) do |_out, _target, _pry_|
|
2012-03-31 17:18:03 -04:00
|
|
|
next if _pry_.quiet?
|
2018-10-14 09:44:58 -04:00
|
|
|
|
2012-12-18 03:26:51 -05:00
|
|
|
_pry_.run_command("whereami --quiet")
|
2011-10-16 21:09:12 -04:00
|
|
|
end
|
2011-05-20 10:50:55 -04:00
|
|
|
|
2011-09-07 22:17:41 -04:00
|
|
|
# The default print
|
2018-11-11 07:22:03 -05:00
|
|
|
DEFAULT_PRINT = proc do |_output, value, _pry_|
|
2014-04-30 05:08:29 -04:00
|
|
|
_pry_.pager.open do |pager|
|
2014-02-05 08:29:25 -05:00
|
|
|
pager.print _pry_.config.output_prefix
|
2013-11-09 15:53:39 -05:00
|
|
|
Pry::ColorPrinter.pp(value, pager, Pry::Terminal.width! - 1)
|
2013-11-03 19:35:33 -05:00
|
|
|
end
|
2011-05-20 10:50:55 -04:00
|
|
|
end
|
|
|
|
|
2011-09-07 03:56:23 -04: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 02:58:18 -05:00
|
|
|
output.puts value.inspect
|
2011-09-07 03:56:23 -04:00
|
|
|
rescue RescuableException
|
2012-11-08 02:58:18 -05:00
|
|
|
output.puts "unknown"
|
2011-09-07 03:56:23 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-07 23:36:24 -04:00
|
|
|
# useful when playing with truly enormous objects
|
|
|
|
CLIPPED_PRINT = proc do |output, value|
|
2014-03-16 01:58:28 -04:00
|
|
|
output.puts Pry.view_clip(value, id: true)
|
2011-09-07 23:36:24 -04:00
|
|
|
end
|
|
|
|
|
2011-05-20 10:50:55 -04:00
|
|
|
# Will only show the first line of the backtrace
|
2011-09-10 12:39:51 -04:00
|
|
|
DEFAULT_EXCEPTION_HANDLER = proc do |output, exception, _|
|
2013-01-12 14:26:02 -05: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}"
|
2016-03-01 16:59:30 -05:00
|
|
|
|
|
|
|
if exception.respond_to? :cause
|
|
|
|
cause = exception.cause
|
|
|
|
while cause
|
|
|
|
output.puts "Caused by #{cause.class}: #{cause}\n"
|
|
|
|
output.puts "from #{cause.backtrace.first}"
|
|
|
|
cause = cause.cause
|
|
|
|
end
|
|
|
|
end
|
2013-01-12 14:26:02 -05:00
|
|
|
end
|
2011-05-20 10:50:55 -04:00
|
|
|
end
|
|
|
|
|
2012-12-14 20:23:24 -05: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 10:25:09 -04:00
|
|
|
DEFAULT_CONTROL_D_HANDLER = proc do |eval_string, _pry_|
|
|
|
|
if !eval_string.empty?
|
2012-12-14 20:23:24 -05:00
|
|
|
eval_string.replace('') # Clear input buffer.
|
2011-09-27 10:25:09 -04:00
|
|
|
elsif _pry_.binding_stack.one?
|
|
|
|
_pry_.binding_stack.clear
|
|
|
|
throw(:breakout)
|
|
|
|
else
|
2012-06-27 07:54:07 -04:00
|
|
|
# Otherwise, saves current binding stack as old stack and pops last
|
|
|
|
# binding out of binding stack (the old stack still has that binding).
|
2018-11-20 04:46:08 -05:00
|
|
|
_pry_.command_state["cd"] ||= Pry::Config.from_hash({})
|
2012-12-14 20:23:24 -05:00
|
|
|
_pry_.command_state['cd'].old_stack = _pry_.binding_stack.dup
|
2012-06-27 07:54:07 -04:00
|
|
|
_pry_.binding_stack.pop
|
2011-09-27 10:25:09 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-09-17 08:42:29 -04:00
|
|
|
DEFAULT_SYSTEM = proc do |output, cmd, _|
|
2011-09-17 02:35:17 -04:00
|
|
|
if !system(cmd)
|
|
|
|
output.puts "Error: there was a problem executing system command: #{cmd}"
|
|
|
|
end
|
|
|
|
end
|
2011-05-20 10:50:55 -04:00
|
|
|
|
2012-01-23 01:33:34 -05:00
|
|
|
# This is to keep from breaking under Rails 3.2 for people who are doing that
|
|
|
|
# IRB = Pry thing.
|
2013-09-03 04:04:25 -04:00
|
|
|
module ExtendCommandBundle; end
|
2012-04-18 02:18:33 -04:00
|
|
|
end
|
|
|
|
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'method_source'
|
2011-03-02 06:18:26 -05:00
|
|
|
require 'shellwords'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'stringio'
|
2015-03-02 16:58:40 -05:00
|
|
|
require 'strscan'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'coderay'
|
2015-12-11 01:04:54 -05:00
|
|
|
require 'pry/slop'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'rbconfig'
|
2012-08-11 20:22:29 -04:00
|
|
|
require 'tempfile'
|
2013-02-17 23:43:07 -05:00
|
|
|
require 'pathname'
|
2011-03-02 06:18:26 -05:00
|
|
|
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'pry/version'
|
2018-11-22 11:37:22 -05:00
|
|
|
require 'pry/input_completer'
|
2012-12-21 03:02:13 -05:00
|
|
|
require 'pry/repl'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'pry/code'
|
2018-10-19 10:03:41 -04:00
|
|
|
require 'pry/ring'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'pry/helpers'
|
2012-12-25 07:47:33 -05:00
|
|
|
require 'pry/code_object'
|
|
|
|
require 'pry/method'
|
|
|
|
require 'pry/wrapped_module'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'pry/history'
|
|
|
|
require 'pry/command'
|
|
|
|
require 'pry/command_set'
|
|
|
|
require 'pry/commands'
|
|
|
|
require 'pry/plugins'
|
|
|
|
require 'pry/core_extensions'
|
2018-10-28 05:45:29 -04:00
|
|
|
require 'pry/basic_object'
|
2018-11-10 15:20:45 -05:00
|
|
|
require "pry/prompt"
|
2018-11-17 19:31:33 -05:00
|
|
|
require 'pry/config/lazy'
|
2018-10-28 05:45:29 -04:00
|
|
|
require 'pry/config/behavior'
|
|
|
|
require 'pry/config/convenience'
|
|
|
|
require 'pry/config'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'pry/pry_class'
|
|
|
|
require 'pry/pry_instance'
|
|
|
|
require 'pry/cli'
|
2013-10-29 00:36:00 -04:00
|
|
|
require 'pry/color_printer'
|
2012-08-18 17:18:54 -04:00
|
|
|
require 'pry/pager'
|
2013-01-30 22:14:06 -05:00
|
|
|
require 'pry/terminal'
|
2012-12-29 17:34:59 -05:00
|
|
|
require 'pry/editor'
|
2013-01-08 17:24:53 -05:00
|
|
|
require 'pry/rubygem'
|
2014-01-20 03:20:28 -05:00
|
|
|
require "pry/indent"
|
2014-03-09 20:28:12 -04:00
|
|
|
require "pry/last_exception"
|
2014-03-19 12:13:20 -04:00
|
|
|
require "pry/inspector"
|
2014-04-27 20:28:56 -04:00
|
|
|
require 'pry/object_path'
|
2014-05-01 04:10:10 -04:00
|
|
|
require 'pry/output'
|