pry 0.9.12.6-i386-mswin32 → 0.10.0-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +37 -31
- data/lib/pry.rb +38 -151
- data/lib/pry/cli.rb +35 -17
- data/lib/pry/code.rb +19 -63
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +2 -1
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +40 -21
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +12 -9
- data/lib/pry/command_set.rb +81 -38
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +2 -2
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +11 -2
- data/lib/pry/commands/cat/exception_formatter.rb +6 -7
- data/lib/pry/commands/cat/file_formatter.rb +15 -32
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cd.rb +14 -3
- data/lib/pry/commands/change_inspector.rb +27 -0
- data/lib/pry/commands/change_prompt.rb +26 -0
- data/lib/pry/commands/code_collector.rb +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +10 -22
- data/lib/pry/commands/edit/exception_patcher.rb +2 -2
- data/lib/pry/commands/edit/file_and_line_locator.rb +0 -2
- data/lib/pry/commands/exit_program.rb +0 -1
- data/lib/pry/commands/find_method.rb +16 -22
- data/lib/pry/commands/gem_install.rb +5 -2
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +10 -11
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +27 -8
- data/lib/pry/commands/install_command.rb +14 -12
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +72 -296
- data/lib/pry/commands/ls/constants.rb +47 -0
- data/lib/pry/commands/ls/formatter.rb +49 -0
- data/lib/pry/commands/ls/globals.rb +48 -0
- data/lib/pry/commands/ls/grep.rb +21 -0
- data/lib/pry/commands/ls/instance_vars.rb +39 -0
- data/lib/pry/commands/ls/interrogatable.rb +18 -0
- data/lib/pry/commands/ls/jruby_hacks.rb +49 -0
- data/lib/pry/commands/ls/local_names.rb +35 -0
- data/lib/pry/commands/ls/local_vars.rb +39 -0
- data/lib/pry/commands/ls/ls_entity.rb +70 -0
- data/lib/pry/commands/ls/methods.rb +57 -0
- data/lib/pry/commands/ls/methods_helper.rb +46 -0
- data/lib/pry/commands/ls/self_methods.rb +32 -0
- data/lib/pry/commands/play.rb +44 -10
- data/lib/pry/commands/pry_backtrace.rb +1 -2
- data/lib/pry/commands/raise_up.rb +2 -2
- data/lib/pry/commands/reload_code.rb +16 -19
- data/lib/pry/commands/ri.rb +7 -3
- data/lib/pry/commands/shell_command.rb +18 -13
- data/lib/pry/commands/shell_mode.rb +2 -4
- data/lib/pry/commands/show_doc.rb +5 -0
- data/lib/pry/commands/show_info.rb +8 -13
- data/lib/pry/commands/show_source.rb +15 -3
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +8 -4
- data/lib/pry/commands/watch_expression.rb +105 -0
- data/lib/pry/commands/watch_expression/expression.rb +38 -0
- data/lib/pry/commands/whereami.rb +18 -10
- data/lib/pry/commands/wtf.rb +3 -3
- data/lib/pry/config.rb +20 -254
- data/lib/pry/config/behavior.rb +139 -0
- data/lib/pry/config/convenience.rb +26 -0
- data/lib/pry/config/default.rb +165 -0
- data/lib/pry/core_extensions.rb +31 -21
- data/lib/pry/editor.rb +107 -103
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers/base_helpers.rb +22 -109
- data/lib/pry/helpers/command_helpers.rb +10 -8
- data/lib/pry/helpers/documentation_helpers.rb +1 -2
- data/lib/pry/helpers/text.rb +4 -5
- data/lib/pry/history.rb +46 -45
- data/lib/pry/history_array.rb +6 -1
- data/lib/pry/hooks.rb +9 -29
- data/lib/pry/indent.rb +6 -6
- data/lib/pry/input_completer.rb +242 -0
- data/lib/pry/input_lock.rb +132 -0
- data/lib/pry/inspector.rb +27 -0
- data/lib/pry/last_exception.rb +61 -0
- data/lib/pry/method.rb +82 -87
- data/lib/pry/{commands/edit/method_patcher.rb → method/patcher.rb} +41 -38
- data/lib/pry/module_candidate.rb +4 -14
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +193 -48
- data/lib/pry/plugins.rb +1 -1
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +149 -230
- data/lib/pry/pry_instance.rb +302 -413
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +202 -0
- data/lib/pry/repl_file_loader.rb +20 -26
- data/lib/pry/rubygem.rb +13 -5
- data/lib/pry/terminal.rb +2 -1
- data/lib/pry/test/helper.rb +26 -41
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +45 -59
- metadata +62 -225
- data/.document +0 -2
- data/.gitignore +0 -16
- data/.travis.yml +0 -25
- data/.yardopts +0 -1
- data/CHANGELOG +0 -534
- data/CONTRIBUTORS +0 -55
- data/Gemfile +0 -12
- data/Rakefile +0 -140
- data/TODO +0 -117
- data/lib/pry/completion.rb +0 -321
- data/lib/pry/custom_completions.rb +0 -6
- data/lib/pry/rbx_method.rb +0 -13
- data/man/pry.1 +0 -195
- data/man/pry.1.html +0 -204
- data/man/pry.1.ronn +0 -141
- data/pry.gemspec +0 -29
- 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 -241
- 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 -515
- 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/plugins.rb
CHANGED
@@ -43,7 +43,7 @@ class Pry
|
|
43
43
|
# Does not reload plugin if it's already active.
|
44
44
|
def activate!
|
45
45
|
# Create the configuration object for the plugin.
|
46
|
-
Pry.config.send("#{gem_name.gsub('-', '_')}=",
|
46
|
+
Pry.config.send("#{gem_name.gsub('-', '_')}=", Pry::Config.from_hash({}))
|
47
47
|
|
48
48
|
begin
|
49
49
|
require gem_name if !active?
|
data/lib/pry/prompt.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
class Pry::Prompt
|
2
|
+
MAP = {
|
3
|
+
"default" => {
|
4
|
+
value: Pry::DEFAULT_PROMPT,
|
5
|
+
description: "The default Pry prompt. Includes information about the\n" \
|
6
|
+
"current expression number, evaluation context, and nesting\n" \
|
7
|
+
"level, plus a reminder that you're using Pry."
|
8
|
+
},
|
9
|
+
|
10
|
+
"simple" => {
|
11
|
+
value: Pry::SIMPLE_PROMPT,
|
12
|
+
description: "A simple '>>'."
|
13
|
+
},
|
14
|
+
|
15
|
+
"nav" => {
|
16
|
+
value: Pry::NAV_PROMPT,
|
17
|
+
description: "A prompt that displays the binding stack as a path and\n" \
|
18
|
+
"includes information about _in_ and _out_."
|
19
|
+
},
|
20
|
+
|
21
|
+
"none" => {
|
22
|
+
value: Pry::NO_PROMPT,
|
23
|
+
description: "Wave goodbye to the Pry prompt."
|
24
|
+
}
|
25
|
+
}
|
26
|
+
end
|
data/lib/pry/pry_class.rb
CHANGED
@@ -1,93 +1,88 @@
|
|
1
|
-
require 'ostruct'
|
2
|
-
require 'forwardable'
|
3
1
|
require 'pry/config'
|
4
|
-
|
5
2
|
class Pry
|
6
3
|
|
7
|
-
|
8
|
-
HOME_RC_FILE = "~/.pryrc"
|
4
|
+
HOME_RC_FILE = ENV["PRYRC"] || "~/.pryrc"
|
9
5
|
LOCAL_RC_FILE = "./.pryrc"
|
10
6
|
|
11
|
-
# @return [Hash] Pry's `Thread.current` hash
|
12
|
-
def self.current
|
13
|
-
Thread.current[:__pry__] ||= {}
|
14
|
-
end
|
15
|
-
|
16
|
-
# class accessors
|
17
7
|
class << self
|
18
8
|
extend Forwardable
|
19
|
-
|
20
|
-
# convenience method
|
21
|
-
def self.delegate_accessors(delagatee, *names)
|
22
|
-
def_delegators delagatee, *names
|
23
|
-
def_delegators delagatee, *names.map { |v| "#{v}=" }
|
24
|
-
end
|
25
|
-
|
26
|
-
# Get/Set the Proc that defines extra Readline completions (on top
|
27
|
-
# of the ones defined for IRB).
|
28
|
-
# @return [Proc] The Proc that defines extra Readline completions (on top
|
29
|
-
# @example Add file names to completion list
|
30
|
-
# Pry.custom_completions = proc { Dir.entries('.') }
|
31
9
|
attr_accessor :custom_completions
|
32
|
-
|
33
|
-
# @return [Fixnum] The current input line.
|
34
10
|
attr_accessor :current_line
|
35
|
-
|
36
|
-
# @return [Array] The Array of evaluated expressions.
|
37
11
|
attr_accessor :line_buffer
|
38
|
-
|
39
|
-
# @return [String] The __FILE__ for the `eval()`. Should be "(pry)"
|
40
|
-
# by default.
|
41
12
|
attr_accessor :eval_path
|
42
|
-
|
43
|
-
|
13
|
+
attr_accessor :cli
|
14
|
+
attr_accessor :quiet
|
15
|
+
attr_accessor :last_internal_error
|
44
16
|
attr_accessor :config
|
17
|
+
attr_writer :history
|
45
18
|
|
46
|
-
|
47
|
-
attr_accessor :history
|
19
|
+
def_delegators :@plugin_manager, :plugins, :load_plugins, :locate_plugins
|
48
20
|
|
49
|
-
|
50
|
-
|
21
|
+
extend Pry::Config::Convenience
|
22
|
+
config_shortcut *Pry::Config.shortcuts
|
51
23
|
|
52
|
-
|
53
|
-
|
24
|
+
def prompt=(value)
|
25
|
+
config.prompt = value
|
26
|
+
end
|
54
27
|
|
55
|
-
|
56
|
-
|
28
|
+
def prompt
|
29
|
+
config.prompt
|
30
|
+
end
|
57
31
|
|
58
|
-
|
59
|
-
|
60
|
-
|
32
|
+
def history
|
33
|
+
@history ||= History.new
|
34
|
+
end
|
35
|
+
end
|
61
36
|
|
62
|
-
|
63
|
-
|
37
|
+
#
|
38
|
+
# @return [main]
|
39
|
+
# returns the special instance of Object, "main".
|
40
|
+
#
|
41
|
+
def self.main
|
42
|
+
@main ||= TOPLEVEL_BINDING.eval "self"
|
43
|
+
end
|
64
44
|
|
65
|
-
|
66
|
-
|
45
|
+
#
|
46
|
+
# @return [Pry::Config]
|
47
|
+
# Returns a value store for an instance of Pry running on the current thread.
|
48
|
+
#
|
49
|
+
def self.current
|
50
|
+
Thread.current[:__pry__] ||= Pry::Config.from_hash({}, nil)
|
67
51
|
end
|
68
52
|
|
69
53
|
# Load the given file in the context of `Pry.toplevel_binding`
|
70
|
-
# @param [String]
|
71
|
-
def self.load_file_at_toplevel(
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
rescue RescuableException => e
|
76
|
-
puts "Error loading #{file_name}: #{e}\n#{e.backtrace.first}"
|
77
|
-
end
|
54
|
+
# @param [String] file The unexpanded file path.
|
55
|
+
def self.load_file_at_toplevel(file)
|
56
|
+
toplevel_binding.eval(File.read(file), file)
|
57
|
+
rescue RescuableException => e
|
58
|
+
puts "Error loading #{file}: #{e}\n#{e.backtrace.first}"
|
78
59
|
end
|
79
60
|
|
80
|
-
# Load
|
61
|
+
# Load HOME_RC_FILE and LOCAL_RC_FILE if appropriate
|
81
62
|
# This method can also be used to reload the files if they have changed.
|
82
|
-
def self.
|
83
|
-
|
63
|
+
def self.load_rc_files
|
64
|
+
rc_files_to_load.each do |file|
|
65
|
+
critical_section do
|
66
|
+
load_file_at_toplevel(file)
|
67
|
+
end
|
68
|
+
end
|
84
69
|
end
|
85
70
|
|
86
71
|
# Load the local RC file (./.pryrc)
|
87
|
-
def self.
|
88
|
-
|
89
|
-
|
90
|
-
|
72
|
+
def self.rc_files_to_load
|
73
|
+
files = []
|
74
|
+
files << HOME_RC_FILE if Pry.config.should_load_rc
|
75
|
+
files << LOCAL_RC_FILE if Pry.config.should_load_local_rc
|
76
|
+
files.map { |file| real_path_to(file) }.compact.uniq
|
77
|
+
end
|
78
|
+
|
79
|
+
# Expand a file to its canonical name (following symlinks as appropriate)
|
80
|
+
def self.real_path_to(file)
|
81
|
+
expanded = Pathname.new(File.expand_path(file)).realpath.to_s
|
82
|
+
# For rbx 1.9 mode [see rubinius issue #2165]
|
83
|
+
File.exist?(expanded) ? expanded : nil
|
84
|
+
rescue Errno::ENOENT
|
85
|
+
nil
|
91
86
|
end
|
92
87
|
|
93
88
|
# Load any Ruby files specified with the -r flag on the command line.
|
@@ -103,26 +98,41 @@ class Pry
|
|
103
98
|
trap('INT'){ raise Interrupt }
|
104
99
|
end
|
105
100
|
|
101
|
+
def self.load_win32console
|
102
|
+
begin
|
103
|
+
require 'win32console'
|
104
|
+
# The mswin and mingw versions of pry require win32console, so this should
|
105
|
+
# only fail on jruby (where win32console doesn't work).
|
106
|
+
# Instead we'll recommend ansicon, which does.
|
107
|
+
rescue LoadError
|
108
|
+
warn <<-WARNING if Pry.config.windows_console_warning
|
109
|
+
For a better Pry experience on Windows, please use ansicon:
|
110
|
+
https://github.com/adoxa/ansicon
|
111
|
+
If you use an alternative to ansicon and don't want to see this warning again,
|
112
|
+
you can add "Pry.config.windows_console_warning = false" to your .pryrc.
|
113
|
+
WARNING
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
106
117
|
# Do basic setup for initial session.
|
107
118
|
# Including: loading .pryrc, loading plugins, loading requires, and
|
108
119
|
# loading history.
|
109
120
|
def self.initial_session_setup
|
110
121
|
return unless initial_session?
|
122
|
+
@initial_session = false
|
111
123
|
|
112
124
|
# note these have to be loaded here rather than in pry_instance as
|
113
125
|
# we only want them loaded once per entire Pry lifetime.
|
114
|
-
|
115
|
-
load_local_rc if Pry.config.should_load_local_rc
|
126
|
+
load_rc_files
|
116
127
|
load_plugins if Pry.config.should_load_plugins
|
117
128
|
load_requires if Pry.config.should_load_requires
|
118
129
|
load_history if Pry.config.history.should_load
|
119
130
|
load_traps if Pry.config.should_trap_interrupts
|
120
|
-
|
121
|
-
@initial_session = false
|
131
|
+
load_win32console if Pry::Helpers::BaseHelpers.windows? && !Pry::Helpers::BaseHelpers.windows_ansi?
|
122
132
|
end
|
123
133
|
|
124
134
|
# Start a Pry REPL.
|
125
|
-
# This method also loads
|
135
|
+
# This method also loads `~/.pryrc` and `./.pryrc` as necessary the
|
126
136
|
# first time it is invoked.
|
127
137
|
# @param [Object, Binding] target The receiver of the Pry session
|
128
138
|
# @param [Hash] options
|
@@ -131,6 +141,7 @@ class Pry
|
|
131
141
|
# Pry.start(Object.new, :input => MyInput.new)
|
132
142
|
def self.start(target=nil, options={})
|
133
143
|
return if ENV['DISABLE_PRY']
|
144
|
+
options = options.to_hash
|
134
145
|
|
135
146
|
if in_critical_section?
|
136
147
|
output.puts "ERROR: Pry started inside Pry."
|
@@ -138,35 +149,24 @@ class Pry
|
|
138
149
|
return
|
139
150
|
end
|
140
151
|
|
141
|
-
target = Pry.binding_for(target || toplevel_binding)
|
152
|
+
options[:target] = Pry.binding_for(target || toplevel_binding)
|
153
|
+
options[:hooks] = Pry::Hooks.from_hash options.delete(:hooks) if options.key?(:hooks)
|
142
154
|
initial_session_setup
|
143
155
|
|
144
|
-
#
|
145
|
-
|
146
|
-
|
147
|
-
# save backtrace
|
148
|
-
pry_instance.backtrace = caller
|
156
|
+
# Unless we were given a backtrace, save the current one
|
157
|
+
if options[:backtrace].nil?
|
158
|
+
options[:backtrace] = caller
|
149
159
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
pry_instance.exec_hook(:when_started, target, options, pry_instance)
|
155
|
-
|
156
|
-
if !pry_instance.binding_stack.empty?
|
157
|
-
head = pry_instance.binding_stack.pop
|
158
|
-
else
|
159
|
-
head = target
|
160
|
+
# If Pry was started via `binding.pry`, elide that from the backtrace
|
161
|
+
if options[:backtrace].first =~ /pry.*core_extensions.*pry/
|
162
|
+
options[:backtrace].shift
|
163
|
+
end
|
160
164
|
end
|
161
165
|
|
162
|
-
|
163
|
-
# https://github.com/pry/pry/issues/566
|
164
|
-
if Pry.config.auto_indent
|
165
|
-
Kernel.print Pry::Helpers::BaseHelpers.windows_ansi? ? "\e[0F" : "\e[0G"
|
166
|
-
end
|
166
|
+
driver = options[:driver] || Pry::REPL
|
167
167
|
|
168
168
|
# Enter the matrix
|
169
|
-
|
169
|
+
driver.start(options)
|
170
170
|
rescue Pry::TooSafeException
|
171
171
|
puts "ERROR: Pry cannot work with $SAFE > 0"
|
172
172
|
raise
|
@@ -179,23 +179,40 @@ class Pry
|
|
179
179
|
REPLFileLoader.new(file_name).load
|
180
180
|
end
|
181
181
|
|
182
|
+
#
|
182
183
|
# An inspector that clips the output to `max_length` chars.
|
183
184
|
# In case of > `max_length` chars the `#<Object...> notation is used.
|
184
|
-
#
|
185
|
-
# @param
|
186
|
-
#
|
187
|
-
|
188
|
-
|
185
|
+
#
|
186
|
+
# @param [Object] obj
|
187
|
+
# The object to view.
|
188
|
+
#
|
189
|
+
# @param [Hash] options
|
190
|
+
# @option options [Integer] :max_length (60)
|
191
|
+
# The maximum number of chars before clipping occurs.
|
192
|
+
#
|
193
|
+
# @option options [Boolean] :id (false)
|
194
|
+
# Boolean to indicate whether or not a hex reprsentation of the object ID
|
195
|
+
# is attached to the return value when the length of inspect is greater than
|
196
|
+
# value of `:max_length`.
|
197
|
+
#
|
198
|
+
# @return [String]
|
199
|
+
# The string representation of `obj`.
|
200
|
+
#
|
201
|
+
def self.view_clip(obj, options = {})
|
202
|
+
max = options.fetch :max_length, 60
|
203
|
+
id = options.fetch :id, false
|
204
|
+
if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max
|
189
205
|
obj.name.to_s
|
190
|
-
elsif
|
191
|
-
# special
|
206
|
+
elsif Pry.main == obj
|
207
|
+
# special-case to support jruby.
|
208
|
+
# fixed as of https://github.com/jruby/jruby/commit/d365ebd309cf9df3dde28f5eb36ea97056e0c039
|
209
|
+
# we can drop in the future.
|
192
210
|
obj.to_s
|
193
|
-
elsif
|
211
|
+
elsif Pry.config.prompt_safe_objects.any? { |v| v === obj } && obj.inspect.length <= max
|
194
212
|
obj.inspect
|
195
213
|
else
|
196
|
-
"#<#{obj.class}
|
214
|
+
id == true ? "#<#{obj.class}:0x%x>" % (obj.object_id << 1) : "#<#{obj.class}>"
|
197
215
|
end
|
198
|
-
|
199
216
|
rescue RescuableException
|
200
217
|
"unknown"
|
201
218
|
end
|
@@ -205,11 +222,6 @@ class Pry
|
|
205
222
|
Pry.history.load
|
206
223
|
end
|
207
224
|
|
208
|
-
# Save new lines of Readline history if required.
|
209
|
-
def self.save_history
|
210
|
-
Pry.history.save
|
211
|
-
end
|
212
|
-
|
213
225
|
# @return [Boolean] Whether this is the first time a Pry session has
|
214
226
|
# been started since loading the Pry class.
|
215
227
|
def self.initial_session?
|
@@ -217,40 +229,40 @@ class Pry
|
|
217
229
|
end
|
218
230
|
|
219
231
|
# Run a Pry command from outside a session. The commands available are
|
220
|
-
# those referenced by `Pry.commands` (the default command set).
|
232
|
+
# those referenced by `Pry.config.commands` (the default command set).
|
221
233
|
# @param [String] command_string The Pry command (including arguments,
|
222
234
|
# if any).
|
223
235
|
# @param [Hash] options Optional named parameters.
|
224
236
|
# @return [Object] The return value of the Pry command.
|
225
|
-
# @option options [Object, Binding] :
|
237
|
+
# @option options [Object, Binding] :target The object to run the
|
226
238
|
# command under. Defaults to `TOPLEVEL_BINDING` (main).
|
227
239
|
# @option options [Boolean] :show_output Whether to show command
|
228
240
|
# output. Defaults to true.
|
229
241
|
# @example Run at top-level with no output.
|
230
242
|
# Pry.run_command "ls"
|
231
243
|
# @example Run under Pry class, returning only public methods.
|
232
|
-
# Pry.run_command "ls -m", :
|
244
|
+
# Pry.run_command "ls -m", :target => Pry
|
233
245
|
# @example Display command output.
|
234
246
|
# Pry.run_command "ls -av", :show_output => true
|
235
247
|
def self.run_command(command_string, options={})
|
236
248
|
options = {
|
237
|
-
:
|
249
|
+
:target => TOPLEVEL_BINDING,
|
238
250
|
:show_output => true,
|
239
|
-
:output => Pry.output,
|
240
|
-
:commands => Pry.commands
|
251
|
+
:output => Pry.config.output,
|
252
|
+
:commands => Pry.config.commands
|
241
253
|
}.merge!(options)
|
242
254
|
|
255
|
+
# :context for compatibility with <= 0.9.11.4
|
256
|
+
target = options[:context] || options[:target]
|
243
257
|
output = options[:show_output] ? options[:output] : StringIO.new
|
244
258
|
|
245
|
-
Pry.new(:output
|
246
|
-
|
247
|
-
:prompt => proc {""}, :hooks => Pry::Hooks.new).repl(options[:context])
|
259
|
+
pry = Pry.new(:output => output, :target => target, :commands => options[:commands])
|
260
|
+
pry.eval command_string
|
248
261
|
end
|
249
262
|
|
250
263
|
def self.default_editor_for_platform
|
251
264
|
return ENV['VISUAL'] if ENV['VISUAL'] and not ENV['VISUAL'].empty?
|
252
265
|
return ENV['EDITOR'] if ENV['EDITOR'] and not ENV['EDITOR'].empty?
|
253
|
-
|
254
266
|
if Helpers::BaseHelpers.windows?
|
255
267
|
'notepad'
|
256
268
|
else
|
@@ -261,19 +273,25 @@ class Pry
|
|
261
273
|
end
|
262
274
|
|
263
275
|
def self.auto_resize!
|
264
|
-
Pry.
|
265
|
-
|
266
|
-
if
|
276
|
+
Pry.config.input # by default, load Readline
|
277
|
+
|
278
|
+
if !defined?(Readline) || Pry.config.input != Readline
|
279
|
+
warn "Sorry, you must be using Readline for Pry.auto_resize! to work."
|
280
|
+
return
|
281
|
+
end
|
282
|
+
|
283
|
+
if Readline::VERSION =~ /edit/i
|
267
284
|
warn <<-EOT
|
268
|
-
Readline version #{
|
285
|
+
Readline version #{Readline::VERSION} detected - will not auto_resize! correctly.
|
269
286
|
For the fix, use GNU Readline instead:
|
270
287
|
https://github.com/guard/guard/wiki/Add-proper-Readline-support-to-Ruby-on-Mac-OS-X
|
271
288
|
EOT
|
272
289
|
return
|
273
290
|
end
|
291
|
+
|
274
292
|
trap :WINCH do
|
275
293
|
begin
|
276
|
-
Readline.set_screen_size
|
294
|
+
Readline.set_screen_size(*Terminal.size!)
|
277
295
|
rescue => e
|
278
296
|
warn "\nPry.auto_resize!'s Readline.set_screen_size failed: #{e}"
|
279
297
|
end
|
@@ -285,124 +303,19 @@ Readline version #{ver} detected - will not auto_resize! correctly.
|
|
285
303
|
end
|
286
304
|
end
|
287
305
|
|
288
|
-
def self.set_config_defaults
|
289
|
-
config.input = proc { Pry.require_readline; Readline }
|
290
|
-
config.output = $stdout
|
291
|
-
config.commands = Pry::Commands
|
292
|
-
config.prompt_name = DEFAULT_PROMPT_NAME
|
293
|
-
config.prompt = DEFAULT_PROMPT
|
294
|
-
config.print = DEFAULT_PRINT
|
295
|
-
config.exception_handler = DEFAULT_EXCEPTION_HANDLER
|
296
|
-
config.exception_whitelist = DEFAULT_EXCEPTION_WHITELIST
|
297
|
-
config.default_window_size = 5
|
298
|
-
config.hooks = DEFAULT_HOOKS
|
299
|
-
config.input_stack = []
|
300
|
-
config.color = Helpers::BaseHelpers.use_ansi_codes?
|
301
|
-
config.pager = true
|
302
|
-
config.system = DEFAULT_SYSTEM
|
303
|
-
config.editor = default_editor_for_platform
|
304
|
-
config.should_load_rc = true
|
305
|
-
config.should_load_local_rc = true
|
306
|
-
config.should_trap_interrupts = Helpers::BaseHelpers.jruby?
|
307
|
-
config.disable_auto_reload = false
|
308
|
-
config.command_prefix = ""
|
309
|
-
config.auto_indent = Helpers::BaseHelpers.use_ansi_codes?
|
310
|
-
config.correct_indent = true
|
311
|
-
config.collision_warning = false
|
312
|
-
config.output_prefix = "=> "
|
313
|
-
config.completer = Pry::BondCompleter
|
314
|
-
|
315
|
-
config.gist ||= OpenStruct.new
|
316
|
-
config.gist.inspecter = proc(&:pretty_inspect)
|
317
|
-
|
318
|
-
config.should_load_plugins = true
|
319
|
-
|
320
|
-
config.requires ||= []
|
321
|
-
config.should_load_requires = true
|
322
|
-
|
323
|
-
config.history ||= OpenStruct.new
|
324
|
-
config.history.should_save = true
|
325
|
-
config.history.should_load = true
|
326
|
-
config.history.file = File.expand_path("~/.pry_history") rescue nil
|
327
|
-
|
328
|
-
if config.history.file.nil?
|
329
|
-
config.should_load_rc = false
|
330
|
-
config.history.should_save = false
|
331
|
-
config.history.should_load = false
|
332
|
-
end
|
333
|
-
|
334
|
-
config.control_d_handler = DEFAULT_CONTROL_D_HANDLER
|
335
|
-
|
336
|
-
config.memory_size = 100
|
337
|
-
|
338
|
-
config.extra_sticky_locals = {}
|
339
|
-
|
340
|
-
config.ls ||= OpenStruct.new({
|
341
|
-
:heading_color => :bright_blue,
|
342
|
-
|
343
|
-
:public_method_color => :default,
|
344
|
-
:private_method_color => :blue,
|
345
|
-
:protected_method_color => :blue,
|
346
|
-
:method_missing_color => :bright_red,
|
347
|
-
|
348
|
-
:local_var_color => :yellow,
|
349
|
-
:pry_var_color => :default, # e.g. _, _pry_, _file_
|
350
|
-
|
351
|
-
:instance_var_color => :blue, # e.g. @foo
|
352
|
-
:class_var_color => :bright_blue, # e.g. @@foo
|
353
|
-
|
354
|
-
:global_var_color => :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
|
355
|
-
:builtin_global_color => :cyan, # e.g. $stdin, $-w, $PID
|
356
|
-
:pseudo_global_color => :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
|
357
|
-
|
358
|
-
:constant_color => :default, # e.g. VERSION, ARGF
|
359
|
-
:class_constant_color => :blue, # e.g. Object, Kernel
|
360
|
-
:exception_constant_color => :magenta, # e.g. Exception, RuntimeError
|
361
|
-
:unloaded_constant_color => :yellow, # Any constant that is still in .autoload? state
|
362
|
-
|
363
|
-
# What should separate items listed by ls? (TODO: we should allow a columnar layout)
|
364
|
-
:separator => " ",
|
365
|
-
|
366
|
-
# Any methods defined on these classes, or modules included into these classes, will not
|
367
|
-
# be shown by ls unless the -v flag is used.
|
368
|
-
# A user of Rails may wih to add ActiveRecord::Base to the list.
|
369
|
-
# add the following to your .pryrc:
|
370
|
-
# Pry.config.ls.ceiling << ActiveRecord::Base if defined? ActiveRecordBase
|
371
|
-
:ceiling => [Object, Module, Class]
|
372
|
-
})
|
373
|
-
end
|
374
|
-
|
375
306
|
# Set all the configurable options back to their default values
|
376
307
|
def self.reset_defaults
|
377
|
-
set_config_defaults
|
378
|
-
|
379
308
|
@initial_session = true
|
380
|
-
|
381
|
-
self.custom_completions = DEFAULT_CUSTOM_COMPLETIONS
|
309
|
+
self.config = Pry::Config.new Pry::Config::Default.new
|
382
310
|
self.cli = false
|
383
311
|
self.current_line = 1
|
384
312
|
self.line_buffer = [""]
|
385
313
|
self.eval_path = "(pry)"
|
386
|
-
|
387
|
-
fix_coderay_colors
|
388
|
-
end
|
389
|
-
|
390
|
-
# To avoid mass-confusion, we change the default colour of "white" to
|
391
|
-
# "blue" enabling global legibility
|
392
|
-
def self.fix_coderay_colors
|
393
|
-
colors = CodeRay::Encoders::Terminal::TOKEN_COLORS
|
394
|
-
|
395
|
-
if colors[:comment].is_a?(String)
|
396
|
-
colors[:comment] = "0;34"
|
397
|
-
end
|
398
314
|
end
|
399
315
|
|
400
316
|
# Basic initialization.
|
401
317
|
def self.init
|
402
318
|
@plugin_manager ||= PluginManager.new
|
403
|
-
self.config ||= Config.new
|
404
|
-
self.history ||= History.new
|
405
|
-
|
406
319
|
reset_defaults
|
407
320
|
locate_plugins
|
408
321
|
end
|
@@ -416,7 +329,7 @@ Readline version #{ver} detected - will not auto_resize! correctly.
|
|
416
329
|
if Binding === target
|
417
330
|
target
|
418
331
|
else
|
419
|
-
if
|
332
|
+
if Pry.main == target
|
420
333
|
TOPLEVEL_BINDING
|
421
334
|
else
|
422
335
|
target.__binding__
|
@@ -425,7 +338,7 @@ Readline version #{ver} detected - will not auto_resize! correctly.
|
|
425
338
|
end
|
426
339
|
|
427
340
|
def self.toplevel_binding
|
428
|
-
unless @toplevel_binding
|
341
|
+
unless defined?(@toplevel_binding) && @toplevel_binding
|
429
342
|
# Grab a copy of the TOPLEVEL_BINDING without any local variables.
|
430
343
|
# This binding has a default definee of Object, and new methods are
|
431
344
|
# private (just as in TOPLEVEL_BINDING).
|
@@ -441,15 +354,21 @@ Readline version #{ver} detected - will not auto_resize! correctly.
|
|
441
354
|
@toplevel_binding
|
442
355
|
end
|
443
356
|
|
357
|
+
def self.toplevel_binding=(binding)
|
358
|
+
@toplevel_binding = binding
|
359
|
+
end
|
360
|
+
|
444
361
|
def self.in_critical_section?
|
445
|
-
|
362
|
+
Thread.current[:pry_critical_section] ||= 0
|
363
|
+
Thread.current[:pry_critical_section] > 0
|
446
364
|
end
|
447
365
|
|
448
366
|
def self.critical_section(&block)
|
449
|
-
|
367
|
+
Thread.current[:pry_critical_section] ||= 0
|
368
|
+
Thread.current[:pry_critical_section] += 1
|
450
369
|
yield
|
451
370
|
ensure
|
452
|
-
|
371
|
+
Thread.current[:pry_critical_section] -= 1
|
453
372
|
end
|
454
373
|
end
|
455
374
|
|