2011-05-28 04:43:32 -04:00
|
|
|
require 'ostruct'
|
|
|
|
|
|
|
|
class Pry
|
|
|
|
class Config < OpenStruct
|
|
|
|
|
|
|
|
# Get/Set the object to use for input by default by all Pry instances.
|
2013-02-25 01:50:32 -05:00
|
|
|
# Pry.config.input is an option determining the input object - the object
|
|
|
|
# from which Pry retrieves its lines of input. Pry accepts any object that
|
|
|
|
# implements the readline method. This includes IO objects, StringIO,
|
|
|
|
# Readline, File and custom objects.
|
2011-05-28 04:43:32 -04:00
|
|
|
# @return [#readline] The object to use for input by default by all
|
|
|
|
# Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.input = StringIO.new("@x = 10\nexit")
|
2011-05-28 04:43:32 -04:00
|
|
|
attr_accessor :input
|
|
|
|
|
|
|
|
# Get/Set the object to use for output by default by all Pry instances.
|
2013-02-25 01:50:32 -05:00
|
|
|
# Pry.config.output is an option determining the output object - the object
|
|
|
|
# to which Pry writes its output. Pry accepts any object that implements the
|
|
|
|
# puts method. This includes IO objects, StringIO, File and custom objects.
|
2011-05-28 04:43:32 -04:00
|
|
|
# @return [#puts] The object to use for output by default by all
|
|
|
|
# Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.output = StringIO.new
|
2011-05-28 04:43:32 -04:00
|
|
|
attr_accessor :output
|
|
|
|
|
|
|
|
# Get/Set the object to use for commands by default by all Pry instances.
|
2013-02-25 01:50:32 -05:00
|
|
|
# @return [Pry::CommandBase] The object to use for commands by default by
|
|
|
|
# all Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.commands = Pry::CommandSet.new do
|
2013-02-25 01:50:32 -05:00
|
|
|
# import_from Pry::Commands, "ls"
|
|
|
|
# command "greet" do |name|
|
|
|
|
# output.puts "hello #{name}"
|
|
|
|
# end
|
|
|
|
# end
|
2011-05-28 04:43:32 -04:00
|
|
|
attr_accessor :commands
|
|
|
|
|
|
|
|
# Get/Set the Proc to use for printing by default by all Pry
|
|
|
|
# instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# Two parameters are passed to the print Proc: these are (1) the
|
2013-02-25 01:50:32 -05:00
|
|
|
# output object for the current session and (2) the expression value to
|
|
|
|
# print. It is important that you write to the output object instead of just
|
|
|
|
# stdout so that all Pry output can be redirected if necessary. This is the
|
|
|
|
# 'print' component of the REPL.
|
2011-05-28 04:43:32 -04:00
|
|
|
# @return [Proc] The Proc to use for printing by default by all
|
|
|
|
# Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.print = proc { |output, value| output.puts "=> #{value.inspect}" }
|
2011-05-28 04:43:32 -04:00
|
|
|
attr_accessor :print
|
|
|
|
|
2013-02-25 01:50:32 -05:00
|
|
|
# Pry.config.exception_handler is an option determining the exception
|
|
|
|
# handler object - the Proc responsible for dealing with exceptions raised
|
|
|
|
# by user input to the REPL. Three parameters are passed to the exception
|
|
|
|
# handler Proc: these are (1) the output object for the current session, (2)
|
|
|
|
# the exception object that was raised inside the Pry session, and (3) a
|
|
|
|
# reference to the associated Pry instance.
|
2011-05-28 04:43:32 -04:00
|
|
|
# @return [Proc] The Proc to use for printing exceptions by default by all
|
|
|
|
# Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.exception_handler = proc do |output, exception, _|
|
|
|
|
# output.puts "#{exception.class}: #{exception.message}"
|
|
|
|
# output.puts "from #{exception.backtrace.first}"
|
|
|
|
# end
|
2011-05-28 04:43:32 -04:00
|
|
|
attr_accessor :exception_handler
|
|
|
|
|
2011-09-17 21:45:46 -04:00
|
|
|
# @return [Array] The classes of exception that will not be caught by Pry.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.exception_whitelist = [SystemExit, SignalException]
|
2011-09-17 21:45:46 -04:00
|
|
|
attr_accessor :exception_whitelist
|
|
|
|
|
2013-04-25 08:29:26 -04:00
|
|
|
# Send Pry into interactive mode after finishing execution
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :exit_interactive
|
|
|
|
|
2011-10-16 02:49:33 -04:00
|
|
|
# @return [Fixnum] The number of lines of context to show before and after
|
2012-01-15 01:30:32 -05:00
|
|
|
# exceptions, etc.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.default_window_size = 10
|
2012-01-15 01:30:32 -05:00
|
|
|
attr_accessor :default_window_size
|
2011-10-16 02:49:33 -04:00
|
|
|
|
2013-02-25 01:50:32 -05:00
|
|
|
# Get/Set the `Pry::Hooks` instance that defines Pry hooks used by default
|
|
|
|
# by all Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @return [Pry::Hooks] The hooks used by default by all Pry instances.
|
2011-05-28 04:43:32 -04:00
|
|
|
# @example
|
2012-04-02 06:50:23 -04:00
|
|
|
# Pry.config.hooks = Pry::Hooks.new.add_hook(:before_session,
|
2013-02-25 01:50:32 -05:00
|
|
|
# :default) { |output, target, _pry_| output.puts "Good morning!" }
|
2012-01-23 07:10:51 -05:00
|
|
|
attr_reader :hooks
|
|
|
|
|
|
|
|
# FIXME:
|
|
|
|
# This is a hack to alert people of the new API.
|
|
|
|
# @param [Pry::Hooks] v Only accept `Pry::Hooks` now!
|
|
|
|
def hooks=(v)
|
|
|
|
if v.is_a?(Hash)
|
2012-01-24 03:44:21 -05:00
|
|
|
warn "Hash-based hooks are now deprecated! Use a `Pry::Hooks` object instead! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
|
|
|
|
@hooks = Pry::Hooks.from_hash(v)
|
|
|
|
else
|
|
|
|
@hooks = v
|
2012-01-23 07:10:51 -05:00
|
|
|
end
|
|
|
|
end
|
2011-05-28 04:43:32 -04:00
|
|
|
|
2013-02-25 01:50:32 -05:00
|
|
|
# Get the array of Procs (or single Proc) to be used for the prompts by
|
|
|
|
# default by all Pry instances. Three parameters are passed into the prompt
|
|
|
|
# procs, (1) the object that is the target of the session, (2) the current
|
|
|
|
# nesting level, and (3) a reference to the associated Pry instance. These
|
|
|
|
# objects can be used in the prompt, if desired.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @return [Array<Proc>, Proc] The array of Procs to be used for the
|
2011-05-28 04:43:32 -04:00
|
|
|
# prompts by default by all Pry instances.
|
2012-04-02 06:50:23 -04:00
|
|
|
# @example
|
|
|
|
# Pry.config.prompt = proc { |obj, nest_level, _pry_| "#{obj}:#{nest_level}> " }
|
2011-05-28 04:43:32 -04:00
|
|
|
attr_accessor :prompt
|
|
|
|
|
2013-02-25 01:50:32 -05:00
|
|
|
# The display name that is part of the prompt. Default is 'pry'. You can
|
|
|
|
# set your own name so you can identify which project your current pry
|
|
|
|
# session is using. This is useful if you have a local pryrc file in a
|
|
|
|
# Rails project for example.
|
2012-08-22 15:12:31 -04:00
|
|
|
# @return [String]
|
2013-02-25 01:50:32 -05:00
|
|
|
# @example
|
2012-08-22 15:12:31 -04:00
|
|
|
# Pry.config.prompt_name = 'my_rails_project'
|
|
|
|
attr_accessor :prompt_name
|
2013-02-25 01:50:32 -05:00
|
|
|
|
|
|
|
# The default editor to use. Defaults to $VISUAL, $EDITOR, or a sensible
|
|
|
|
# fallback for the platform. If `editor` is a String then that string is
|
|
|
|
# used as the shell command to invoke the editor. If `editor` is callable
|
|
|
|
# (e.g a Proc) then `file`, `line`, and `reloading` are passed in as
|
|
|
|
# parameters and the return value of that callable invocation is used as the
|
|
|
|
# exact shell command to invoke the editor. `reloading` indicates whether
|
|
|
|
# Pry will be reloading code after the shell command returns. Any or all of
|
|
|
|
# these parameters can be omitted from the callable's signature.
|
2011-05-28 04:43:32 -04:00
|
|
|
# @example String
|
2011-08-29 11:00:13 -04:00
|
|
|
# Pry.config.editor = "emacsclient"
|
2011-05-28 04:43:32 -04:00
|
|
|
# @example Callable
|
2011-08-29 11:00:13 -04:00
|
|
|
# Pry.config.editor = proc { |file, line| "emacsclient #{file} +#{line}" }
|
2012-04-03 22:48:09 -04:00
|
|
|
# @example Callable waiting only if reloading
|
2013-02-25 01:50:32 -05:00
|
|
|
# Pry.config.editor = proc { |file, line, reloading|
|
|
|
|
# "subl #{'--wait' if reloading} #{file}:#{line}"
|
|
|
|
# }
|
2011-05-28 04:43:32 -04:00
|
|
|
# @return [String, #call]
|
|
|
|
attr_accessor :editor
|
|
|
|
|
2011-07-26 03:34:54 -04:00
|
|
|
# A string that must precede all Pry commands (e.g., if command_prefix is
|
|
|
|
# set to "%", the "cd" command must be invoked as "%cd").
|
|
|
|
# @return [String]
|
|
|
|
attr_accessor :command_prefix
|
|
|
|
|
2011-05-28 04:43:32 -04:00
|
|
|
# @return [Boolean] Toggle Pry color on and off.
|
|
|
|
attr_accessor :color
|
|
|
|
|
|
|
|
# @return [Boolean] Toggle paging on and off.
|
|
|
|
attr_accessor :pager
|
|
|
|
|
|
|
|
# Determines whether the rc file (~/.pryrc) should be loaded.
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :should_load_rc
|
2011-05-28 07:58:27 -04:00
|
|
|
|
2012-07-03 23:09:01 -04:00
|
|
|
# Determines whether the local rc file (./.pryrc) should be loaded.
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :should_load_local_rc
|
|
|
|
|
2011-05-28 07:58:27 -04:00
|
|
|
# Determines whether plugins should be loaded.
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :should_load_plugins
|
2011-05-29 11:37:12 -04:00
|
|
|
|
2011-07-24 23:04:44 -04:00
|
|
|
# Determines whether to load files specified with the -r flag.
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :should_load_requires
|
|
|
|
|
2011-07-25 01:57:40 -04:00
|
|
|
# Determines whether to disable edit-method's auto-reloading behavior.
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :disable_auto_reload
|
|
|
|
|
2011-11-24 00:53:55 -05:00
|
|
|
# Determines whether Pry should trap SIGINT and cause it to raise an
|
2011-11-22 12:06:27 -05:00
|
|
|
# Interrupt exception. This is only useful on jruby, MRI does this
|
|
|
|
# for us.
|
|
|
|
# @return [Boolean]
|
|
|
|
attr_accessor :should_trap_interrupts
|
|
|
|
|
2011-05-29 11:37:12 -04:00
|
|
|
# Config option for history.
|
2011-12-11 03:16:09 -05:00
|
|
|
# sub-options include history.file, history.load, and history.save
|
|
|
|
# history.file is the file to save/load history to, e.g
|
2011-05-29 11:37:12 -04:00
|
|
|
# Pry.config.history.file = "~/.pry_history".
|
2011-12-11 03:16:09 -05:00
|
|
|
# history.should_load is a boolean that determines whether history will be
|
|
|
|
# loaded from history.file at session start.
|
|
|
|
# history.should_save is a boolean that determines whether history will be
|
|
|
|
# saved to history.file at session end.
|
2011-05-29 11:37:12 -04:00
|
|
|
# @return [OpenStruct]
|
|
|
|
attr_accessor :history
|
2011-06-02 05:41:41 -04:00
|
|
|
|
|
|
|
# Config option for plugins:
|
|
|
|
# sub-options include:
|
2013-02-25 01:50:32 -05:00
|
|
|
# `plugins.strict_loading` (Boolean) which toggles whether referring to a
|
|
|
|
# non-existent plugin should raise an exception (defaults to `false`).
|
2011-06-02 05:41:41 -04:00
|
|
|
# @return [OpenStruct]
|
|
|
|
attr_accessor :plugins
|
2011-06-05 12:37:54 -04:00
|
|
|
|
2013-02-25 01:50:32 -05:00
|
|
|
# @return [Array<String>] Ruby files to be required after loading
|
|
|
|
# any plugins.
|
2011-07-24 23:04:44 -04:00
|
|
|
attr_accessor :requires
|
|
|
|
|
2011-06-11 06:44:30 -04:00
|
|
|
# @return [Integer] Amount of results that will be stored into out
|
2011-06-05 12:37:54 -04:00
|
|
|
attr_accessor :memory_size
|
2011-08-29 10:21:51 -04:00
|
|
|
|
|
|
|
# @return [Proc] The proc that manages ^D presses in the REPL.
|
|
|
|
# The proc is passed the current eval_string and the current pry instance.
|
|
|
|
attr_accessor :control_d_handler
|
2011-09-17 02:35:17 -04:00
|
|
|
|
|
|
|
# @return [Proc] The proc that runs system commands
|
2011-09-17 08:42:29 -04:00
|
|
|
# The proc is passed the pry output object, the command string
|
|
|
|
# to eval, and a reference to the pry instance
|
2011-09-17 02:35:17 -04:00
|
|
|
attr_accessor :system
|
2011-10-05 13:04:44 -04:00
|
|
|
|
2011-10-08 07:40:55 -04:00
|
|
|
# @return [Boolean] Whether or not code should be indented
|
2011-10-05 13:04:44 -04:00
|
|
|
# using Pry::Indent.
|
2011-10-08 07:40:55 -04:00
|
|
|
attr_accessor :auto_indent
|
2011-10-28 02:57:01 -04:00
|
|
|
|
|
|
|
# @return [Boolean] Whether or not indentation should be corrected
|
|
|
|
# after hitting enter. This feature is not supported by all terminals.
|
|
|
|
attr_accessor :correct_indent
|
2011-11-16 22:00:46 -05:00
|
|
|
|
|
|
|
# @return [Boolean] Whether or not a warning will be displayed when
|
|
|
|
# a command name collides with a method/local in the current context.
|
|
|
|
attr_accessor :collision_warning
|
2011-12-11 03:16:09 -05:00
|
|
|
|
|
|
|
# Config option for gist.
|
|
|
|
# sub-options include `gist.inspecter`,
|
|
|
|
# `gist.inspecter` is a callable that defines how the expression output
|
|
|
|
# will be displayed when using the `gist -i` command.
|
|
|
|
# @example Pretty inspect output
|
|
|
|
# Pry.config.gist.inspecter = proc { |v| v.pretty_inspect }
|
|
|
|
# @example Regular inspect
|
|
|
|
# Pry.config.gist.inspecter = proc &:inspect
|
|
|
|
# @return [OpenStruct]
|
|
|
|
attr_accessor :gist
|
2012-03-13 22:33:51 -04:00
|
|
|
|
2013-02-25 01:50:32 -05:00
|
|
|
# @return [Hash] Additional sticky locals (to the standard ones) to use in
|
|
|
|
# Pry sessions.
|
2012-03-13 22:33:51 -04:00
|
|
|
# @example Inject `random_number` sticky local into Pry session
|
|
|
|
# Pry.config.extra_sticky_locals = { :random_number => proc {
|
|
|
|
# rand(10) } }
|
|
|
|
attr_accessor :extra_sticky_locals
|
2012-08-18 18:49:20 -04:00
|
|
|
|
|
|
|
# @return [#build_completion_proc] A completer to use.
|
|
|
|
attr_accessor :completer
|
2011-05-28 04:43:32 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|