pry 0.9.10pre1-java → 0.9.11-java
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGELOG +63 -2
- data/CONTRIBUTORS +43 -25
- data/Gemfile +7 -0
- data/Guardfile +62 -0
- data/README.markdown +4 -4
- data/Rakefile +34 -35
- data/lib/pry.rb +107 -54
- data/lib/pry/cli.rb +34 -11
- data/lib/pry/code.rb +165 -182
- data/lib/pry/code/code_range.rb +70 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +153 -0
- data/lib/pry/command.rb +160 -22
- data/lib/pry/command_set.rb +37 -26
- data/lib/pry/commands.rb +4 -27
- data/lib/pry/commands/amend_line.rb +99 -0
- data/lib/pry/commands/bang.rb +20 -0
- data/lib/pry/commands/bang_pry.rb +17 -0
- data/lib/pry/commands/cat.rb +53 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +78 -0
- data/lib/pry/commands/cat/file_formatter.rb +84 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +30 -0
- data/lib/pry/commands/code_collector.rb +165 -0
- data/lib/pry/commands/deprecated_commands.rb +2 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +206 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +38 -0
- data/lib/pry/commands/edit/method_patcher.rb +122 -0
- data/lib/pry/commands/exit.rb +42 -0
- data/lib/pry/commands/exit_all.rb +29 -0
- data/lib/pry/commands/exit_program.rb +24 -0
- data/lib/pry/commands/find_method.rb +199 -0
- data/lib/pry/commands/fix_indent.rb +19 -0
- data/lib/pry/commands/gem_cd.rb +26 -0
- data/lib/pry/commands/gem_install.rb +29 -0
- data/lib/pry/commands/gem_list.rb +33 -0
- data/lib/pry/commands/gem_open.rb +29 -0
- data/lib/pry/commands/gist.rb +95 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +161 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +51 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/ls.rb +339 -0
- data/lib/pry/commands/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +69 -0
- data/lib/pry/commands/pry_backtrace.rb +26 -0
- data/lib/pry/commands/pry_version.rb +17 -0
- data/lib/pry/commands/raise_up.rb +32 -0
- data/lib/pry/commands/reload_code.rb +39 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +56 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +43 -0
- data/lib/pry/commands/shell_mode.rb +27 -0
- data/lib/pry/commands/show_doc.rb +78 -0
- data/lib/pry/commands/show_info.rb +139 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +37 -0
- data/lib/pry/commands/simple_prompt.rb +22 -0
- data/lib/pry/commands/stat.rb +40 -0
- data/lib/pry/commands/switch_to.rb +23 -0
- data/lib/pry/commands/toggle_color.rb +20 -0
- data/lib/pry/commands/whereami.rb +114 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/completion.rb +120 -46
- data/lib/pry/config.rb +11 -0
- data/lib/pry/core_extensions.rb +30 -19
- data/lib/pry/editor.rb +129 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +89 -119
- data/lib/pry/helpers/command_helpers.rb +7 -122
- data/lib/pry/helpers/table.rb +100 -0
- data/lib/pry/helpers/text.rb +4 -4
- data/lib/pry/history_array.rb +5 -0
- data/lib/pry/hooks.rb +1 -3
- data/lib/pry/indent.rb +104 -30
- data/lib/pry/method.rb +66 -22
- data/lib/pry/module_candidate.rb +26 -15
- data/lib/pry/pager.rb +70 -0
- data/lib/pry/plugins.rb +1 -2
- data/lib/pry/pry_class.rb +63 -22
- data/lib/pry/pry_instance.rb +58 -37
- data/lib/pry/rubygem.rb +74 -0
- data/lib/pry/terminal_info.rb +43 -0
- data/lib/pry/test/helper.rb +185 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +58 -24
- data/pry.gemspec +21 -37
- data/{test/test_cli.rb → spec/cli_spec.rb} +0 -0
- data/spec/code_object_spec.rb +277 -0
- data/{test/test_code.rb → spec/code_spec.rb} +19 -1
- data/{test/test_command_helpers.rb → spec/command_helpers_spec.rb} +0 -0
- data/{test/test_command_integration.rb → spec/command_integration_spec.rb} +38 -46
- data/{test/test_command_set.rb → spec/command_set_spec.rb} +18 -1
- data/{test/test_command.rb → spec/command_spec.rb} +250 -149
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +19 -0
- data/spec/commands/cat_spec.rb +164 -0
- data/spec/commands/cd_spec.rb +250 -0
- data/spec/commands/disable_pry_spec.rb +25 -0
- data/spec/commands/edit_spec.rb +727 -0
- data/spec/commands/exit_all_spec.rb +34 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +34 -0
- data/{test/test_default_commands/test_find_method.rb → spec/commands/find_method_spec.rb} +27 -7
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +75 -0
- data/{test/test_default_commands/test_help.rb → spec/commands/help_spec.rb} +8 -9
- data/spec/commands/hist_spec.rb +181 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +177 -0
- data/spec/commands/play_spec.rb +140 -0
- data/spec/commands/raise_up_spec.rb +56 -0
- data/spec/commands/save_file_spec.rb +177 -0
- data/spec/commands/show_doc_spec.rb +378 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +597 -0
- data/spec/commands/whereami_spec.rb +154 -0
- data/spec/completion_spec.rb +233 -0
- data/spec/control_d_handler_spec.rb +58 -0
- data/spec/editor_spec.rb +79 -0
- data/{test/test_exception_whitelist.rb → spec/exception_whitelist_spec.rb} +0 -0
- data/{test → spec/fixtures}/candidate_helper1.rb +0 -0
- data/{test → spec/fixtures}/candidate_helper2.rb +0 -0
- data/{test/test_default_commands → spec/fixtures}/example.erb +0 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/{test → spec/fixtures}/testrc +0 -0
- data/{test → spec/fixtures}/testrcbad +0 -0
- data/spec/helper.rb +34 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +43 -0
- data/spec/helpers/table_spec.rb +83 -0
- data/{test/test_history_array.rb → spec/history_array_spec.rb} +21 -19
- data/{test/test_hooks.rb → spec/hooks_spec.rb} +0 -0
- data/{test/test_indent.rb → spec/indent_spec.rb} +24 -0
- data/{test/test_input_stack.rb → spec/input_stack_spec.rb} +4 -0
- data/{test/test_method.rb → spec/method_spec.rb} +65 -1
- data/{test/test_prompt.rb → spec/prompt_spec.rb} +0 -0
- data/{test/test_pry_defaults.rb → spec/pry_defaults_spec.rb} +14 -14
- data/{test/test_pry_history.rb → spec/pry_history_spec.rb} +15 -0
- data/spec/pry_output_spec.rb +95 -0
- data/{test/test_pry.rb → spec/pry_spec.rb} +74 -32
- data/{test/test_sticky_locals.rb → spec/sticky_locals_spec.rb} +27 -25
- data/{test/test_syntax_checking.rb → spec/syntax_checking_spec.rb} +17 -1
- data/{test/test_wrapped_module.rb → spec/wrapped_module_spec.rb} +92 -5
- metadata +239 -115
- data/examples/example_basic.rb +0 -15
- data/examples/example_command_override.rb +0 -32
- data/examples/example_commands.rb +0 -36
- data/examples/example_hooks.rb +0 -9
- data/examples/example_image_edit.rb +0 -67
- data/examples/example_input.rb +0 -7
- data/examples/example_input2.rb +0 -29
- data/examples/example_output.rb +0 -11
- data/examples/example_print.rb +0 -6
- data/examples/example_prompt.rb +0 -9
- data/examples/helper.rb +0 -6
- data/lib/pry/default_commands/cd.rb +0 -81
- data/lib/pry/default_commands/commands.rb +0 -62
- data/lib/pry/default_commands/context.rb +0 -98
- data/lib/pry/default_commands/easter_eggs.rb +0 -95
- data/lib/pry/default_commands/editing.rb +0 -420
- data/lib/pry/default_commands/find_method.rb +0 -169
- data/lib/pry/default_commands/gems.rb +0 -84
- data/lib/pry/default_commands/gist.rb +0 -187
- data/lib/pry/default_commands/help.rb +0 -127
- data/lib/pry/default_commands/hist.rb +0 -120
- data/lib/pry/default_commands/input_and_output.rb +0 -306
- data/lib/pry/default_commands/introspection.rb +0 -410
- data/lib/pry/default_commands/ls.rb +0 -272
- data/lib/pry/default_commands/misc.rb +0 -38
- data/lib/pry/default_commands/navigating_pry.rb +0 -110
- data/lib/pry/default_commands/whereami.rb +0 -92
- data/lib/pry/extended_commands/experimental.rb +0 -7
- data/test/helper.rb +0 -223
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/test_cd.rb +0 -321
- data/test/test_default_commands/test_context.rb +0 -288
- data/test/test_default_commands/test_documentation.rb +0 -315
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_input.rb +0 -428
- data/test/test_default_commands/test_introspection.rb +0 -511
- data/test/test_default_commands/test_ls.rb +0 -151
- data/test/test_default_commands/test_shell.rb +0 -343
- data/test/test_default_commands/test_show_source.rb +0 -432
- data/test/test_pry_output.rb +0 -41
data/lib/pry/pager.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
class Pry::Pager
|
2
|
+
# @param [String] text
|
3
|
+
# A piece of text to run through a pager.
|
4
|
+
# @param [Symbol?] pager
|
5
|
+
# `:simple` -- Use the pure ruby pager.
|
6
|
+
# `:system` -- Use the system pager (less) or the environment variable
|
7
|
+
# $PAGER if set.
|
8
|
+
# `nil` -- Infer what pager to use from the environment. What this
|
9
|
+
# really means is that JRuby and systems that do not have
|
10
|
+
# access to 'less' will run through the pure ruby pager.
|
11
|
+
def self.page(text, pager = nil)
|
12
|
+
case pager
|
13
|
+
when nil
|
14
|
+
no_pager = !SystemPager.available?
|
15
|
+
is_jruby = defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
|
16
|
+
(is_jruby || no_pager) ? SimplePager.new(text).page : SystemPager.new(text).page
|
17
|
+
when :simple
|
18
|
+
SimplePager.new(text).page
|
19
|
+
when :system
|
20
|
+
SystemPager.new(text).page
|
21
|
+
else
|
22
|
+
raise "'#{pager}' is not a recognized pager."
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.page_size
|
27
|
+
27
|
28
|
+
end
|
29
|
+
|
30
|
+
def initialize(text)
|
31
|
+
@text = text
|
32
|
+
end
|
33
|
+
|
34
|
+
class SimplePager < Pry::Pager
|
35
|
+
def page
|
36
|
+
text_array = @text.lines.to_a
|
37
|
+
text_array.each_slice(Pry::Pager.page_size) do |chunk|
|
38
|
+
puts chunk.join
|
39
|
+
break if chunk.size < Pry::Pager.page_size
|
40
|
+
if text_array.size > Pry::Pager.page_size
|
41
|
+
puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
|
42
|
+
break if $stdin.gets.chomp == "q"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
class SystemPager < Pry::Pager
|
49
|
+
def self.default_pager
|
50
|
+
ENV["PAGER"] || "less -R -S -F -X"
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.available?
|
54
|
+
pager_executable = default_pager.split(' ').first
|
55
|
+
`which #{ pager_executable }`
|
56
|
+
rescue
|
57
|
+
end
|
58
|
+
|
59
|
+
def initialize(*)
|
60
|
+
super
|
61
|
+
@pager = SystemPager.default_pager
|
62
|
+
end
|
63
|
+
|
64
|
+
def page
|
65
|
+
IO.popen(@pager, 'w') do |io|
|
66
|
+
io.write @text
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/pry/plugins.rb
CHANGED
@@ -48,7 +48,7 @@ class Pry
|
|
48
48
|
begin
|
49
49
|
require gem_name if !active?
|
50
50
|
rescue LoadError => e
|
51
|
-
warn "
|
51
|
+
warn "Found plugin #{gem_name}, but could not require '#{gem_name}'"
|
52
52
|
warn e
|
53
53
|
end
|
54
54
|
|
@@ -99,4 +99,3 @@ class Pry
|
|
99
99
|
end
|
100
100
|
|
101
101
|
end
|
102
|
-
|
data/lib/pry/pry_class.rb
CHANGED
@@ -5,9 +5,14 @@ require 'pry/config'
|
|
5
5
|
class Pry
|
6
6
|
|
7
7
|
# The RC Files to load.
|
8
|
-
|
8
|
+
HOME_RC_FILE = "~/.pryrc"
|
9
9
|
LOCAL_RC_FILE = "./.pryrc"
|
10
10
|
|
11
|
+
# @return [Hash] Pry's `Thread.current` hash
|
12
|
+
def self.current
|
13
|
+
Thread.current[:__pry__] ||= {}
|
14
|
+
end
|
15
|
+
|
11
16
|
# class accessors
|
12
17
|
class << self
|
13
18
|
extend Forwardable
|
@@ -57,29 +62,28 @@ class Pry
|
|
57
62
|
:hooks, :color, :pager, :editor, :memory_size, :input_stack, :extra_sticky_locals
|
58
63
|
end
|
59
64
|
|
60
|
-
|
61
65
|
# Load the given file in the context of `Pry.toplevel_binding`
|
62
66
|
# @param [String] file_name The unexpanded file path.
|
63
67
|
def self.load_file_at_toplevel(file_name)
|
64
68
|
full_name = File.expand_path(file_name)
|
65
69
|
begin
|
66
|
-
toplevel_binding.eval(File.read(full_name)) if File.exists?(full_name)
|
70
|
+
toplevel_binding.eval(File.read(full_name), full_name) if File.exists?(full_name)
|
67
71
|
rescue RescuableException => e
|
68
|
-
puts "Error loading #{file_name}: #{e}"
|
72
|
+
puts "Error loading #{file_name}: #{e}\n#{e.backtrace.first}"
|
69
73
|
end
|
70
74
|
end
|
71
75
|
|
72
76
|
# Load the rc files given in the `Pry::RC_FILES` array.
|
73
77
|
# This method can also be used to reload the files if they have changed.
|
74
78
|
def self.load_rc
|
75
|
-
|
76
|
-
load_file_at_toplevel(file_name)
|
77
|
-
end
|
79
|
+
load_file_at_toplevel(HOME_RC_FILE)
|
78
80
|
end
|
79
81
|
|
80
82
|
# Load the local RC file (./.pryrc)
|
81
83
|
def self.load_local_rc
|
82
|
-
|
84
|
+
unless File.expand_path(HOME_RC_FILE) == File.expand_path(LOCAL_RC_FILE)
|
85
|
+
load_file_at_toplevel(LOCAL_RC_FILE)
|
86
|
+
end
|
83
87
|
end
|
84
88
|
|
85
89
|
# Load any Ruby files specified with the -r flag on the command line.
|
@@ -115,15 +119,23 @@ class Pry
|
|
115
119
|
end
|
116
120
|
|
117
121
|
# Start a Pry REPL.
|
118
|
-
# This method also loads the
|
122
|
+
# This method also loads the ~/.pryrc and ./.pryrc as necessary
|
119
123
|
# first time it is invoked.
|
120
124
|
# @param [Object, Binding] target The receiver of the Pry session
|
121
125
|
# @param [Hash] options
|
122
126
|
# @option options (see Pry#initialize)
|
123
127
|
# @example
|
124
128
|
# Pry.start(Object.new, :input => MyInput.new)
|
125
|
-
def self.start(target=
|
126
|
-
|
129
|
+
def self.start(target=nil, options={})
|
130
|
+
return if ENV['DISABLE_PRY']
|
131
|
+
|
132
|
+
if in_critical_section?
|
133
|
+
output.puts "ERROR: Pry started inside Pry."
|
134
|
+
output.puts "This can happen if you have a binding.pry inside a #to_s or #inspect function."
|
135
|
+
return
|
136
|
+
end
|
137
|
+
|
138
|
+
target = Pry.binding_for(target || toplevel_binding)
|
127
139
|
initial_session_setup
|
128
140
|
|
129
141
|
# create the Pry instance to manage the session
|
@@ -152,6 +164,9 @@ class Pry
|
|
152
164
|
|
153
165
|
# Enter the matrix
|
154
166
|
pry_instance.repl(head)
|
167
|
+
rescue Pry::TooSafeException
|
168
|
+
puts "ERROR: Pry cannot work with $SAFE > 0"
|
169
|
+
raise
|
155
170
|
end
|
156
171
|
|
157
172
|
# Execute the file through the REPL loop, non-interactively.
|
@@ -244,6 +259,7 @@ class Pry
|
|
244
259
|
config.input = Readline
|
245
260
|
config.output = $stdout
|
246
261
|
config.commands = Pry::Commands
|
262
|
+
config.prompt_name = DEFAULT_PROMPT_NAME
|
247
263
|
config.prompt = DEFAULT_PROMPT
|
248
264
|
config.print = DEFAULT_PRINT
|
249
265
|
config.exception_handler = DEFAULT_EXCEPTION_HANDLER
|
@@ -263,6 +279,13 @@ class Pry
|
|
263
279
|
config.auto_indent = Helpers::BaseHelpers.use_ansi_codes?
|
264
280
|
config.correct_indent = true
|
265
281
|
config.collision_warning = false
|
282
|
+
config.output_prefix = "=> "
|
283
|
+
|
284
|
+
if defined?(Bond) && Readline::VERSION !~ /editline/i
|
285
|
+
config.completer = Pry::BondCompleter
|
286
|
+
else
|
287
|
+
config.completer = Pry::InputCompleter
|
288
|
+
end
|
266
289
|
|
267
290
|
config.gist ||= OpenStruct.new
|
268
291
|
config.gist.inspecter = proc(&:pretty_inspect)
|
@@ -297,8 +320,8 @@ class Pry
|
|
297
320
|
:protected_method_color => :yellow,
|
298
321
|
:method_missing_color => :bright_red,
|
299
322
|
|
300
|
-
:local_var_color => :
|
301
|
-
:pry_var_color => :
|
323
|
+
:local_var_color => :yellow,
|
324
|
+
:pry_var_color => :default, # e.g. _, _pry_, _file_
|
302
325
|
|
303
326
|
:instance_var_color => :blue, # e.g. @foo
|
304
327
|
:class_var_color => :bright_blue, # e.g. @@foo
|
@@ -383,16 +406,34 @@ class Pry
|
|
383
406
|
end
|
384
407
|
end
|
385
408
|
end
|
386
|
-
end
|
387
409
|
|
388
|
-
|
389
|
-
|
390
|
-
#
|
391
|
-
|
392
|
-
|
410
|
+
def self.toplevel_binding
|
411
|
+
unless @toplevel_binding
|
412
|
+
# Grab a copy of the TOPLEVEL_BINDING without any local variables.
|
413
|
+
# This binding has a default definee of Object, and new methods are
|
414
|
+
# private (just as in TOPLEVEL_BINDING).
|
415
|
+
TOPLEVEL_BINDING.eval <<-RUBY
|
416
|
+
def self.__pry__
|
417
|
+
binding
|
418
|
+
end
|
419
|
+
Pry.toplevel_binding = __pry__
|
420
|
+
class << self; undef __pry__; end
|
421
|
+
RUBY
|
422
|
+
end
|
423
|
+
@toplevel_binding.eval('private')
|
424
|
+
@toplevel_binding
|
425
|
+
end
|
426
|
+
|
427
|
+
def self.in_critical_section?
|
428
|
+
@critical_section.to_i > 0
|
429
|
+
end
|
430
|
+
|
431
|
+
def self.critical_section(&block)
|
432
|
+
@critical_section = @critical_section.to_i + 1
|
433
|
+
yield
|
434
|
+
ensure
|
435
|
+
@critical_section -= 1
|
436
|
+
end
|
393
437
|
end
|
394
|
-
Pry.toplevel_binding = __binding_impl__
|
395
|
-
Pry.toplevel_binding.eval("private")
|
396
|
-
class << self; undef __binding_impl__; end
|
397
438
|
|
398
439
|
Pry.init
|
data/lib/pry/pry_instance.rb
CHANGED
@@ -97,13 +97,15 @@ class Pry
|
|
97
97
|
attributes = [
|
98
98
|
:input, :output, :commands, :print, :quiet,
|
99
99
|
:exception_handler, :hooks, :custom_completions,
|
100
|
-
:prompt, :memory_size, :
|
100
|
+
:prompt, :memory_size, :extra_sticky_locals
|
101
101
|
]
|
102
102
|
|
103
103
|
attributes.each do |attribute|
|
104
104
|
defaults[attribute] = Pry.send attribute
|
105
105
|
end
|
106
106
|
|
107
|
+
defaults[:input_stack] = Pry.input_stack.dup
|
108
|
+
|
107
109
|
defaults.merge!(options).each do |key, value|
|
108
110
|
send("#{key}=", value) if respond_to?("#{key}=")
|
109
111
|
end
|
@@ -143,10 +145,10 @@ class Pry
|
|
143
145
|
# @param [Binding] b The binding to set the local on.
|
144
146
|
# @return [Object] The value the local was set to.
|
145
147
|
def inject_local(name, value, b)
|
146
|
-
|
147
|
-
b.eval("#{name} = ::
|
148
|
+
Pry.current[:pry_local] = value.is_a?(Proc) ? value.call : value
|
149
|
+
b.eval("#{name} = ::Pry.current[:pry_local]")
|
148
150
|
ensure
|
149
|
-
|
151
|
+
Pry.current[:pry_local] = nil
|
150
152
|
end
|
151
153
|
|
152
154
|
# @return [Integer] The maximum amount of objects remembered by the inp and
|
@@ -186,7 +188,8 @@ class Pry
|
|
186
188
|
:_ex_ => proc { last_exception },
|
187
189
|
:_file_ => proc { last_file },
|
188
190
|
:_dir_ => proc { last_dir },
|
189
|
-
:_ => proc { last_result }
|
191
|
+
:_ => proc { last_result },
|
192
|
+
:__ => proc { @output_array[-2] }
|
190
193
|
}.merge(extra_sticky_locals)
|
191
194
|
end
|
192
195
|
|
@@ -196,7 +199,6 @@ class Pry
|
|
196
199
|
exec_hook :before_session, output, target, self
|
197
200
|
set_last_result(nil, target)
|
198
201
|
|
199
|
-
|
200
202
|
@input_array << nil # add empty input so _in_ and _out_ match
|
201
203
|
|
202
204
|
binding_stack.push target
|
@@ -228,6 +230,7 @@ class Pry
|
|
228
230
|
exception = catch(:raise_up) do
|
229
231
|
break_data = catch(:breakout) do
|
230
232
|
loop do
|
233
|
+
throw(:breakout) if binding_stack.empty?
|
231
234
|
rep(binding_stack.last)
|
232
235
|
end
|
233
236
|
end
|
@@ -250,7 +253,9 @@ class Pry
|
|
250
253
|
target = Pry.binding_for(target)
|
251
254
|
result = re(target)
|
252
255
|
|
253
|
-
|
256
|
+
Pry.critical_section do
|
257
|
+
show_result(result)
|
258
|
+
end
|
254
259
|
end
|
255
260
|
|
256
261
|
# Perform a read-eval
|
@@ -265,23 +270,15 @@ class Pry
|
|
265
270
|
target = Pry.binding_for(target)
|
266
271
|
|
267
272
|
# It's not actually redundant to inject them continually as we may have
|
268
|
-
# moved into the scope of a new Binding (e.g the user typed `cd`)
|
273
|
+
# moved into the scope of a new Binding (e.g the user typed `cd`).
|
269
274
|
inject_sticky_locals(target)
|
270
275
|
|
271
276
|
code = r(target)
|
272
277
|
|
273
|
-
|
274
|
-
|
275
|
-
result = target.eval(code, Pry.eval_path, Pry.current_line)
|
276
|
-
set_last_result(result, target, code)
|
277
|
-
|
278
|
-
result
|
278
|
+
evaluate_ruby(code, target)
|
279
279
|
rescue RescuableException => e
|
280
280
|
self.last_exception = e
|
281
281
|
e
|
282
|
-
ensure
|
283
|
-
update_input_history(code)
|
284
|
-
exec_hook :after_eval, result, self
|
285
282
|
end
|
286
283
|
|
287
284
|
# Perform a read.
|
@@ -309,23 +306,39 @@ class Pry
|
|
309
306
|
begin
|
310
307
|
break if Pry::Code.complete_expression?(eval_string)
|
311
308
|
rescue SyntaxError => e
|
312
|
-
output
|
309
|
+
exception_handler.call(output, e.extend(UserError), self)
|
313
310
|
eval_string = ""
|
314
311
|
end
|
315
312
|
end
|
316
313
|
|
317
|
-
|
314
|
+
if eval_string =~ /;\Z/ || eval_string.empty? || eval_string =~ /\A *#.*\n\z/
|
315
|
+
@suppress_output = true
|
316
|
+
end
|
318
317
|
|
319
318
|
exec_hook :after_read, eval_string, self
|
320
319
|
eval_string
|
321
320
|
end
|
322
321
|
|
322
|
+
def evaluate_ruby(code, target = binding_stack.last)
|
323
|
+
target = Pry.binding_for(target)
|
324
|
+
inject_sticky_locals(target)
|
325
|
+
exec_hook :before_eval, code, self
|
326
|
+
|
327
|
+
result = target.eval(code, Pry.eval_path, Pry.current_line)
|
328
|
+
set_last_result(result, target, code)
|
329
|
+
ensure
|
330
|
+
update_input_history(code)
|
331
|
+
exec_hook :after_eval, result, self
|
332
|
+
end
|
333
|
+
|
323
334
|
# Output the result or pass to an exception handler (if result is an exception).
|
324
335
|
def show_result(result)
|
325
336
|
if last_result_is_exception?
|
326
337
|
exception_handler.call(output, result, self)
|
327
|
-
|
338
|
+
elsif should_print?
|
328
339
|
print.call(output, result)
|
340
|
+
else
|
341
|
+
# nothin'
|
329
342
|
end
|
330
343
|
rescue RescuableException => e
|
331
344
|
# Being uber-paranoid here, given that this exception arose because we couldn't
|
@@ -359,14 +372,15 @@ class Pry
|
|
359
372
|
@indent.reset if eval_string.empty?
|
360
373
|
|
361
374
|
current_prompt = select_prompt(eval_string, target)
|
362
|
-
completion_proc = Pry
|
375
|
+
completion_proc = Pry.config.completer.build_completion_proc(target, self,
|
363
376
|
instance_eval(&custom_completions))
|
364
377
|
|
378
|
+
safe_completion_proc = proc{ |*a| Pry.critical_section{ completion_proc.call(*a) } }
|
365
379
|
|
366
380
|
indentation = Pry.config.auto_indent ? @indent.current_prefix : ''
|
367
381
|
|
368
382
|
begin
|
369
|
-
val = readline("#{current_prompt}#{indentation}",
|
383
|
+
val = readline("#{current_prompt}#{indentation}", safe_completion_proc)
|
370
384
|
|
371
385
|
# Handle <Ctrl+C> like Bash, empty the current input buffer but do not quit.
|
372
386
|
# This is only for ruby-1.9; other versions of ruby do not let you send Interrupt
|
@@ -403,12 +417,16 @@ class Pry
|
|
403
417
|
indented_val = val
|
404
418
|
end
|
405
419
|
|
420
|
+
# Check this before processing the line, because a command might change
|
421
|
+
# Pry's input.
|
422
|
+
interactive = !input.is_a?(StringIO)
|
423
|
+
|
406
424
|
begin
|
407
425
|
if !process_command(val, eval_string, target)
|
408
|
-
eval_string << "#{indented_val.
|
426
|
+
eval_string << "#{indented_val.chomp}\n" unless val.empty?
|
409
427
|
end
|
410
428
|
ensure
|
411
|
-
Pry.history << indented_val
|
429
|
+
Pry.history << indented_val if interactive
|
412
430
|
end
|
413
431
|
end
|
414
432
|
|
@@ -419,7 +437,8 @@ class Pry
|
|
419
437
|
# @param [String] eval_string The cumulative lines of input.
|
420
438
|
# @param [Binding] target The target of the Pry session.
|
421
439
|
# @return [Boolean] `true` if `val` is a command, `false` otherwise
|
422
|
-
def process_command(val, eval_string, target)
|
440
|
+
def process_command(val, eval_string = '', target = binding_stack.last)
|
441
|
+
val = val.chomp
|
423
442
|
result = commands.process_line(val, {
|
424
443
|
:target => target,
|
425
444
|
:output => output,
|
@@ -428,7 +447,7 @@ class Pry
|
|
428
447
|
})
|
429
448
|
|
430
449
|
# set a temporary (just so we can inject the value we want into eval_string)
|
431
|
-
|
450
|
+
Pry.current[:pry_cmd_result] = result
|
432
451
|
|
433
452
|
# note that `result` wraps the result of command processing; if a
|
434
453
|
# command was matched and invoked then `result.command?` returns true,
|
@@ -438,7 +457,7 @@ class Pry
|
|
438
457
|
# the command that was invoked was non-void (had a return value) and so we make
|
439
458
|
# the value of the current expression equal to the return value
|
440
459
|
# of the command.
|
441
|
-
eval_string.replace "
|
460
|
+
eval_string.replace "::Pry.current[:pry_cmd_result].retval\n"
|
442
461
|
end
|
443
462
|
true
|
444
463
|
else
|
@@ -590,7 +609,8 @@ class Pry
|
|
590
609
|
|
591
610
|
if defined? Coolline and input.is_a? Coolline
|
592
611
|
input.completion_proc = proc do |cool|
|
593
|
-
completion_proc.call cool.completed_word
|
612
|
+
completions = completion_proc.call cool.completed_word
|
613
|
+
completions.compact
|
594
614
|
end
|
595
615
|
elsif input.respond_to? :completion_proc=
|
596
616
|
input.completion_proc = completion_proc
|
@@ -611,11 +631,10 @@ class Pry
|
|
611
631
|
end
|
612
632
|
|
613
633
|
# Whether the print proc should be invoked.
|
614
|
-
# Currently only invoked if the output is not suppressed
|
615
|
-
# is an exception regardless of suppression.
|
634
|
+
# Currently only invoked if the output is not suppressed.
|
616
635
|
# @return [Boolean] Whether the print proc should be invoked.
|
617
636
|
def should_print?
|
618
|
-
!@suppress_output
|
637
|
+
!@suppress_output
|
619
638
|
end
|
620
639
|
|
621
640
|
# Returns the appropriate prompt to use.
|
@@ -642,13 +661,15 @@ class Pry
|
|
642
661
|
:eval_string => eval_string,
|
643
662
|
:cont => !eval_string.empty?)
|
644
663
|
|
645
|
-
|
646
|
-
|
647
|
-
|
664
|
+
Pry.critical_section do
|
665
|
+
# If input buffer is empty then use normal prompt
|
666
|
+
if eval_string.empty?
|
667
|
+
generate_prompt(Array(prompt).first, c)
|
648
668
|
|
649
|
-
|
650
|
-
|
651
|
-
|
669
|
+
# Otherwise use the wait prompt (indicating multi-line expression)
|
670
|
+
else
|
671
|
+
generate_prompt(Array(prompt).last, c)
|
672
|
+
end
|
652
673
|
end
|
653
674
|
end
|
654
675
|
|