pry 0.10.2-i386-mingw32 → 1.0.0.pre1-i386-mingw32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.document +2 -0
- data/.gitignore +16 -0
- data/.travis.yml +21 -0
- data/.yardopts +3 -0
- data/CHANGELOG +503 -0
- data/CONTRIBUTORS +55 -0
- data/Gemfile +9 -0
- data/Guardfile +62 -0
- data/LICENSE +2 -2
- data/{README.md → README.markdown} +31 -37
- data/Rakefile +144 -0
- data/TODO +117 -0
- data/lib/pry.rb +146 -33
- data/lib/pry/cli.rb +13 -35
- data/lib/pry/code.rb +63 -24
- data/lib/pry/code/loc.rb +2 -2
- data/lib/pry/code_object.rb +21 -40
- data/lib/pry/command.rb +6 -9
- data/lib/pry/command_set.rb +37 -80
- data/lib/pry/commands.rb +1 -1
- data/lib/pry/commands/amend_line.rb +1 -1
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat.rb +2 -11
- data/lib/pry/commands/cat/abstract_formatter.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +7 -6
- data/lib/pry/commands/cat/file_formatter.rb +32 -15
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cd.rb +3 -14
- data/lib/pry/commands/code_collector.rb +4 -4
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +22 -10
- data/lib/pry/commands/edit/exception_patcher.rb +1 -1
- data/lib/pry/commands/edit/file_and_line_locator.rb +2 -0
- data/lib/pry/{method/patcher.rb → commands/edit/method_patcher.rb} +37 -40
- data/lib/pry/commands/find_method.rb +22 -16
- data/lib/pry/commands/gem_install.rb +2 -5
- data/lib/pry/commands/gem_open.rb +1 -1
- data/lib/pry/commands/gist.rb +11 -10
- data/lib/pry/commands/help.rb +14 -14
- data/lib/pry/commands/hist.rb +5 -24
- data/lib/pry/commands/ls.rb +287 -56
- data/lib/pry/commands/play.rb +10 -44
- data/lib/pry/commands/pry_backtrace.rb +2 -1
- data/lib/pry/commands/raise_up.rb +1 -1
- data/lib/pry/commands/reload_code.rb +15 -31
- data/lib/pry/commands/ri.rb +3 -7
- data/lib/pry/commands/shell_command.rb +12 -17
- data/lib/pry/commands/shell_mode.rb +2 -2
- data/lib/pry/commands/show_doc.rb +0 -5
- data/lib/pry/commands/show_info.rb +10 -11
- data/lib/pry/commands/show_source.rb +3 -15
- data/lib/pry/commands/simple_prompt.rb +1 -1
- data/lib/pry/commands/toggle_color.rb +4 -8
- data/lib/pry/commands/whereami.rb +10 -18
- data/lib/pry/completion.rb +293 -0
- data/lib/pry/config.rb +233 -20
- data/lib/pry/core_extensions.rb +19 -29
- data/lib/pry/custom_completions.rb +6 -0
- data/lib/pry/editor.rb +103 -109
- data/lib/pry/helpers/base_helpers.rb +109 -22
- data/lib/pry/helpers/command_helpers.rb +8 -10
- data/lib/pry/helpers/documentation_helpers.rb +2 -1
- data/lib/pry/helpers/text.rb +5 -4
- data/lib/pry/history.rb +10 -21
- data/lib/pry/history_array.rb +0 -5
- data/lib/pry/hooks.rb +29 -9
- data/lib/pry/indent.rb +10 -5
- data/lib/pry/method.rb +86 -81
- data/lib/pry/method/weird_method_locator.rb +2 -4
- data/lib/pry/module_candidate.rb +14 -5
- data/lib/pry/pager.rb +48 -193
- data/lib/pry/plugins.rb +2 -2
- data/lib/pry/pry_class.rb +193 -104
- data/lib/pry/pry_instance.rb +154 -152
- data/lib/pry/rbx_method.rb +13 -0
- data/lib/pry/rbx_path.rb +1 -1
- data/lib/pry/repl.rb +14 -17
- data/lib/pry/repl_file_loader.rb +3 -8
- data/lib/pry/rubygem.rb +3 -3
- data/lib/pry/terminal.rb +3 -4
- data/lib/pry/test/helper.rb +11 -6
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +56 -49
- data/man/pry.1 +195 -0
- data/man/pry.1.html +204 -0
- data/man/pry.1.ronn +141 -0
- data/pry.gemspec +31 -0
- data/spec/Procfile +3 -0
- data/spec/cli_spec.rb +78 -0
- data/spec/code_object_spec.rb +277 -0
- data/spec/code_spec.rb +219 -0
- data/spec/command_helpers_spec.rb +29 -0
- data/spec/command_integration_spec.rb +562 -0
- data/spec/command_set_spec.rb +627 -0
- data/spec/command_spec.rb +821 -0
- data/spec/commands/amend_line_spec.rb +247 -0
- data/spec/commands/bang_spec.rb +18 -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 +725 -0
- data/spec/commands/exit_all_spec.rb +27 -0
- data/spec/commands/exit_program_spec.rb +19 -0
- data/spec/commands/exit_spec.rb +28 -0
- data/spec/commands/find_method_spec.rb +70 -0
- data/spec/commands/gem_list_spec.rb +26 -0
- data/spec/commands/gist_spec.rb +79 -0
- data/spec/commands/help_spec.rb +56 -0
- data/spec/commands/hist_spec.rb +172 -0
- data/spec/commands/jump_to_spec.rb +15 -0
- data/spec/commands/ls_spec.rb +189 -0
- data/spec/commands/play_spec.rb +136 -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 +488 -0
- data/spec/commands/show_input_spec.rb +17 -0
- data/spec/commands/show_source_spec.rb +760 -0
- data/spec/commands/whereami_spec.rb +203 -0
- data/spec/completion_spec.rb +221 -0
- data/spec/control_d_handler_spec.rb +62 -0
- data/spec/documentation_helper_spec.rb +73 -0
- data/spec/editor_spec.rb +79 -0
- data/spec/exception_whitelist_spec.rb +21 -0
- data/spec/fixtures/candidate_helper1.rb +11 -0
- data/spec/fixtures/candidate_helper2.rb +8 -0
- data/spec/fixtures/example.erb +5 -0
- data/spec/fixtures/example_nesting.rb +33 -0
- data/spec/fixtures/show_source_doc_examples.rb +15 -0
- data/spec/fixtures/testlinkrc +2 -0
- data/spec/fixtures/testrc +2 -0
- data/spec/fixtures/testrcbad +2 -0
- data/spec/fixtures/whereami_helper.rb +6 -0
- data/spec/helper.rb +35 -0
- data/spec/helpers/bacon.rb +86 -0
- data/spec/helpers/mock_pry.rb +44 -0
- data/spec/helpers/repl_tester.rb +112 -0
- data/spec/helpers/table_spec.rb +105 -0
- data/spec/history_array_spec.rb +67 -0
- data/spec/hooks_spec.rb +522 -0
- data/spec/indent_spec.rb +301 -0
- data/spec/method_spec.rb +482 -0
- data/spec/prompt_spec.rb +61 -0
- data/spec/pry_defaults_spec.rb +420 -0
- data/spec/pry_history_spec.rb +69 -0
- data/spec/pry_output_spec.rb +95 -0
- data/spec/pry_repl_spec.rb +86 -0
- data/spec/pry_spec.rb +394 -0
- data/spec/pryrc_spec.rb +97 -0
- data/spec/run_command_spec.rb +25 -0
- data/spec/sticky_locals_spec.rb +147 -0
- data/spec/syntax_checking_spec.rb +81 -0
- data/spec/wrapped_module_spec.rb +261 -0
- data/wiki/Customizing-pry.md +397 -0
- data/wiki/Home.md +4 -0
- metadata +272 -61
- checksums.yaml +0 -7
- data/CHANGELOG.md +0 -714
- data/lib/pry/code/code_file.rb +0 -103
- data/lib/pry/color_printer.rb +0 -55
- data/lib/pry/commands/change_inspector.rb +0 -27
- data/lib/pry/commands/change_prompt.rb +0 -26
- data/lib/pry/commands/list_inspectors.rb +0 -35
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/ls/constants.rb +0 -47
- data/lib/pry/commands/ls/formatter.rb +0 -49
- data/lib/pry/commands/ls/globals.rb +0 -48
- data/lib/pry/commands/ls/grep.rb +0 -21
- data/lib/pry/commands/ls/instance_vars.rb +0 -39
- data/lib/pry/commands/ls/interrogatable.rb +0 -18
- data/lib/pry/commands/ls/jruby_hacks.rb +0 -49
- data/lib/pry/commands/ls/local_names.rb +0 -35
- data/lib/pry/commands/ls/local_vars.rb +0 -39
- data/lib/pry/commands/ls/ls_entity.rb +0 -70
- data/lib/pry/commands/ls/methods.rb +0 -57
- data/lib/pry/commands/ls/methods_helper.rb +0 -46
- data/lib/pry/commands/ls/self_methods.rb +0 -32
- data/lib/pry/commands/watch_expression.rb +0 -105
- data/lib/pry/commands/watch_expression/expression.rb +0 -38
- data/lib/pry/config/behavior.rb +0 -139
- data/lib/pry/config/convenience.rb +0 -25
- data/lib/pry/config/default.rb +0 -161
- data/lib/pry/exceptions.rb +0 -78
- data/lib/pry/input_completer.rb +0 -242
- data/lib/pry/input_lock.rb +0 -132
- data/lib/pry/inspector.rb +0 -27
- data/lib/pry/last_exception.rb +0 -61
- data/lib/pry/object_path.rb +0 -82
- data/lib/pry/output.rb +0 -50
- data/lib/pry/prompt.rb +0 -26
data/lib/pry/core_extensions.rb
CHANGED
@@ -89,7 +89,7 @@ class Object
|
|
89
89
|
# If we can't define methods on the Object's singleton_class. Then we fall
|
90
90
|
# back to setting the default definee to be the Object's class. That seems
|
91
91
|
# nicer than having a REPL in which you can't define methods.
|
92
|
-
rescue TypeError
|
92
|
+
rescue TypeError
|
93
93
|
# class_eval sets the default definee to self.class
|
94
94
|
self.class.class_eval(*Pry::BINDING_METHOD_IMPL)
|
95
95
|
end
|
@@ -99,33 +99,23 @@ class Object
|
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
# definition is eval'd.
|
121
|
-
#
|
122
|
-
# Please don't call this method directly, see {__binding__}.
|
123
|
-
#
|
124
|
-
# @return [Binding]
|
125
|
-
def __pry__
|
126
|
-
::Kernel.binding
|
127
|
-
end
|
128
|
-
EOF
|
129
|
-
self.__pry__
|
102
|
+
# There's a splat bug on jruby in 1.9 emulation mode, which breaks the
|
103
|
+
# pp library.
|
104
|
+
#
|
105
|
+
# * http://jira.codehaus.org/browse/JRUBY-6687
|
106
|
+
# * https://github.com/pry/pry/issues/568
|
107
|
+
#
|
108
|
+
# Until that gets fixed upstream, let's monkey-patch here:
|
109
|
+
if [[1, 2]].pretty_inspect == "[1]\n"
|
110
|
+
class Array
|
111
|
+
def pretty_print(q)
|
112
|
+
q.group(1, '[', ']') {
|
113
|
+
i = 0
|
114
|
+
q.seplist(self) { |*|
|
115
|
+
q.pp self[i]
|
116
|
+
i += 1
|
117
|
+
}
|
118
|
+
}
|
119
|
+
end
|
130
120
|
end
|
131
121
|
end
|
data/lib/pry/editor.rb
CHANGED
@@ -1,135 +1,129 @@
|
|
1
1
|
class Pry
|
2
2
|
class Editor
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
f.flush
|
16
|
-
f.close(false)
|
17
|
-
invoke_editor(f.path, line, true)
|
18
|
-
File.read(f.path)
|
3
|
+
extend Pry::Helpers::BaseHelpers
|
4
|
+
extend Pry::Helpers::CommandHelpers
|
5
|
+
|
6
|
+
class << self
|
7
|
+
def edit_tempfile_with_content(initial_content, line=1)
|
8
|
+
temp_file do |f|
|
9
|
+
f.puts(initial_content)
|
10
|
+
f.flush
|
11
|
+
f.close(false)
|
12
|
+
invoke_editor(f.path, line, true)
|
13
|
+
File.read(f.path)
|
14
|
+
end
|
19
15
|
end
|
20
|
-
end
|
21
16
|
|
22
|
-
|
23
|
-
|
17
|
+
def invoke_editor(file, line, blocking=true)
|
18
|
+
raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless Pry.config.editor
|
24
19
|
|
25
|
-
|
26
|
-
|
20
|
+
editor_invocation = build_editor_invocation_string(file, line, blocking)
|
21
|
+
return nil unless editor_invocation
|
27
22
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
if jruby?
|
24
|
+
open_editor_on_jruby(editor_invocation)
|
25
|
+
else
|
26
|
+
open_editor(editor_invocation)
|
27
|
+
end
|
32
28
|
end
|
33
|
-
end
|
34
29
|
|
35
|
-
|
30
|
+
private
|
36
31
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
32
|
+
# Generate the string that's used to start the editor. This includes
|
33
|
+
# all the flags we want as well as the file and line number we
|
34
|
+
# want to open at.
|
35
|
+
def build_editor_invocation_string(file, line, blocking)
|
41
36
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
37
|
+
if Pry.config.editor.respond_to?(:call)
|
38
|
+
args = [file, line, blocking][0...(Pry.config.editor.arity)]
|
39
|
+
Pry.config.editor.call(*args)
|
40
|
+
else
|
41
|
+
sanitized_file = if windows?
|
42
|
+
file.gsub(/\//, '\\')
|
43
|
+
else
|
44
|
+
Shellwords.escape(file)
|
45
|
+
end
|
51
46
|
|
52
|
-
|
47
|
+
"#{Pry.config.editor} #{blocking_flag_for_editor(blocking)} #{start_line_syntax_for_editor(sanitized_file, line)}"
|
48
|
+
end
|
53
49
|
end
|
54
|
-
end
|
55
50
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
51
|
+
# Start the editor running, using the calculated invocation string
|
52
|
+
def open_editor(editor_invocation)
|
53
|
+
# Note we dont want to use Pry.config.system here as that
|
54
|
+
# may be invoked non-interactively (i.e via Open4), whereas we want to
|
55
|
+
# ensure the editor is always interactive
|
56
|
+
system(editor_invocation) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
|
57
|
+
end
|
63
58
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
59
|
+
# We need JRuby specific code here cos just shelling out using
|
60
|
+
# system() appears to be pretty broken :/
|
61
|
+
def open_editor_on_jruby(editor_invocation)
|
62
|
+
begin
|
63
|
+
require 'spoon'
|
64
|
+
pid = Spoon.spawnp(*editor_invocation.split)
|
65
|
+
Process.waitpid(pid)
|
66
|
+
rescue FFI::NotFoundError
|
67
|
+
system(editor_invocation)
|
68
|
+
end
|
73
69
|
end
|
74
|
-
end
|
75
70
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
71
|
+
# Some editors that run outside the terminal allow you to control whether or
|
72
|
+
# not to block the process from which they were launched (in this case, Pry).
|
73
|
+
# For those editors, return the flag that produces the desired behavior.
|
74
|
+
def blocking_flag_for_editor(blocking)
|
75
|
+
case editor_name
|
76
|
+
when /^emacsclient/
|
77
|
+
'--no-wait' unless blocking
|
78
|
+
when /^[gm]vim/
|
79
|
+
'--nofork' if blocking
|
80
|
+
when /^jedit/
|
81
|
+
'-wait' if blocking
|
82
|
+
when /^mate/, /^subl/
|
83
|
+
'-w' if blocking
|
84
|
+
end
|
89
85
|
end
|
90
|
-
end
|
91
86
|
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
87
|
+
# Return the syntax for a given editor for starting the editor
|
88
|
+
# and moving to a particular line within that file
|
89
|
+
def start_line_syntax_for_editor(file_name, line_number)
|
90
|
+
# special case for 1st line
|
91
|
+
return file_name if line_number <= 1
|
97
92
|
|
98
|
-
|
99
|
-
|
100
|
-
"+#{line_number} #{file_name}"
|
101
|
-
when /^mate/, /^geany/
|
102
|
-
"-l #{line_number} #{file_name}"
|
103
|
-
when /^subl/
|
104
|
-
"#{file_name}:#{line_number}"
|
105
|
-
when /^uedit32/
|
106
|
-
"#{file_name}/#{line_number}"
|
107
|
-
when /^jedit/
|
108
|
-
"#{file_name} +line:#{line_number}"
|
109
|
-
when /^redcar/
|
110
|
-
"-l#{line_number} #{file_name}"
|
111
|
-
else
|
112
|
-
if windows?
|
113
|
-
"#{file_name}"
|
114
|
-
else
|
93
|
+
case editor_name
|
94
|
+
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
115
95
|
"+#{line_number} #{file_name}"
|
96
|
+
when /^mate/, /^geany/
|
97
|
+
"-l #{line_number} #{file_name}"
|
98
|
+
when /^subl/
|
99
|
+
"#{file_name}:#{line_number}"
|
100
|
+
when /^uedit32/
|
101
|
+
"#{file_name}/#{line_number}"
|
102
|
+
when /^jedit/
|
103
|
+
"#{file_name} +line:#{line_number}"
|
104
|
+
else
|
105
|
+
if windows?
|
106
|
+
"#{file_name}"
|
107
|
+
else
|
108
|
+
"+#{line_number} #{file_name}"
|
109
|
+
end
|
116
110
|
end
|
117
111
|
end
|
118
|
-
end
|
119
112
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
113
|
+
# Get the name of the binary that Pry.config.editor points to.
|
114
|
+
#
|
115
|
+
# This is useful for deciding which flags we pass to the editor as
|
116
|
+
# we can just use the program's name and ignore any absolute paths.
|
117
|
+
#
|
118
|
+
# @example
|
119
|
+
# Pry.config.editor="/home/conrad/bin/textmate -w"
|
120
|
+
# editor_name
|
121
|
+
# # => textmate
|
122
|
+
#
|
123
|
+
def editor_name
|
124
|
+
File.basename(Pry.config.editor).split(" ").first
|
125
|
+
end
|
133
126
|
|
127
|
+
end
|
134
128
|
end
|
135
129
|
end
|
@@ -42,12 +42,25 @@ class Pry
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
+
def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
|
46
|
+
return if !target or !file_name
|
47
|
+
_pry_.last_file = File.expand_path(file_name)
|
48
|
+
_pry_.inject_local("_file_", _pry_.last_file, target)
|
49
|
+
|
50
|
+
_pry_.last_dir = File.dirname(_pry_.last_file)
|
51
|
+
_pry_.inject_local("_dir_", _pry_.last_dir, target)
|
52
|
+
end
|
53
|
+
|
45
54
|
def use_ansi_codes?
|
46
55
|
windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
47
56
|
end
|
48
57
|
|
49
58
|
def colorize_code(code)
|
50
|
-
|
59
|
+
if Pry.color
|
60
|
+
CodeRay.scan(code, :ruby).term
|
61
|
+
else
|
62
|
+
code
|
63
|
+
end
|
51
64
|
end
|
52
65
|
|
53
66
|
def highlight(string, regexp, highlight_color=:bright_yellow)
|
@@ -57,7 +70,7 @@ class Pry
|
|
57
70
|
# formatting
|
58
71
|
def heading(text)
|
59
72
|
text = "#{text}\n--"
|
60
|
-
"\e[1m#{text}\e[0m"
|
73
|
+
Pry.color ? "\e[1m#{text}\e[0m": text
|
61
74
|
end
|
62
75
|
|
63
76
|
# have fun on the Windows platform.
|
@@ -67,7 +80,7 @@ class Pry
|
|
67
80
|
|
68
81
|
# are we able to use ansi on windows?
|
69
82
|
def windows_ansi?
|
70
|
-
defined?(Win32::Console) || ENV['ANSICON']
|
83
|
+
defined?(Win32::Console) || ENV['ANSICON']
|
71
84
|
end
|
72
85
|
|
73
86
|
def jruby?
|
@@ -75,39 +88,113 @@ class Pry
|
|
75
88
|
end
|
76
89
|
|
77
90
|
def jruby_19?
|
78
|
-
|
91
|
+
RbConfig::CONFIG['ruby_install_name'] == 'jruby' &&
|
92
|
+
RbConfig::CONFIG['ruby_version'] == '1.9'
|
79
93
|
end
|
80
94
|
|
81
95
|
def rbx?
|
82
96
|
RbConfig::CONFIG['ruby_install_name'] == 'rbx'
|
83
97
|
end
|
84
98
|
|
85
|
-
def
|
86
|
-
RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
99
|
+
def mri_18?
|
100
|
+
RUBY_VERSION =~ /1.8/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
87
101
|
end
|
88
102
|
|
89
103
|
def mri_19?
|
90
|
-
|
104
|
+
RUBY_VERSION =~ /1.9/ && RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
91
105
|
end
|
92
106
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
107
|
+
# Try to use `less` for paging, if it fails then use
|
108
|
+
# simple_pager. Also do not page if Pry.pager is falsey
|
109
|
+
def stagger_output(text, out = nil)
|
110
|
+
out ||= case
|
111
|
+
when respond_to?(:output)
|
112
|
+
# Mixin.
|
113
|
+
output
|
114
|
+
when Pry.respond_to?(:output)
|
115
|
+
# Parent.
|
116
|
+
Pry.output
|
117
|
+
else
|
118
|
+
# Sys.
|
119
|
+
$stdout
|
120
|
+
end
|
121
|
+
|
122
|
+
if text.lines.count < Pry::Pager.page_size || !Pry.pager
|
123
|
+
out.puts text
|
124
|
+
else
|
125
|
+
Pry::Pager.page(text)
|
126
|
+
end
|
127
|
+
rescue Errno::ENOENT
|
128
|
+
Pry::Pager.page(text, :simple)
|
129
|
+
rescue Errno::EPIPE
|
130
|
+
end
|
131
|
+
|
132
|
+
# @param [String] arg_string The object path expressed as a string.
|
133
|
+
# @param [Pry] _pry_ The relevant Pry instance.
|
134
|
+
# @param [Array<Binding>] old_stack The state of the old binding stack
|
135
|
+
# @return [Array<Array<Binding>, Array<Binding>>] An array
|
136
|
+
# containing two elements: The new `binding_stack` and the old `binding_stack`.
|
137
|
+
def context_from_object_path(arg_string, _pry_=nil, old_stack=[])
|
138
|
+
|
139
|
+
# Extract command arguments. Delete blank arguments like " ", but
|
140
|
+
# don't delete empty strings like "".
|
141
|
+
path = arg_string.split(/\//).delete_if { |a| a =~ /\A\s+\z/ }
|
142
|
+
stack = _pry_.binding_stack.dup
|
143
|
+
state_old_stack = old_stack
|
144
|
+
|
145
|
+
# Special case when we only get a single "/", return to root.
|
146
|
+
if path.empty?
|
147
|
+
state_old_stack = stack.dup unless old_stack.empty?
|
148
|
+
stack = [stack.first]
|
149
|
+
end
|
100
150
|
|
101
|
-
|
102
|
-
|
151
|
+
path.each_with_index do |context, i|
|
152
|
+
begin
|
153
|
+
case context.chomp
|
154
|
+
when ""
|
155
|
+
state_old_stack = stack.dup
|
156
|
+
stack = [stack.first]
|
157
|
+
when "::"
|
158
|
+
state_old_stack = stack.dup
|
159
|
+
stack.push(TOPLEVEL_BINDING)
|
160
|
+
when "."
|
161
|
+
next
|
162
|
+
when ".."
|
163
|
+
unless stack.size == 1
|
164
|
+
# Don't rewrite old_stack if we're in complex expression
|
165
|
+
# (e.g.: `cd 1/2/3/../4).
|
166
|
+
state_old_stack = stack.dup if path.first == ".."
|
167
|
+
stack.pop
|
168
|
+
end
|
169
|
+
when "-"
|
170
|
+
unless old_stack.empty?
|
171
|
+
# Interchange current stack and old stack with each other.
|
172
|
+
stack, state_old_stack = state_old_stack, stack
|
173
|
+
end
|
174
|
+
else
|
175
|
+
state_old_stack = stack.dup if i == 0
|
176
|
+
stack.push(Pry.binding_for(stack.last.eval(context)))
|
177
|
+
end
|
178
|
+
|
179
|
+
rescue RescuableException => e
|
180
|
+
# Restore old stack to its initial values.
|
181
|
+
state_old_stack = old_stack
|
182
|
+
|
183
|
+
msg = [
|
184
|
+
"Bad object path: #{arg_string}.",
|
185
|
+
"Failed trying to resolve: #{context}.",
|
186
|
+
e.inspect
|
187
|
+
].join(' ')
|
188
|
+
|
189
|
+
CommandError.new(msg).tap do |err|
|
190
|
+
err.set_backtrace e.backtrace
|
191
|
+
raise err
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
return stack, state_old_stack
|
103
196
|
end
|
104
197
|
|
105
|
-
# Send the given text through the best available pager (if Pry.config.pager is
|
106
|
-
# enabled). Infers where to send the output if used as a mixin.
|
107
|
-
# DEPRECATED.
|
108
|
-
def stagger_output(text, out = nil)
|
109
|
-
Pry.new.pager.page text
|
110
|
-
end
|
111
198
|
end
|
112
199
|
end
|
113
200
|
end
|