pry 0.10.pre.1-i386-mswin32 → 0.10.0.pre3-i386-mswin32
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +702 -0
- data/LICENSE +2 -2
- data/{README.markdown → README.md} +41 -35
- data/lib/pry.rb +82 -139
- data/lib/pry/cli.rb +77 -30
- data/lib/pry/code.rb +122 -183
- data/lib/pry/code/code_file.rb +103 -0
- data/lib/pry/code/code_range.rb +71 -0
- data/lib/pry/code/loc.rb +92 -0
- data/lib/pry/code_object.rb +172 -0
- data/lib/pry/color_printer.rb +55 -0
- data/lib/pry/command.rb +184 -28
- data/lib/pry/command_set.rb +113 -59
- 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 +62 -0
- data/lib/pry/commands/cat/abstract_formatter.rb +27 -0
- data/lib/pry/commands/cat/exception_formatter.rb +77 -0
- data/lib/pry/commands/cat/file_formatter.rb +67 -0
- data/lib/pry/commands/cat/input_expression_formatter.rb +43 -0
- data/lib/pry/commands/cd.rb +41 -0
- 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 +165 -0
- data/lib/pry/commands/disable_pry.rb +27 -0
- data/lib/pry/commands/disabled_commands.rb +2 -0
- data/lib/pry/commands/easter_eggs.rb +112 -0
- data/lib/pry/commands/edit.rb +195 -0
- data/lib/pry/commands/edit/exception_patcher.rb +25 -0
- data/lib/pry/commands/edit/file_and_line_locator.rb +36 -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 +23 -0
- data/lib/pry/commands/find_method.rb +193 -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 +32 -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 +101 -0
- data/lib/pry/commands/help.rb +164 -0
- data/lib/pry/commands/hist.rb +180 -0
- data/lib/pry/commands/import_set.rb +22 -0
- data/lib/pry/commands/install_command.rb +53 -0
- data/lib/pry/commands/jump_to.rb +29 -0
- data/lib/pry/commands/list_inspectors.rb +35 -0
- data/lib/pry/commands/list_prompts.rb +35 -0
- data/lib/pry/commands/ls.rb +114 -0
- 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/nesting.rb +25 -0
- data/lib/pry/commands/play.rb +103 -0
- data/lib/pry/commands/pry_backtrace.rb +25 -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 +62 -0
- data/lib/pry/commands/reset.rb +18 -0
- data/lib/pry/commands/ri.rb +60 -0
- data/lib/pry/commands/save_file.rb +61 -0
- data/lib/pry/commands/shell_command.rb +48 -0
- data/lib/pry/commands/shell_mode.rb +25 -0
- data/lib/pry/commands/show_doc.rb +83 -0
- data/lib/pry/commands/show_info.rb +195 -0
- data/lib/pry/commands/show_input.rb +17 -0
- data/lib/pry/commands/show_source.rb +50 -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 +24 -0
- 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 +190 -0
- data/lib/pry/commands/wtf.rb +57 -0
- data/lib/pry/config.rb +20 -229
- 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 +59 -38
- data/lib/pry/editor.rb +133 -0
- data/lib/pry/exceptions.rb +77 -0
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/helpers/base_helpers.rb +40 -154
- data/lib/pry/helpers/command_helpers.rb +19 -130
- data/lib/pry/helpers/documentation_helpers.rb +21 -11
- data/lib/pry/helpers/table.rb +109 -0
- data/lib/pry/helpers/text.rb +8 -9
- data/lib/pry/history.rb +61 -45
- data/lib/pry/history_array.rb +11 -1
- data/lib/pry/hooks.rb +10 -32
- data/lib/pry/indent.rb +110 -38
- 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 +199 -200
- data/lib/pry/method/disowned.rb +53 -0
- data/lib/pry/method/patcher.rb +125 -0
- data/lib/pry/method/weird_method_locator.rb +186 -0
- data/lib/pry/module_candidate.rb +39 -33
- data/lib/pry/object_path.rb +82 -0
- data/lib/pry/output.rb +50 -0
- data/lib/pry/pager.rb +234 -0
- data/lib/pry/plugins.rb +4 -3
- data/lib/pry/prompt.rb +26 -0
- data/lib/pry/pry_class.rb +199 -227
- data/lib/pry/pry_instance.rb +344 -403
- 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 +82 -0
- data/lib/pry/terminal.rb +79 -0
- data/lib/pry/test/helper.rb +170 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/wrapped_module.rb +133 -48
- metadata +132 -197
- data/.document +0 -2
- data/.gemtest +0 -0
- data/.gitignore +0 -16
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/CHANGELOG +0 -387
- data/CONTRIBUTORS +0 -36
- data/Gemfile +0 -2
- data/Rakefile +0 -137
- data/TODO +0 -117
- 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/completion.rb +0 -221
- data/lib/pry/custom_completions.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/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 -46
- data/test/candidate_helper1.rb +0 -11
- data/test/candidate_helper2.rb +0 -8
- data/test/helper.rb +0 -223
- data/test/test_cli.rb +0 -78
- data/test/test_code.rb +0 -201
- data/test/test_command.rb +0 -712
- data/test/test_command_helpers.rb +0 -9
- data/test/test_command_integration.rb +0 -668
- data/test/test_command_set.rb +0 -610
- data/test/test_completion.rb +0 -62
- data/test/test_control_d_handler.rb +0 -45
- data/test/test_default_commands/example.erb +0 -5
- data/test/test_default_commands/test_cd.rb +0 -318
- data/test/test_default_commands/test_context.rb +0 -280
- data/test/test_default_commands/test_documentation.rb +0 -314
- data/test/test_default_commands/test_find_method.rb +0 -50
- data/test/test_default_commands/test_gems.rb +0 -18
- data/test/test_default_commands/test_help.rb +0 -57
- 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_exception_whitelist.rb +0 -21
- data/test/test_history_array.rb +0 -65
- data/test/test_hooks.rb +0 -521
- data/test/test_indent.rb +0 -277
- data/test/test_input_stack.rb +0 -86
- data/test/test_method.rb +0 -401
- data/test/test_pry.rb +0 -463
- data/test/test_pry_defaults.rb +0 -419
- data/test/test_pry_history.rb +0 -84
- data/test/test_pry_output.rb +0 -41
- data/test/test_sticky_locals.rb +0 -155
- data/test/test_syntax_checking.rb +0 -65
- data/test/test_wrapped_module.rb +0 -174
- data/test/testrc +0 -2
- data/test/testrcbad +0 -2
- data/wiki/Customizing-pry.md +0 -397
- data/wiki/Home.md +0 -4
@@ -0,0 +1,77 @@
|
|
1
|
+
class Pry
|
2
|
+
|
3
|
+
# As a REPL, we often want to catch any unexpected exceptions that may have
|
4
|
+
# been raised; however we don't want to go overboard and prevent the user
|
5
|
+
# from exiting Pry when they want to.
|
6
|
+
module RescuableException
|
7
|
+
def self.===(exception)
|
8
|
+
case exception
|
9
|
+
# Catch when the user hits ^C (Interrupt < SignalException), and assume
|
10
|
+
# that they just wanted to stop the in-progress command (just like bash
|
11
|
+
# etc.)
|
12
|
+
when Interrupt
|
13
|
+
true
|
14
|
+
# Don't catch signals (particularly not SIGTERM) as these are unlikely
|
15
|
+
# to be intended for pry itself. We should also make sure that
|
16
|
+
# Kernel#exit works.
|
17
|
+
when *Pry.config.exception_whitelist
|
18
|
+
false
|
19
|
+
# All other exceptions will be caught.
|
20
|
+
else
|
21
|
+
true
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# Catches SecurityErrors if $SAFE is set
|
27
|
+
module Pry::TooSafeException
|
28
|
+
def self.===(exception)
|
29
|
+
$SAFE > 0 && SecurityError === exception
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# An Exception Tag (cf. Exceptional Ruby) that instructs Pry to show the error
|
34
|
+
# in a more user-friendly manner. This should be used when the exception
|
35
|
+
# happens within Pry itself as a direct consequence of the user typing
|
36
|
+
# something wrong.
|
37
|
+
#
|
38
|
+
# This allows us to distinguish between the user typing:
|
39
|
+
#
|
40
|
+
# pry(main)> def )
|
41
|
+
# SyntaxError: unexpected )
|
42
|
+
#
|
43
|
+
# pry(main)> method_that_evals("def )")
|
44
|
+
# SyntaxError: (eval):1: syntax error, unexpected ')'
|
45
|
+
# from ./a.rb:2 in `eval'
|
46
|
+
module UserError; end
|
47
|
+
|
48
|
+
# When we try to get a binding for an object, we try to define a method on
|
49
|
+
# that Object's singleton class. This doesn't work for "frozen" Object's, and
|
50
|
+
# the exception is just a vanilla RuntimeError.
|
51
|
+
module FrozenObjectException
|
52
|
+
def self.===(exception)
|
53
|
+
["can't modify frozen class/module",
|
54
|
+
"can't modify frozen Class",
|
55
|
+
].include?(exception.message)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
# Don't catch these exceptions
|
60
|
+
DEFAULT_EXCEPTION_WHITELIST = [SystemExit,
|
61
|
+
SignalException,
|
62
|
+
Pry::TooSafeException]
|
63
|
+
|
64
|
+
# CommandErrors are caught by the REPL loop and displayed to the user. They
|
65
|
+
# indicate an exceptional condition that's fatal to the current command.
|
66
|
+
class CommandError < StandardError; end
|
67
|
+
class MethodNotFound < CommandError; end
|
68
|
+
|
69
|
+
# indicates obsolete API
|
70
|
+
class ObsoleteError < StandardError; end
|
71
|
+
|
72
|
+
# This is to keep from breaking under Rails 3.2 for people who are doing that
|
73
|
+
# IRB = Pry thing.
|
74
|
+
module ExtendCommandBundle
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
data/lib/pry/helpers.rb
CHANGED
@@ -15,16 +15,20 @@ class Pry
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
18
|
+
# Acts like send but ignores any methods defined below Object or Class in the
|
19
|
+
# inheritance hierarchy.
|
20
|
+
# This is required to introspect methods on objects like Net::HTTP::Get that
|
21
|
+
# have overridden the `method` method.
|
22
|
+
def safe_send(obj, method, *args, &block)
|
23
|
+
(Module === obj ? Module : Object).instance_method(method).bind(obj).call(*args, &block)
|
24
|
+
end
|
25
|
+
public :safe_send
|
26
|
+
|
27
|
+
def find_command(name, set = Pry::Commands)
|
28
|
+
command_match = set.find do |_, command|
|
29
|
+
(listing = command.options[:listing]) == name && listing != nil
|
30
|
+
end
|
31
|
+
command_match.last if command_match
|
28
32
|
end
|
29
33
|
|
30
34
|
def not_a_real_file?(file)
|
@@ -34,51 +38,16 @@ class Pry
|
|
34
38
|
def command_dependencies_met?(options)
|
35
39
|
return true if !options[:requires_gem]
|
36
40
|
Array(options[:requires_gem]).all? do |g|
|
37
|
-
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def set_file_and_dir_locals(file_name)
|
42
|
-
return if !target or !file_name
|
43
|
-
_pry_.last_file = File.expand_path(file_name)
|
44
|
-
_pry_.inject_local("_file_", _pry_.last_file, target)
|
45
|
-
|
46
|
-
_pry_.last_dir = File.dirname(_pry_.last_file)
|
47
|
-
_pry_.inject_local("_dir_", _pry_.last_dir, target)
|
48
|
-
end
|
49
|
-
|
50
|
-
def stub_proc(name, options)
|
51
|
-
gems_needed = Array(options[:requires_gem])
|
52
|
-
gems_not_installed = gems_needed.select { |g| !gem_installed?(g) }
|
53
|
-
proc do
|
54
|
-
output.puts "\nThe command '#{name}' requires the following gems to be installed: #{(gems_needed.join(", "))}"
|
55
|
-
output.puts "-"
|
56
|
-
output.puts "Command not available due to dependency on gems: `#{gems_not_installed.join(", ")}` not being met."
|
57
|
-
output.puts "-"
|
58
|
-
output.puts "Type `install #{name}` to install the required gems and activate this command."
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def create_command_stub(names, description, options, block)
|
63
|
-
Array(names).each do |name|
|
64
|
-
commands[name] = {
|
65
|
-
:description => "Not available. Execute #{(name)} command for more information.",
|
66
|
-
:action => stub_proc(name, options),
|
67
|
-
:stub_info => options
|
68
|
-
}
|
41
|
+
Rubygem.installed?(g)
|
69
42
|
end
|
70
43
|
end
|
71
44
|
|
72
45
|
def use_ansi_codes?
|
73
|
-
|
46
|
+
windows_ansi? || ENV['TERM'] && ENV['TERM'] != "dumb"
|
74
47
|
end
|
75
48
|
|
76
49
|
def colorize_code(code)
|
77
|
-
|
78
|
-
CodeRay.scan(code, :ruby).term
|
79
|
-
else
|
80
|
-
code
|
81
|
-
end
|
50
|
+
CodeRay.scan(code, :ruby).term
|
82
51
|
end
|
83
52
|
|
84
53
|
def highlight(string, regexp, highlight_color=:bright_yellow)
|
@@ -88,11 +57,7 @@ class Pry
|
|
88
57
|
# formatting
|
89
58
|
def heading(text)
|
90
59
|
text = "#{text}\n--"
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
def page_size
|
95
|
-
27
|
60
|
+
"\e[1m#{text}\e[0m"
|
96
61
|
end
|
97
62
|
|
98
63
|
# have fun on the Windows platform.
|
@@ -102,126 +67,47 @@ class Pry
|
|
102
67
|
|
103
68
|
# are we able to use ansi on windows?
|
104
69
|
def windows_ansi?
|
105
|
-
defined?(Win32::Console) || ENV['ANSICON']
|
70
|
+
defined?(Win32::Console) || ENV['ANSICON'] || (windows? && mri_2?)
|
106
71
|
end
|
107
72
|
|
108
|
-
# are we on Jruby platform?
|
109
73
|
def jruby?
|
110
74
|
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
111
75
|
end
|
112
76
|
|
113
|
-
|
77
|
+
def jruby_19?
|
78
|
+
jruby? && RbConfig::CONFIG['ruby_version'] == '1.9'
|
79
|
+
end
|
80
|
+
|
114
81
|
def rbx?
|
115
82
|
RbConfig::CONFIG['ruby_install_name'] == 'rbx'
|
116
83
|
end
|
117
84
|
|
118
|
-
def
|
119
|
-
|
85
|
+
def mri?
|
86
|
+
RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
120
87
|
end
|
121
88
|
|
122
89
|
def mri_19?
|
123
|
-
RUBY_VERSION =~
|
124
|
-
end
|
125
|
-
|
126
|
-
# a simple pager for systems without `less`. A la windows.
|
127
|
-
def simple_pager(text, output=output())
|
128
|
-
text_array = text.lines.to_a
|
129
|
-
text_array.each_slice(page_size) do |chunk|
|
130
|
-
output.puts chunk.join
|
131
|
-
break if chunk.size < page_size
|
132
|
-
if text_array.size > page_size
|
133
|
-
output.puts "\n<page break> --- Press enter to continue ( q<enter> to break ) --- <page break>"
|
134
|
-
break if $stdin.gets.chomp == "q"
|
135
|
-
end
|
136
|
-
end
|
90
|
+
mri? && RUBY_VERSION =~ /^1\.9/
|
137
91
|
end
|
138
92
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
def stagger_output(text, out = nil)
|
143
|
-
out ||= case
|
144
|
-
when respond_to?(:output)
|
145
|
-
# Mixin.
|
146
|
-
output
|
147
|
-
when Pry.respond_to?(:output)
|
148
|
-
# Parent.
|
149
|
-
Pry.output
|
150
|
-
else
|
151
|
-
# Sys.
|
152
|
-
$stdout
|
153
|
-
end
|
154
|
-
|
155
|
-
if text.lines.count < page_size || !Pry.pager
|
156
|
-
out.puts text
|
157
|
-
return
|
158
|
-
end
|
159
|
-
|
160
|
-
# FIXME! Another JRuby hack
|
161
|
-
if jruby?
|
162
|
-
simple_pager(text, out)
|
163
|
-
else
|
164
|
-
lesspipe { |less| less.puts text }
|
165
|
-
end
|
166
|
-
rescue Errno::ENOENT
|
167
|
-
simple_pager(text, out)
|
168
|
-
rescue Errno::EPIPE
|
169
|
-
end
|
170
|
-
|
171
|
-
#
|
172
|
-
# Create scrollable output via less!
|
173
|
-
#
|
174
|
-
# This command runs `less` in a subprocess, and gives you the IO to its STDIN pipe
|
175
|
-
# so that you can communicate with it.
|
176
|
-
#
|
177
|
-
# Example:
|
178
|
-
#
|
179
|
-
# lesspipe do |less|
|
180
|
-
# 50.times { less.puts "Hi mom!" }
|
181
|
-
# end
|
182
|
-
#
|
183
|
-
# The default less parameters are:
|
184
|
-
# * Allow colour
|
185
|
-
# * Don't wrap lines longer than the screen
|
186
|
-
# * Quit immediately (without paging) if there's less than one screen of text.
|
187
|
-
#
|
188
|
-
# You can change these options by passing a hash to `lesspipe`, like so:
|
189
|
-
#
|
190
|
-
# lesspipe(:wrap=>false) { |less| less.puts essay.to_s }
|
191
|
-
#
|
192
|
-
# It accepts the following boolean options:
|
193
|
-
# :color => Allow ANSI colour codes?
|
194
|
-
# :wrap => Wrap long lines?
|
195
|
-
# :always => Always page, even if there's less than one page of text?
|
196
|
-
#
|
197
|
-
def lesspipe(*args)
|
198
|
-
if args.any? and args.last.is_a?(Hash)
|
199
|
-
options = args.pop
|
200
|
-
else
|
201
|
-
options = {}
|
202
|
-
end
|
93
|
+
def mri_2?
|
94
|
+
mri? && RUBY_VERSION =~ /^2/
|
95
|
+
end
|
203
96
|
|
204
|
-
|
97
|
+
def mri_20?
|
98
|
+
mri? && RUBY_VERSION =~ /^2\.0/
|
99
|
+
end
|
205
100
|
|
206
|
-
|
207
|
-
|
208
|
-
params << "-S" unless options[:wrap] == true
|
209
|
-
params << "-F" unless options[:always] == true
|
210
|
-
if options[:tail] == true
|
211
|
-
params << "+\\>"
|
212
|
-
$stderr.puts "Seeking to end of stream..."
|
213
|
-
end
|
214
|
-
params << "-X"
|
215
|
-
|
216
|
-
IO.popen("less #{params * ' '}", "w") do |less|
|
217
|
-
if output
|
218
|
-
less.puts output
|
219
|
-
else
|
220
|
-
yield less
|
221
|
-
end
|
222
|
-
end
|
101
|
+
def mri_21?
|
102
|
+
mri? && RUBY_VERSION =~ /^2\.1/
|
223
103
|
end
|
224
104
|
|
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
|
225
111
|
end
|
226
112
|
end
|
227
113
|
end
|
@@ -15,53 +15,29 @@ class Pry
|
|
15
15
|
file.close(true) if file
|
16
16
|
end
|
17
17
|
|
18
|
-
def render_output(str, opts={})
|
19
|
-
if opts[:flood]
|
20
|
-
output.puts str
|
21
|
-
else
|
22
|
-
stagger_output str
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
# Return the file and line for a Binding.
|
27
|
-
# @param [Binding] target The binding
|
28
|
-
# @return [Array] The file and line
|
29
|
-
def file_and_line_from_binding(target)
|
30
|
-
file = target.eval('__FILE__')
|
31
|
-
line_num = target.eval('__LINE__')
|
32
|
-
if rbx?
|
33
|
-
if !target.instance_variable_defined?(:@__actual_file__)
|
34
|
-
target.instance_variable_set(:@__actual_file__, RbxPath.convert_path_to_full(target.variables.method.file.to_s))
|
35
|
-
end
|
36
|
-
file = target.instance_variable_get(:@__actual_file__).to_s
|
37
|
-
end
|
38
|
-
|
39
|
-
[file, line_num]
|
40
|
-
end
|
41
|
-
|
42
18
|
def internal_binding?(target)
|
43
|
-
m = target.eval("__method__").to_s
|
19
|
+
m = target.eval("::Kernel.__method__").to_s
|
44
20
|
# class_eval is here because of http://jira.codehaus.org/browse/JRUBY-6753
|
45
|
-
["__binding__", "
|
21
|
+
["__binding__", "__pry__", "class_eval"].include?(m)
|
46
22
|
end
|
47
23
|
|
48
24
|
def get_method_or_raise(name, target, opts={}, omit_help=false)
|
49
25
|
meth = Pry::Method.from_str(name, target, opts)
|
50
26
|
|
51
27
|
if name && !meth
|
52
|
-
command_error("The method '#{name}' could not be found.", omit_help)
|
28
|
+
command_error("The method '#{name}' could not be found.", omit_help, MethodNotFound)
|
53
29
|
end
|
54
30
|
|
55
31
|
(opts[:super] || 0).times do
|
56
32
|
if meth.super
|
57
33
|
meth = meth.super
|
58
34
|
else
|
59
|
-
command_error("'#{meth.name_with_owner}' has no super method.", omit_help)
|
35
|
+
command_error("'#{meth.name_with_owner}' has no super method.", omit_help, MethodNotFound)
|
60
36
|
end
|
61
37
|
end
|
62
38
|
|
63
39
|
if !meth || (!name && internal_binding?(target))
|
64
|
-
command_error("No method name given, and context is not a method.", omit_help,
|
40
|
+
command_error("No method name given, and context is not a method.", omit_help, MethodNotFound)
|
65
41
|
end
|
66
42
|
|
67
43
|
set_file_and_dir_locals(meth.source_file)
|
@@ -73,104 +49,6 @@ class Pry
|
|
73
49
|
raise klass, message
|
74
50
|
end
|
75
51
|
|
76
|
-
def make_header(meth, content=meth.source)
|
77
|
-
header = "\n#{Pry::Helpers::Text.bold('From:')} #{meth.source_file} "
|
78
|
-
|
79
|
-
if meth.source_type == :c
|
80
|
-
header << "(C Method):\n"
|
81
|
-
else
|
82
|
-
header << "@ line #{meth.source_line}:\n"
|
83
|
-
end
|
84
|
-
|
85
|
-
header << "#{Pry::Helpers::Text.bold("Number of lines:")} #{content.each_line.count.to_s}\n"
|
86
|
-
end
|
87
|
-
|
88
|
-
def invoke_editor(file, line, reloading)
|
89
|
-
raise CommandError, "Please set Pry.config.editor or export $VISUAL or $EDITOR" unless Pry.config.editor
|
90
|
-
if Pry.config.editor.respond_to?(:call)
|
91
|
-
args = [file, line, reloading][0...(Pry.config.editor.arity)]
|
92
|
-
editor_invocation = Pry.config.editor.call(*args)
|
93
|
-
else
|
94
|
-
editor_invocation = "#{Pry.config.editor} #{blocking_flag_for_editor(reloading)} #{start_line_syntax_for_editor(file, line)}"
|
95
|
-
end
|
96
|
-
return nil unless editor_invocation
|
97
|
-
|
98
|
-
if jruby?
|
99
|
-
begin
|
100
|
-
require 'spoon'
|
101
|
-
pid = Spoon.spawnp(*editor_invocation.split)
|
102
|
-
Process.waitpid(pid)
|
103
|
-
rescue FFI::NotFoundError
|
104
|
-
system(editor_invocation)
|
105
|
-
end
|
106
|
-
else
|
107
|
-
# Note we dont want to use Pry.config.system here as that
|
108
|
-
# may be invoked non-interactively (i.e via Open4), whereas we want to
|
109
|
-
# ensure the editor is always interactive
|
110
|
-
system(editor_invocation) or raise CommandError, "`#{editor_invocation}` gave exit status: #{$?.exitstatus}"
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
# Some editors that run outside the terminal allow you to control whether or
|
115
|
-
# not to block the process from which they were launched (in this case, Pry).
|
116
|
-
# For those editors, return the flag that produces the desired behavior.
|
117
|
-
def blocking_flag_for_editor(block)
|
118
|
-
case editor_name
|
119
|
-
when /^emacsclient/
|
120
|
-
'--no-wait' unless block
|
121
|
-
when /^[gm]vim/
|
122
|
-
'--nofork' if block
|
123
|
-
when /^jedit/
|
124
|
-
'-wait' if block
|
125
|
-
when /^mate/, /^subl/
|
126
|
-
'-w' if block
|
127
|
-
end
|
128
|
-
end
|
129
|
-
|
130
|
-
# Return the syntax for a given editor for starting the editor
|
131
|
-
# and moving to a particular line within that file
|
132
|
-
def start_line_syntax_for_editor(file_name, line_number)
|
133
|
-
if windows?
|
134
|
-
file_name = file_name.gsub(/\//, '\\')
|
135
|
-
end
|
136
|
-
|
137
|
-
# special case for 1st line
|
138
|
-
return file_name if line_number <= 1
|
139
|
-
|
140
|
-
case editor_name
|
141
|
-
when /^[gm]?vi/, /^emacs/, /^nano/, /^pico/, /^gedit/, /^kate/
|
142
|
-
"+#{line_number} #{file_name}"
|
143
|
-
when /^mate/, /^geany/
|
144
|
-
"-l #{line_number} #{file_name}"
|
145
|
-
when /^subl/
|
146
|
-
"#{file_name}:#{line_number}"
|
147
|
-
when /^uedit32/
|
148
|
-
"#{file_name}/#{line_number}"
|
149
|
-
when /^jedit/
|
150
|
-
"#{file_name} +line:#{line_number}"
|
151
|
-
else
|
152
|
-
if windows?
|
153
|
-
"#{file_name}"
|
154
|
-
else
|
155
|
-
"+#{line_number} #{file_name}"
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
# Get the name of the binary that Pry.config.editor points to.
|
161
|
-
#
|
162
|
-
# This is useful for deciding which flags we pass to the editor as
|
163
|
-
# we can just use the program's name and ignore any absolute paths.
|
164
|
-
#
|
165
|
-
# @example
|
166
|
-
# Pry.config.editor="/home/conrad/bin/textmate -w"
|
167
|
-
# editor_name
|
168
|
-
# # => textmate
|
169
|
-
#
|
170
|
-
def editor_name
|
171
|
-
File.basename(Pry.config.editor).split(" ").first
|
172
|
-
end
|
173
|
-
|
174
52
|
# Remove any common leading whitespace from every line in `text`.
|
175
53
|
#
|
176
54
|
# This can be used to make a HEREDOC line up with the left margin, without
|
@@ -193,12 +71,14 @@ class Pry
|
|
193
71
|
#
|
194
72
|
# @param [String] text The text from which to remove indentation
|
195
73
|
# @return [String] The text with indentation stripped.
|
196
|
-
def unindent(text)
|
74
|
+
def unindent(text, left_padding = 0)
|
197
75
|
# Empty blank lines
|
198
76
|
text = text.sub(/^[ \t]+$/, '')
|
199
77
|
|
200
78
|
# Find the longest common whitespace to all indented lines
|
201
|
-
|
79
|
+
# Ignore lines containing just -- or ++ as these seem to be used by
|
80
|
+
# comment authors as delimeters.
|
81
|
+
margin = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/).inject do |current_margin, next_indent|
|
202
82
|
if next_indent.start_with?(current_margin)
|
203
83
|
current_margin
|
204
84
|
elsif current_margin.start_with?(next_indent)
|
@@ -208,7 +88,7 @@ class Pry
|
|
208
88
|
end
|
209
89
|
end
|
210
90
|
|
211
|
-
text.gsub(/^#{margin}/, '')
|
91
|
+
text.gsub(/^#{margin}/, ' ' * left_padding)
|
212
92
|
end
|
213
93
|
|
214
94
|
# Restrict a string to the given range of lines (1-indexed)
|
@@ -261,6 +141,15 @@ class Pry
|
|
261
141
|
|
262
142
|
Range.new(a, b)
|
263
143
|
end
|
144
|
+
|
145
|
+
def set_file_and_dir_locals(file_name, _pry_=_pry_(), target=target())
|
146
|
+
return if !target or !file_name
|
147
|
+
_pry_.last_file = File.expand_path(file_name)
|
148
|
+
_pry_.inject_local("_file_", _pry_.last_file, target)
|
149
|
+
|
150
|
+
_pry_.last_dir = File.dirname(_pry_.last_file)
|
151
|
+
_pry_.inject_local("_dir_", _pry_.last_dir, target)
|
152
|
+
end
|
264
153
|
end
|
265
154
|
|
266
155
|
end
|