pry 0.9.12.2 → 0.14.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +1141 -0
- data/LICENSE +2 -2
- data/README.md +466 -0
- data/bin/pry +4 -7
- data/lib/pry/basic_object.rb +10 -0
- data/lib/pry/block_command.rb +22 -0
- data/lib/pry/class_command.rb +194 -0
- data/lib/pry/cli.rb +97 -92
- data/lib/pry/code/code_file.rb +114 -0
- data/lib/pry/code/code_range.rb +7 -4
- data/lib/pry/code/loc.rb +27 -14
- data/lib/pry/code.rb +62 -90
- data/lib/pry/code_object.rb +83 -39
- data/lib/pry/color_printer.rb +66 -0
- data/lib/pry/command.rb +202 -371
- data/lib/pry/command_set.rb +151 -133
- data/lib/pry/command_state.rb +31 -0
- data/lib/pry/commands/amend_line.rb +86 -82
- data/lib/pry/commands/bang.rb +18 -14
- data/lib/pry/commands/bang_pry.rb +15 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +23 -18
- data/lib/pry/commands/cat/exception_formatter.rb +85 -73
- data/lib/pry/commands/cat/file_formatter.rb +56 -63
- data/lib/pry/commands/cat/input_expression_formatter.rb +35 -30
- data/lib/pry/commands/cat.rb +64 -47
- data/lib/pry/commands/cd.rb +42 -26
- data/lib/pry/commands/change_inspector.rb +34 -0
- data/lib/pry/commands/change_prompt.rb +51 -0
- data/lib/pry/commands/clear_screen.rb +20 -0
- data/lib/pry/commands/code_collector.rb +148 -131
- data/lib/pry/commands/disable_pry.rb +23 -19
- data/lib/pry/commands/easter_eggs.rb +23 -34
- data/lib/pry/commands/edit/exception_patcher.rb +21 -17
- data/lib/pry/commands/edit/file_and_line_locator.rb +33 -24
- data/lib/pry/commands/edit.rb +183 -167
- data/lib/pry/commands/exit.rb +40 -35
- data/lib/pry/commands/exit_all.rb +24 -20
- data/lib/pry/commands/exit_program.rb +20 -17
- data/lib/pry/commands/find_method.rb +167 -167
- data/lib/pry/commands/fix_indent.rb +16 -12
- data/lib/pry/commands/help.rb +140 -133
- data/lib/pry/commands/hist.rb +153 -132
- data/lib/pry/commands/import_set.rb +20 -15
- data/lib/pry/commands/jump_to.rb +25 -21
- data/lib/pry/commands/list_inspectors.rb +42 -0
- data/lib/pry/commands/ls/constants.rb +75 -0
- data/lib/pry/commands/ls/formatter.rb +55 -0
- data/lib/pry/commands/ls/globals.rb +50 -0
- data/lib/pry/commands/ls/grep.rb +23 -0
- data/lib/pry/commands/ls/instance_vars.rb +40 -0
- data/lib/pry/commands/ls/interrogatable.rb +24 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +55 -0
- data/lib/pry/commands/ls/local_names.rb +37 -0
- data/lib/pry/commands/ls/local_vars.rb +47 -0
- data/lib/pry/commands/ls/ls_entity.rb +65 -0
- data/lib/pry/commands/ls/methods.rb +55 -0
- data/lib/pry/commands/ls/methods_helper.rb +50 -0
- data/lib/pry/commands/ls/self_methods.rb +34 -0
- data/lib/pry/commands/ls.rb +100 -303
- data/lib/pry/commands/nesting.rb +21 -17
- data/lib/pry/commands/play.rb +93 -49
- data/lib/pry/commands/pry_backtrace.rb +22 -18
- data/lib/pry/commands/pry_version.rb +15 -11
- data/lib/pry/commands/raise_up.rb +33 -27
- data/lib/pry/commands/reload_code.rb +57 -48
- data/lib/pry/commands/reset.rb +16 -12
- data/lib/pry/commands/ri.rb +57 -38
- data/lib/pry/commands/save_file.rb +45 -43
- data/lib/pry/commands/shell_command.rb +66 -34
- data/lib/pry/commands/shell_mode.rb +22 -20
- data/lib/pry/commands/show_doc.rb +80 -65
- data/lib/pry/commands/show_info.rb +193 -159
- data/lib/pry/commands/show_input.rb +16 -11
- data/lib/pry/commands/show_source.rb +113 -33
- data/lib/pry/commands/stat.rb +35 -31
- data/lib/pry/commands/switch_to.rb +21 -15
- data/lib/pry/commands/toggle_color.rb +21 -13
- data/lib/pry/commands/watch_expression/expression.rb +43 -0
- data/lib/pry/commands/watch_expression.rb +110 -0
- data/lib/pry/commands/whereami.rb +157 -134
- data/lib/pry/commands/wtf.rb +78 -40
- data/lib/pry/config/attributable.rb +22 -0
- data/lib/pry/config/lazy_value.rb +29 -0
- data/lib/pry/config/memoized_value.rb +34 -0
- data/lib/pry/config/value.rb +24 -0
- data/lib/pry/config.rb +290 -220
- data/lib/pry/control_d_handler.rb +28 -0
- data/lib/pry/core_extensions.rb +50 -27
- data/lib/pry/editor.rb +130 -102
- data/lib/pry/env.rb +18 -0
- data/lib/pry/exception_handler.rb +43 -0
- data/lib/pry/exceptions.rb +73 -0
- data/lib/pry/forwardable.rb +27 -0
- data/lib/pry/helpers/base_helpers.rb +22 -151
- data/lib/pry/helpers/command_helpers.rb +55 -63
- data/lib/pry/helpers/documentation_helpers.rb +21 -13
- data/lib/pry/helpers/options_helpers.rb +15 -8
- data/lib/pry/helpers/platform.rb +55 -0
- data/lib/pry/helpers/table.rb +44 -32
- data/lib/pry/helpers/text.rb +96 -86
- data/lib/pry/helpers.rb +3 -0
- data/lib/pry/history.rb +101 -70
- data/lib/pry/hooks.rb +67 -137
- data/lib/pry/indent.rb +79 -73
- data/lib/pry/input_completer.rb +283 -0
- data/lib/pry/input_lock.rb +129 -0
- data/lib/pry/inspector.rb +39 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method/disowned.rb +19 -5
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +51 -42
- data/lib/pry/method/weird_method_locator.rb +80 -44
- data/lib/pry/method.rb +225 -176
- data/lib/pry/object_path.rb +91 -0
- data/lib/pry/output.rb +136 -0
- data/lib/pry/pager.rb +227 -68
- data/lib/pry/prompt.rb +214 -0
- data/lib/pry/pry_class.rb +216 -289
- data/lib/pry/pry_instance.rb +438 -500
- data/lib/pry/repl.rb +256 -0
- data/lib/pry/repl_file_loader.rb +34 -35
- data/lib/pry/ring.rb +89 -0
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +190 -0
- data/lib/pry/slop/option.rb +210 -0
- data/lib/pry/slop.rb +672 -0
- data/lib/pry/syntax_highlighter.rb +26 -0
- data/lib/pry/system_command_handler.rb +17 -0
- data/lib/pry/testable/evalable.rb +24 -0
- data/lib/pry/testable/mockable.rb +22 -0
- data/lib/pry/testable/pry_tester.rb +88 -0
- data/lib/pry/testable/utility.rb +34 -0
- data/lib/pry/testable/variables.rb +52 -0
- data/lib/pry/testable.rb +68 -0
- data/lib/pry/version.rb +3 -1
- data/lib/pry/warning.rb +20 -0
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +36 -43
- data/lib/pry/wrapped_module.rb +102 -103
- data/lib/pry.rb +135 -261
- metadata +94 -283
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -21
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -9
- data/Guardfile +0 -62
- data/README.markdown +0 -400
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/commands/disabled_commands.rb +0 -2
- data/lib/pry/commands/gem_cd.rb +0 -26
- data/lib/pry/commands/gem_install.rb +0 -29
- data/lib/pry/commands/gem_list.rb +0 -33
- data/lib/pry/commands/gem_open.rb +0 -29
- data/lib/pry/commands/gist.rb +0 -102
- data/lib/pry/commands/install_command.rb +0 -51
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/commands.rb +0 -6
- data/lib/pry/completion.rb +0 -304
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/history_array.rb +0 -116
- data/lib/pry/plugins.rb +0 -103
- data/lib/pry/rbx_method.rb +0 -13
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/rubygem.rb +0 -74
- data/lib/pry/terminal.rb +0 -78
- data/lib/pry/test/helper.rb +0 -185
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -30
- data/spec/Procfile +0 -3
- data/spec/cli_spec.rb +0 -78
- data/spec/code_object_spec.rb +0 -277
- data/spec/code_spec.rb +0 -219
- data/spec/command_helpers_spec.rb +0 -29
- data/spec/command_integration_spec.rb +0 -644
- data/spec/command_set_spec.rb +0 -627
- data/spec/command_spec.rb +0 -821
- data/spec/commands/amend_line_spec.rb +0 -247
- data/spec/commands/bang_spec.rb +0 -19
- data/spec/commands/cat_spec.rb +0 -164
- data/spec/commands/cd_spec.rb +0 -250
- data/spec/commands/disable_pry_spec.rb +0 -25
- data/spec/commands/edit_spec.rb +0 -727
- data/spec/commands/exit_all_spec.rb +0 -34
- data/spec/commands/exit_program_spec.rb +0 -19
- data/spec/commands/exit_spec.rb +0 -34
- data/spec/commands/find_method_spec.rb +0 -70
- data/spec/commands/gem_list_spec.rb +0 -26
- data/spec/commands/gist_spec.rb +0 -79
- data/spec/commands/help_spec.rb +0 -56
- data/spec/commands/hist_spec.rb +0 -181
- data/spec/commands/jump_to_spec.rb +0 -15
- data/spec/commands/ls_spec.rb +0 -181
- data/spec/commands/play_spec.rb +0 -140
- data/spec/commands/raise_up_spec.rb +0 -56
- data/spec/commands/save_file_spec.rb +0 -177
- data/spec/commands/show_doc_spec.rb +0 -510
- data/spec/commands/show_input_spec.rb +0 -17
- data/spec/commands/show_source_spec.rb +0 -782
- data/spec/commands/whereami_spec.rb +0 -203
- data/spec/completion_spec.rb +0 -239
- data/spec/control_d_handler_spec.rb +0 -58
- data/spec/documentation_helper_spec.rb +0 -73
- data/spec/editor_spec.rb +0 -79
- data/spec/exception_whitelist_spec.rb +0 -21
- data/spec/fixtures/candidate_helper1.rb +0 -11
- data/spec/fixtures/candidate_helper2.rb +0 -8
- data/spec/fixtures/example.erb +0 -5
- data/spec/fixtures/example_nesting.rb +0 -33
- data/spec/fixtures/show_source_doc_examples.rb +0 -15
- data/spec/fixtures/testrc +0 -2
- data/spec/fixtures/testrcbad +0 -2
- data/spec/fixtures/whereami_helper.rb +0 -6
- data/spec/helper.rb +0 -34
- data/spec/helpers/bacon.rb +0 -86
- data/spec/helpers/mock_pry.rb +0 -43
- data/spec/helpers/table_spec.rb +0 -105
- data/spec/history_array_spec.rb +0 -67
- data/spec/hooks_spec.rb +0 -522
- data/spec/indent_spec.rb +0 -301
- data/spec/input_stack_spec.rb +0 -90
- data/spec/method_spec.rb +0 -482
- data/spec/prompt_spec.rb +0 -60
- data/spec/pry_defaults_spec.rb +0 -419
- data/spec/pry_history_spec.rb +0 -99
- data/spec/pry_output_spec.rb +0 -95
- data/spec/pry_spec.rb +0 -504
- data/spec/run_command_spec.rb +0 -25
- data/spec/sticky_locals_spec.rb +0 -157
- data/spec/syntax_checking_spec.rb +0 -81
- data/spec/wrapped_module_spec.rb +0 -261
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
data/lib/pry/config.rb
CHANGED
@@ -1,244 +1,314 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'ostruct'
|
2
4
|
|
3
5
|
class Pry
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
# Pry.config.input is an option determining the input object - the object from
|
8
|
-
# which Pry retrieves its lines of input. Pry accepts any object that implements the readline method.
|
9
|
-
# This includes IO objects, StringIO, Readline, File and custom objects.
|
10
|
-
# @return [#readline] The object to use for input by default by all
|
11
|
-
# Pry instances.
|
12
|
-
# @example
|
13
|
-
# Pry.config.input = StringIO.new("@x = 10\nexit")
|
14
|
-
attr_accessor :input
|
15
|
-
|
16
|
-
# Get/Set the object to use for output by default by all Pry instances.
|
17
|
-
# Pry.config.output is an option determining the output object - the object to which
|
18
|
-
# Pry writes its output. Pry accepts any object that implements the puts method. This
|
19
|
-
# includes IO objects, StringIO, File and custom objects.
|
20
|
-
# @return [#puts] The object to use for output by default by all
|
21
|
-
# Pry instances.
|
22
|
-
# @example
|
23
|
-
# Pry.config.output = StringIO.new
|
24
|
-
attr_accessor :output
|
25
|
-
|
26
|
-
# Get/Set the object to use for commands by default by all Pry instances.
|
27
|
-
# @return [Pry::CommandBase] The object to use for commands by default by all
|
28
|
-
# Pry instances.
|
29
|
-
# @example
|
30
|
-
# Pry.config.commands = Pry::CommandSet.new do
|
31
|
-
# import_from Pry::Commands, "ls"
|
32
|
-
#
|
33
|
-
# command "greet" do |name|
|
34
|
-
# output.puts "hello #{name}"
|
35
|
-
# end
|
36
|
-
# end
|
37
|
-
attr_accessor :commands
|
38
|
-
|
39
|
-
# Get/Set the Proc to use for printing by default by all Pry
|
40
|
-
# instances.
|
41
|
-
# Two parameters are passed to the print Proc: these are (1) the
|
42
|
-
# output object for the current session and (2) the expression value to print. It is important
|
43
|
-
# that you write to the output object instead of just stdout so that all Pry output can be redirected if necessary.
|
44
|
-
# This is the 'print' component of the REPL.
|
45
|
-
# @return [Proc] The Proc to use for printing by default by all
|
46
|
-
# Pry instances.
|
47
|
-
# @example
|
48
|
-
# Pry.config.print = proc { |output, value| output.puts "=> #{value.inspect}" }
|
49
|
-
attr_accessor :print
|
50
|
-
|
51
|
-
# Pry.config.exception_handler is an option determining the exception handler object - the
|
52
|
-
# Proc responsible for dealing with exceptions raised by user input to the REPL.
|
53
|
-
# Three parameters are passed to the exception handler Proc: these
|
54
|
-
# are (1) the output object for the current session, (2) the
|
55
|
-
# exception object that was raised inside the Pry session, and (3)
|
56
|
-
# a reference to the associated Pry instance.
|
57
|
-
# @return [Proc] The Proc to use for printing exceptions by default by all
|
58
|
-
# Pry instances.
|
59
|
-
# @example
|
60
|
-
# Pry.config.exception_handler = proc do |output, exception, _|
|
61
|
-
# output.puts "#{exception.class}: #{exception.message}"
|
62
|
-
# output.puts "from #{exception.backtrace.first}"
|
63
|
-
# end
|
64
|
-
attr_accessor :exception_handler
|
65
|
-
|
66
|
-
# @return [Array] The classes of exception that will not be caught by Pry.
|
67
|
-
# @example
|
68
|
-
# Pry.config.exception_whitelist = [SystemExit, SignalException]
|
69
|
-
attr_accessor :exception_whitelist
|
70
|
-
|
71
|
-
# @return [Fixnum] The number of lines of context to show before and after
|
72
|
-
# exceptions, etc.
|
73
|
-
# @example
|
74
|
-
# Pry.config.default_window_size = 10
|
75
|
-
attr_accessor :default_window_size
|
76
|
-
|
77
|
-
# Get/Set the `Pry::Hooks` instance that defines Pry hooks used by default by all Pry
|
78
|
-
# instances.
|
79
|
-
# @return [Pry::Hooks] The hooks used by default by all Pry instances.
|
80
|
-
# @example
|
81
|
-
# Pry.config.hooks = Pry::Hooks.new.add_hook(:before_session,
|
82
|
-
# :default) { |output, target, _pry_| output.puts "Good morning!" }
|
83
|
-
attr_reader :hooks
|
84
|
-
|
85
|
-
# FIXME:
|
86
|
-
# This is a hack to alert people of the new API.
|
87
|
-
# @param [Pry::Hooks] v Only accept `Pry::Hooks` now!
|
88
|
-
def hooks=(v)
|
89
|
-
if v.is_a?(Hash)
|
90
|
-
warn "Hash-based hooks are now deprecated! Use a `Pry::Hooks` object instead! http://rubydoc.info/github/pry/pry/master/Pry/Hooks"
|
91
|
-
@hooks = Pry::Hooks.from_hash(v)
|
92
|
-
else
|
93
|
-
@hooks = v
|
94
|
-
end
|
95
|
-
end
|
6
|
+
# @api private
|
7
|
+
class Config
|
8
|
+
extend Attributable
|
96
9
|
|
97
|
-
#
|
98
|
-
#
|
99
|
-
|
100
|
-
|
101
|
-
#
|
102
|
-
|
103
|
-
|
104
|
-
#
|
105
|
-
|
106
|
-
|
107
|
-
#
|
108
|
-
|
109
|
-
|
110
|
-
#
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
#
|
117
|
-
#
|
118
|
-
|
119
|
-
|
120
|
-
#
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
#
|
125
|
-
|
126
|
-
|
127
|
-
#
|
128
|
-
|
129
|
-
|
130
|
-
#
|
131
|
-
|
132
|
-
|
133
|
-
#
|
134
|
-
#
|
135
|
-
|
136
|
-
|
137
|
-
#
|
10
|
+
# @return [IO, #readline] he object from which Pry retrieves its lines of
|
11
|
+
# input
|
12
|
+
attribute :input
|
13
|
+
|
14
|
+
# @return [IO, #puts] where Pry should output results provided by {input}
|
15
|
+
attribute :output
|
16
|
+
|
17
|
+
# @return [Pry::CommandSet]
|
18
|
+
attribute :commands
|
19
|
+
|
20
|
+
# @return [Proc] the printer for Ruby expressions (not commands)
|
21
|
+
attribute :print
|
22
|
+
|
23
|
+
# @return [Proc] the printer for exceptions
|
24
|
+
attribute :exception_handler
|
25
|
+
|
26
|
+
# @return [Array] Exception that Pry shouldn't rescue
|
27
|
+
attribute :unrescued_exceptions
|
28
|
+
|
29
|
+
# @deprecated
|
30
|
+
# @return [Array] Exception that Pry shouldn't rescue
|
31
|
+
attribute :exception_whitelist
|
32
|
+
|
33
|
+
# @return [Integer] The number of lines of context to show before and after
|
34
|
+
# exceptions
|
35
|
+
attribute :default_window_size
|
36
|
+
|
37
|
+
# @return [Pry::Hooks]
|
38
|
+
attribute :hooks
|
39
|
+
|
40
|
+
# @return [Pry::Prompt]
|
41
|
+
attribute :prompt
|
42
|
+
|
43
|
+
# @return [String] The display name that is part of the prompt
|
44
|
+
attribute :prompt_name
|
45
|
+
|
46
|
+
# @return [Array<Object>] the list of objects that are known to have a
|
47
|
+
# 1-line #inspect output suitable for prompt
|
48
|
+
attribute :prompt_safe_contexts
|
49
|
+
|
50
|
+
# If it is a String, then that String is used as the shell
|
51
|
+
# command to invoke the editor.
|
52
|
+
#
|
53
|
+
# If it responds to #call is callable then `file`, `line`, and `reloading`
|
54
|
+
# are passed to it. `reloading` indicates whether Pry will be reloading code
|
55
|
+
# after the shell command returns. All parameters are optional.
|
138
56
|
# @return [String, #call]
|
139
|
-
|
57
|
+
attribute :editor
|
140
58
|
|
141
|
-
# A string that must precede all
|
59
|
+
# A string that must precede all commands. For example, if is is
|
142
60
|
# set to "%", the "cd" command must be invoked as "%cd").
|
143
61
|
# @return [String]
|
144
|
-
|
62
|
+
attribute :command_prefix
|
145
63
|
|
146
|
-
# @return [Boolean]
|
147
|
-
|
148
|
-
|
149
|
-
# @return [Boolean] Toggle paging on and off.
|
150
|
-
attr_accessor :pager
|
64
|
+
# @return [Boolean]
|
65
|
+
attribute :color
|
151
66
|
|
152
|
-
# Determines whether the rc file (~/.pryrc) should be loaded.
|
153
67
|
# @return [Boolean]
|
154
|
-
|
68
|
+
attribute :pager
|
69
|
+
|
70
|
+
# @return [Boolean] whether the global ~/.pryrc should be loaded
|
71
|
+
attribute :should_load_rc
|
72
|
+
|
73
|
+
# @return [Boolean] whether the local ./.pryrc should be loaded
|
74
|
+
attribute :should_load_local_rc
|
75
|
+
|
76
|
+
# @return [Boolean] whether to load files specified with the -r flag
|
77
|
+
attribute :should_load_requires
|
155
78
|
|
156
|
-
#
|
79
|
+
# @return [Boolean] whether to disable edit-method's auto-reloading behavior
|
80
|
+
attribute :disable_auto_reload
|
81
|
+
|
82
|
+
# Whether Pry should trap SIGINT and cause it to raise an Interrupt
|
83
|
+
# exception. This is only useful on JRuby, MRI does this for us.
|
157
84
|
# @return [Boolean]
|
158
|
-
|
85
|
+
attribute :should_trap_interrupts
|
86
|
+
|
87
|
+
# @return [Pry::History]
|
88
|
+
attribute :history
|
159
89
|
|
160
|
-
# Determines whether plugins should be loaded.
|
161
90
|
# @return [Boolean]
|
162
|
-
|
91
|
+
attribute :history_save
|
163
92
|
|
164
|
-
# Determines whether to load files specified with the -r flag.
|
165
93
|
# @return [Boolean]
|
166
|
-
|
94
|
+
attribute :history_load
|
95
|
+
|
96
|
+
# @return [String]
|
97
|
+
attribute :history_file
|
98
|
+
|
99
|
+
# @return [Array<String,Regexp>]
|
100
|
+
attribute :history_ignorelist
|
101
|
+
|
102
|
+
# @return [Array<String>] Ruby files to be required
|
103
|
+
attribute :requires
|
104
|
+
|
105
|
+
# @return [Integer] how many input/output lines to keep in memory
|
106
|
+
attribute :memory_size
|
107
|
+
|
108
|
+
# @return [Proc] The proc that runs system commands
|
109
|
+
attribute :system
|
167
110
|
|
168
|
-
# Determines whether to disable edit-method's auto-reloading behavior.
|
169
111
|
# @return [Boolean]
|
170
|
-
|
112
|
+
attribute :auto_indent
|
171
113
|
|
172
|
-
# Determines whether Pry should trap SIGINT and cause it to raise an
|
173
|
-
# Interrupt exception. This is only useful on jruby, MRI does this
|
174
|
-
# for us.
|
175
114
|
# @return [Boolean]
|
176
|
-
|
177
|
-
|
178
|
-
# Config option for history.
|
179
|
-
# sub-options include history.file, history.load, and history.save
|
180
|
-
# history.file is the file to save/load history to, e.g
|
181
|
-
# Pry.config.history.file = "~/.pry_history".
|
182
|
-
# history.should_load is a boolean that determines whether history will be
|
183
|
-
# loaded from history.file at session start.
|
184
|
-
# history.should_save is a boolean that determines whether history will be
|
185
|
-
# saved to history.file at session end.
|
186
|
-
# @return [OpenStruct]
|
187
|
-
attr_accessor :history
|
188
|
-
|
189
|
-
# Config option for plugins:
|
190
|
-
# sub-options include:
|
191
|
-
# `plugins.strict_loading` (Boolean) which toggles whether referring to a non-existent plugin should raise an exception (defaults to `false`)
|
192
|
-
# @return [OpenStruct]
|
193
|
-
attr_accessor :plugins
|
194
|
-
|
195
|
-
# @return [Array<String>] Ruby files to be required after loading any plugins.
|
196
|
-
attr_accessor :requires
|
197
|
-
|
198
|
-
# @return [Integer] Amount of results that will be stored into out
|
199
|
-
attr_accessor :memory_size
|
200
|
-
|
201
|
-
# @return [Proc] The proc that manages ^D presses in the REPL.
|
202
|
-
# The proc is passed the current eval_string and the current pry instance.
|
203
|
-
attr_accessor :control_d_handler
|
115
|
+
attribute :correct_indent
|
204
116
|
|
205
|
-
# @return [
|
206
|
-
#
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
#
|
216
|
-
|
217
|
-
|
218
|
-
# @return [Boolean]
|
219
|
-
#
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
#
|
226
|
-
|
227
|
-
|
228
|
-
#
|
229
|
-
|
230
|
-
|
231
|
-
# @return [
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
# @
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
117
|
+
# @return [Boolean] whether or not display a warning when a command name
|
118
|
+
# collides with a method/local in the current context.
|
119
|
+
attribute :collision_warning
|
120
|
+
|
121
|
+
# @return [Hash{Symbol=>Proc}]
|
122
|
+
attribute :extra_sticky_locals
|
123
|
+
|
124
|
+
# @return [#build_completion_proc] a completer to use
|
125
|
+
attribute :completer
|
126
|
+
|
127
|
+
# @return [Boolean] suppresses whereami output on `binding.pry`
|
128
|
+
attribute :quiet
|
129
|
+
|
130
|
+
# @return [Boolean] displays a warning about experience improvement on
|
131
|
+
# Windows
|
132
|
+
attribute :windows_console_warning
|
133
|
+
|
134
|
+
# @return [Proc]
|
135
|
+
attribute :command_completions
|
136
|
+
|
137
|
+
# @return [Proc]
|
138
|
+
attribute :file_completions
|
139
|
+
|
140
|
+
# @return [Hash]
|
141
|
+
attribute :ls
|
142
|
+
|
143
|
+
# @return [String] a line of code to execute in context before the session
|
144
|
+
# starts
|
145
|
+
attribute :exec_string
|
146
|
+
|
147
|
+
# @return [String]
|
148
|
+
attribute :output_prefix
|
149
|
+
|
150
|
+
# @return [String]
|
151
|
+
# @since v0.13.0
|
152
|
+
attribute :rc_file
|
153
|
+
|
154
|
+
def initialize
|
155
|
+
merge!(
|
156
|
+
input: MemoizedValue.new { lazy_readline },
|
157
|
+
output: $stdout.tap { |out| out.sync = true },
|
158
|
+
commands: Pry::Commands,
|
159
|
+
prompt_name: 'pry',
|
160
|
+
prompt: Pry::Prompt[:default],
|
161
|
+
prompt_safe_contexts: [String, Numeric, Symbol, nil, true, false],
|
162
|
+
print: Pry::ColorPrinter.method(:default),
|
163
|
+
quiet: false,
|
164
|
+
exception_handler: Pry::ExceptionHandler.method(:handle_exception),
|
165
|
+
|
166
|
+
unrescued_exceptions: [
|
167
|
+
::SystemExit, ::SignalException, Pry::TooSafeException
|
168
|
+
],
|
169
|
+
|
170
|
+
exception_whitelist: MemoizedValue.new do
|
171
|
+
output.puts(
|
172
|
+
'[warning] Pry.config.exception_whitelist is deprecated, ' \
|
173
|
+
'please use Pry.config.unrescued_exceptions instead.'
|
174
|
+
)
|
175
|
+
unrescued_exceptions
|
176
|
+
end,
|
177
|
+
|
178
|
+
hooks: Pry::Hooks.default,
|
179
|
+
pager: true,
|
180
|
+
system: Pry::SystemCommandHandler.method(:default),
|
181
|
+
color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
|
182
|
+
default_window_size: 5,
|
183
|
+
editor: Pry::Editor.default,
|
184
|
+
rc_file: default_rc_file,
|
185
|
+
should_load_rc: true,
|
186
|
+
should_load_local_rc: true,
|
187
|
+
should_trap_interrupts: Pry::Helpers::Platform.jruby?,
|
188
|
+
disable_auto_reload: false,
|
189
|
+
command_prefix: '',
|
190
|
+
auto_indent: Pry::Helpers::BaseHelpers.use_ansi_codes?,
|
191
|
+
correct_indent: true,
|
192
|
+
collision_warning: false,
|
193
|
+
output_prefix: '=> ',
|
194
|
+
requires: [],
|
195
|
+
should_load_requires: true,
|
196
|
+
windows_console_warning: true,
|
197
|
+
control_d_handler: Pry::ControlDHandler.method(:default),
|
198
|
+
memory_size: 100,
|
199
|
+
extra_sticky_locals: {},
|
200
|
+
command_completions: proc { commands.keys },
|
201
|
+
file_completions: proc { Dir['.'] },
|
202
|
+
ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
|
203
|
+
completer: Pry::InputCompleter,
|
204
|
+
history_save: true,
|
205
|
+
history_load: true,
|
206
|
+
history_file: Pry::History.default_file,
|
207
|
+
history_ignorelist: [],
|
208
|
+
history: MemoizedValue.new do
|
209
|
+
if defined?(input::HISTORY)
|
210
|
+
Pry::History.new(history: input::HISTORY)
|
211
|
+
else
|
212
|
+
Pry::History.new
|
213
|
+
end
|
214
|
+
end,
|
215
|
+
exec_string: ''
|
216
|
+
)
|
217
|
+
|
218
|
+
@custom_attrs = {}
|
219
|
+
end
|
220
|
+
|
221
|
+
def merge!(config_hash)
|
222
|
+
config_hash.each_pair { |attr, value| __send__("#{attr}=", value) }
|
223
|
+
self
|
224
|
+
end
|
225
|
+
|
226
|
+
def merge(config_hash)
|
227
|
+
dup.merge!(config_hash)
|
228
|
+
end
|
229
|
+
|
230
|
+
def []=(attr, value)
|
231
|
+
@custom_attrs[attr.to_s] = Config::Value.new(value)
|
232
|
+
end
|
233
|
+
|
234
|
+
def [](attr)
|
235
|
+
@custom_attrs[attr.to_s].call
|
236
|
+
end
|
237
|
+
|
238
|
+
# rubocop:disable Style/MethodMissingSuper
|
239
|
+
def method_missing(method_name, *args, &_block)
|
240
|
+
name = method_name.to_s
|
241
|
+
|
242
|
+
if name.end_with?('=')
|
243
|
+
self[name[0..-2]] = args.first
|
244
|
+
elsif @custom_attrs.key?(name)
|
245
|
+
self[name]
|
246
|
+
end
|
247
|
+
end
|
248
|
+
# rubocop:enable Style/MethodMissingSuper
|
249
|
+
|
250
|
+
def respond_to_missing?(method_name, include_all = false)
|
251
|
+
@custom_attrs.key?(method_name.to_s.tr('=', '')) || super
|
252
|
+
end
|
253
|
+
|
254
|
+
def initialize_dup(other)
|
255
|
+
super
|
256
|
+
@custom_attrs = @custom_attrs.dup
|
257
|
+
end
|
258
|
+
|
259
|
+
attr_reader :control_d_handler
|
260
|
+
def control_d_handler=(value)
|
261
|
+
proxy_proc =
|
262
|
+
if value.arity == 2
|
263
|
+
Pry::Warning.warn(
|
264
|
+
"control_d_handler's arity of 2 parameters was deprecated " \
|
265
|
+
'(eval_string, pry_instance). Now it gets passed just 1 ' \
|
266
|
+
'parameter (pry_instance)'
|
267
|
+
)
|
268
|
+
proc do |*args|
|
269
|
+
if args.size == 2
|
270
|
+
value.call(args.first, args[1])
|
271
|
+
else
|
272
|
+
value.call(args.first.eval_string, args.first)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
else
|
276
|
+
proc do |*args|
|
277
|
+
if args.size == 2
|
278
|
+
value.call(args[1])
|
279
|
+
else
|
280
|
+
value.call(args.first)
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
@control_d_handler = proxy_proc
|
285
|
+
end
|
286
|
+
|
287
|
+
private
|
288
|
+
|
289
|
+
def lazy_readline
|
290
|
+
require 'readline'
|
291
|
+
::Readline
|
292
|
+
rescue LoadError
|
293
|
+
output.puts(
|
294
|
+
"Sorry, you can't use Pry without Readline or a compatible library. \n" \
|
295
|
+
"Possible solutions: \n" \
|
296
|
+
" * Rebuild Ruby with Readline support using `--with-readline` \n" \
|
297
|
+
" * Use the rb-readline gem, which is a pure-Ruby port of Readline \n" \
|
298
|
+
" * Use the pry-coolline gem, a pure-ruby alternative to Readline"
|
299
|
+
)
|
300
|
+
raise
|
301
|
+
end
|
302
|
+
|
303
|
+
def default_rc_file
|
304
|
+
[Pry::Env['PRYRC'],
|
305
|
+
# See XDG Base Directory Specification at
|
306
|
+
# https://specifications.freedesktop.org/basedir-spec/latest/
|
307
|
+
"#{Pry::Env['XDG_CONFIG_HOME']}/pry/pryrc",
|
308
|
+
File.expand_path('~/.pryrc'),
|
309
|
+
File.expand_path('~/.config/pry/pryrc')]
|
310
|
+
.compact
|
311
|
+
.find { |file| File.exist?(file) }
|
312
|
+
end
|
242
313
|
end
|
243
314
|
end
|
244
|
-
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Pry
|
4
|
+
# @api private
|
5
|
+
# @since v0.13.0
|
6
|
+
module ControlDHandler
|
7
|
+
# Deal with the ^D key being pressed. Different behaviour in different
|
8
|
+
# cases:
|
9
|
+
# 1. In an expression behave like `!` command.
|
10
|
+
# 2. At top-level session behave like `exit` command.
|
11
|
+
# 3. In a nested session behave like `cd ..`.
|
12
|
+
def self.default(pry_instance)
|
13
|
+
if !pry_instance.eval_string.empty?
|
14
|
+
# Clear input buffer.
|
15
|
+
pry_instance.eval_string = ''
|
16
|
+
elsif pry_instance.binding_stack.one?
|
17
|
+
pry_instance.binding_stack.clear
|
18
|
+
throw(:breakout)
|
19
|
+
else
|
20
|
+
# Otherwise, saves current binding stack as old stack and pops last
|
21
|
+
# binding out of binding stack (the old stack still has that binding).
|
22
|
+
cd_state = Pry::CommandState.default.state_for('cd')
|
23
|
+
cd_state.old_stack = pry_instance.binding_stack.dup
|
24
|
+
pry_instance.binding_stack.pop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|