pry 0.10.4 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +251 -16
- data/LICENSE +1 -1
- data/README.md +35 -51
- data/bin/pry +3 -11
- data/lib/pry/basic_object.rb +6 -0
- data/lib/pry/cli.rb +50 -52
- data/lib/pry/code/code_file.rb +13 -6
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code.rb +11 -6
- data/lib/pry/code_object.rb +27 -4
- data/lib/pry/color_printer.rb +20 -10
- data/lib/pry/command.rb +76 -45
- data/lib/pry/command_set.rb +17 -45
- data/lib/pry/commands/amend_line.rb +3 -4
- data/lib/pry/commands/bang.rb +1 -1
- data/lib/pry/commands/cat/exception_formatter.rb +10 -8
- data/lib/pry/commands/cat/file_formatter.rb +7 -3
- data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
- data/lib/pry/commands/cat.rb +7 -6
- data/lib/pry/commands/change_prompt.rb +29 -9
- data/lib/pry/commands/clear_screen.rb +14 -0
- data/lib/pry/commands/code_collector.rb +25 -23
- data/lib/pry/commands/easter_eggs.rb +12 -12
- data/lib/pry/commands/edit/file_and_line_locator.rb +1 -1
- data/lib/pry/commands/edit.rb +15 -10
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +12 -14
- data/lib/pry/commands/gem_cd.rb +1 -1
- data/lib/pry/commands/gem_install.rb +2 -2
- data/lib/pry/commands/gem_list.rb +2 -2
- data/lib/pry/commands/gem_open.rb +2 -2
- data/lib/pry/commands/gem_readme.rb +25 -0
- data/lib/pry/commands/gem_search.rb +40 -0
- data/lib/pry/commands/gem_stats.rb +83 -0
- data/lib/pry/commands/gist.rb +7 -6
- data/lib/pry/commands/help.rb +3 -3
- data/lib/pry/commands/hist.rb +11 -10
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/jump_to.rb +7 -7
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls/constants.rb +14 -3
- data/lib/pry/commands/ls/formatter.rb +4 -2
- data/lib/pry/commands/ls/globals.rb +0 -2
- data/lib/pry/commands/ls/grep.rb +0 -2
- data/lib/pry/commands/ls/instance_vars.rb +0 -1
- data/lib/pry/commands/ls/jruby_hacks.rb +2 -2
- data/lib/pry/commands/ls/local_names.rb +0 -2
- data/lib/pry/commands/ls/local_vars.rb +0 -2
- data/lib/pry/commands/ls/ls_entity.rb +0 -1
- data/lib/pry/commands/ls/methods.rb +0 -3
- data/lib/pry/commands/ls/methods_helper.rb +1 -1
- data/lib/pry/commands/ls/self_methods.rb +2 -1
- data/lib/pry/commands/ls.rb +30 -31
- data/lib/pry/commands/play.rb +3 -4
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/reload_code.rb +2 -2
- data/lib/pry/commands/ri.rb +9 -4
- data/lib/pry/commands/shell_command.rb +36 -9
- data/lib/pry/commands/shell_mode.rb +6 -6
- data/lib/pry/commands/show_doc.rb +5 -7
- data/lib/pry/commands/show_info.rb +35 -20
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression/expression.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +11 -10
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config/behavior.rb +230 -114
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +151 -153
- data/lib/pry/config/memoization.rb +48 -0
- data/lib/pry/config.rb +30 -19
- data/lib/pry/core_extensions.rb +15 -4
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +1 -3
- data/lib/pry/forwardable.rb +23 -0
- data/lib/pry/helpers/base_helpers.rb +197 -110
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +3 -2
- data/lib/pry/helpers/options_helpers.rb +6 -6
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +82 -74
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/history.rb +43 -9
- data/lib/pry/hooks.rb +50 -109
- data/lib/pry/indent.rb +21 -19
- data/lib/pry/input_completer.rb +146 -123
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +2 -2
- data/lib/pry/method/disowned.rb +3 -1
- data/lib/pry/method/patcher.rb +2 -5
- data/lib/pry/method/weird_method_locator.rb +21 -11
- data/lib/pry/method.rb +44 -38
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +37 -37
- data/lib/pry/pager.rb +195 -184
- data/lib/pry/platform.rb +91 -0
- data/lib/pry/plugins.rb +27 -8
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +83 -33
- data/lib/pry/pry_instance.rb +94 -59
- data/lib/pry/repl.rb +70 -11
- data/lib/pry/repl_file_loader.rb +2 -3
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +9 -7
- data/lib/pry/slop/LICENSE +20 -0
- data/lib/pry/slop/commands.rb +195 -0
- data/lib/pry/slop/option.rb +206 -0
- data/lib/pry/slop.rb +661 -0
- data/lib/pry/terminal.rb +18 -6
- data/lib/pry/testable/evalable.rb +15 -0
- data/lib/pry/testable/mockable.rb +14 -0
- data/lib/pry/testable/pry_tester.rb +73 -0
- data/lib/pry/testable/utility.rb +26 -0
- data/lib/pry/testable/variables.rb +46 -0
- data/lib/pry/testable.rb +70 -0
- data/lib/pry/version.rb +1 -1
- data/lib/pry/{module_candidate.rb → wrapped_module/candidate.rb} +8 -14
- data/lib/pry/wrapped_module.rb +21 -21
- data/lib/pry.rb +21 -50
- metadata +29 -40
- data/lib/pry/commands/list_prompts.rb +0 -35
- data/lib/pry/commands/simple_prompt.rb +0 -22
- data/lib/pry/history_array.rb +0 -121
- data/lib/pry/rbx_path.rb +0 -22
- data/lib/pry/test/helper.rb +0 -170
data/lib/pry/pager.rb
CHANGED
@@ -3,237 +3,248 @@ require 'pry/terminal'
|
|
3
3
|
# A pager is an `IO`-like object that accepts text and either prints it
|
4
4
|
# immediately, prints it one page at a time, or streams it to an external
|
5
5
|
# program to print one page at a time.
|
6
|
-
class Pry
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
attr_reader :_pry_
|
11
|
-
|
12
|
-
def initialize(_pry_)
|
13
|
-
@_pry_ = _pry_
|
14
|
-
end
|
15
|
-
|
16
|
-
# Send the given text through the best available pager (if `Pry.config.pager` is
|
17
|
-
# enabled).
|
18
|
-
# If you want to send text through in chunks as you generate it, use `open` to
|
19
|
-
# get a writable object instead.
|
20
|
-
# @param [String] text A piece of text to run through a pager.
|
21
|
-
# @param [IO] output (`$stdout`) An object to send output to.
|
22
|
-
def page(text)
|
23
|
-
open do |pager|
|
24
|
-
pager << text
|
6
|
+
class Pry
|
7
|
+
class Pager
|
8
|
+
class StopPaging < StandardError
|
25
9
|
end
|
26
|
-
end
|
27
10
|
|
28
|
-
|
29
|
-
# pagers accept output with `#puts`, `#print`, `#write`, and `#<<`.
|
30
|
-
# @param [IO] output (`$stdout`) An object to send output to.
|
31
|
-
def open
|
32
|
-
pager = best_available
|
33
|
-
yield pager
|
34
|
-
rescue StopPaging
|
35
|
-
ensure
|
36
|
-
pager.close if pager
|
37
|
-
end
|
11
|
+
attr_reader :_pry_
|
38
12
|
|
39
|
-
|
40
|
-
|
41
|
-
def enabled?; !!@enabled; end
|
42
|
-
|
43
|
-
def output; @output; end
|
44
|
-
|
45
|
-
# Return an instance of the "best" available pager class -- `SystemPager` if
|
46
|
-
# possible, `SimplePager` if `SystemPager` isn't available, and `NullPager`
|
47
|
-
# if the user has disabled paging. All pagers accept output with `#puts`,
|
48
|
-
# `#print`, `#write`, and `#<<`. You must call `#close` when you're done
|
49
|
-
# writing output to a pager, and you must rescue `Pry::Pager::StopPaging`.
|
50
|
-
# These requirements can be avoided by using `.open` instead.
|
51
|
-
# @param [#<<] output ($stdout) An object to send output to.
|
52
|
-
def best_available
|
53
|
-
if !_pry_.config.pager
|
54
|
-
NullPager.new(_pry_.output)
|
55
|
-
elsif !SystemPager.available? || Pry::Helpers::BaseHelpers.jruby?
|
56
|
-
SimplePager.new(_pry_.output)
|
57
|
-
else
|
58
|
-
SystemPager.new(_pry_.output)
|
13
|
+
def initialize(_pry_)
|
14
|
+
@_pry_ = _pry_
|
59
15
|
end
|
60
|
-
end
|
61
16
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
17
|
+
# Send the given text through the best available pager (if
|
18
|
+
# `Pry.config.pager` is enabled). If you want to send text through in
|
19
|
+
# chunks as you generate it, use `open` to get a writable object
|
20
|
+
# instead.
|
21
|
+
#
|
22
|
+
# @param [String] text
|
23
|
+
# Text to run through a pager.
|
24
|
+
#
|
25
|
+
def page(text)
|
26
|
+
open do |pager|
|
27
|
+
pager << text
|
28
|
+
end
|
71
29
|
end
|
72
30
|
|
73
|
-
|
74
|
-
|
31
|
+
# Yields a pager object (`NullPager`, `SimplePager`, or `SystemPager`).
|
32
|
+
# All pagers accept output with `#puts`, `#print`, `#write`, and `#<<`.
|
33
|
+
def open
|
34
|
+
pager = best_available
|
35
|
+
yield pager
|
36
|
+
rescue StopPaging
|
37
|
+
ensure
|
38
|
+
pager.close if pager
|
75
39
|
end
|
76
|
-
alias << print
|
77
40
|
|
78
|
-
|
79
|
-
@out.write str
|
80
|
-
end
|
41
|
+
private
|
81
42
|
|
82
|
-
def
|
43
|
+
def enabled?; !!@enabled; end
|
44
|
+
|
45
|
+
def output; @output; end
|
46
|
+
|
47
|
+
# Return an instance of the "best" available pager class --
|
48
|
+
# `SystemPager` if possible, `SimplePager` if `SystemPager` isn't
|
49
|
+
# available, and `NullPager` if the user has disabled paging. All
|
50
|
+
# pagers accept output with `#puts`, `#print`, `#write`, and `#<<`. You
|
51
|
+
# must call `#close` when you're done writing output to a pager, and
|
52
|
+
# you must rescue `Pry::Pager::StopPaging`. These requirements can be
|
53
|
+
# avoided by using `.open` instead.
|
54
|
+
def best_available
|
55
|
+
if !_pry_.config.pager
|
56
|
+
NullPager.new(_pry_.output)
|
57
|
+
elsif !SystemPager.available? || Helpers::Platform.jruby?
|
58
|
+
SimplePager.new(_pry_.output)
|
59
|
+
else
|
60
|
+
SystemPager.new(_pry_.output)
|
61
|
+
end
|
83
62
|
end
|
84
63
|
|
85
|
-
|
64
|
+
# `NullPager` is a "pager" that actually just prints all output as it
|
65
|
+
# comes in. Used when `Pry.config.pager` is false.
|
66
|
+
class NullPager
|
67
|
+
def initialize(out)
|
68
|
+
@out = out
|
69
|
+
end
|
86
70
|
|
87
|
-
|
88
|
-
|
89
|
-
|
71
|
+
def puts(str)
|
72
|
+
print "#{str.chomp}\n"
|
73
|
+
end
|
90
74
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
75
|
+
def print(str)
|
76
|
+
write str
|
77
|
+
end
|
78
|
+
alias << print
|
95
79
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
def initialize(*)
|
100
|
-
super
|
101
|
-
@tracker = PageTracker.new(height - 3, width)
|
102
|
-
end
|
80
|
+
def write(str)
|
81
|
+
@out.write str
|
82
|
+
end
|
103
83
|
|
104
|
-
|
105
|
-
str.lines.each do |line|
|
106
|
-
@out.print line
|
107
|
-
@tracker.record line
|
108
|
-
|
109
|
-
if @tracker.page?
|
110
|
-
@out.print "\n"
|
111
|
-
@out.print "\e[0m"
|
112
|
-
@out.print "<page break> --- Press enter to continue " \
|
113
|
-
"( q<enter> to break ) --- <page break>\n"
|
114
|
-
raise StopPaging if Readline.readline("").chomp == "q"
|
115
|
-
@tracker.reset
|
116
|
-
end
|
84
|
+
def close
|
117
85
|
end
|
118
|
-
end
|
119
|
-
end
|
120
86
|
|
121
|
-
|
122
|
-
# long, then invokes an external pager and starts streaming output to it. If
|
123
|
-
# `#close` is called before then, it just prints out the buffered content.
|
124
|
-
class SystemPager < NullPager
|
125
|
-
def self.default_pager
|
126
|
-
pager = ENV["PAGER"] || ""
|
87
|
+
private
|
127
88
|
|
128
|
-
|
129
|
-
|
130
|
-
pager = "less -R -F -X"
|
89
|
+
def height
|
90
|
+
@height ||= Pry::Terminal.height!
|
131
91
|
end
|
132
92
|
|
133
|
-
|
93
|
+
def width
|
94
|
+
@width ||= Pry::Terminal.width!
|
95
|
+
end
|
134
96
|
end
|
135
97
|
|
136
|
-
|
98
|
+
# `SimplePager` is a straightforward pure-Ruby pager. We use it on
|
99
|
+
# JRuby and when we can't find a usable external pager.
|
100
|
+
class SimplePager < NullPager
|
101
|
+
def initialize(*)
|
102
|
+
super
|
103
|
+
@tracker = PageTracker.new(height - 3, width)
|
104
|
+
end
|
105
|
+
|
106
|
+
def write(str)
|
107
|
+
str.lines.each do |line|
|
108
|
+
@out.print line
|
109
|
+
@tracker.record line
|
137
110
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
111
|
+
if @tracker.page?
|
112
|
+
@out.print "\n"
|
113
|
+
@out.print "\e[0m"
|
114
|
+
@out.print "<page break> --- Press enter to continue " \
|
115
|
+
"( q<enter> to break ) --- <page break>\n"
|
116
|
+
raise StopPaging if Readline.readline("").chomp == "q"
|
117
|
+
|
118
|
+
@tracker.reset
|
119
|
+
end
|
146
120
|
end
|
147
|
-
else
|
148
|
-
@system_pager
|
149
121
|
end
|
150
122
|
end
|
151
123
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
124
|
+
# `SystemPager` buffers output until we're pretty sure it's at least a
|
125
|
+
# page long, then invokes an external pager and starts streaming output
|
126
|
+
# to it. If `#close` is called before then, it just prints out the
|
127
|
+
# buffered content.
|
128
|
+
class SystemPager < NullPager
|
129
|
+
def self.default_pager
|
130
|
+
pager = ENV["PAGER"] || ""
|
158
131
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
132
|
+
# Default to less, and make sure less is being passed the correct
|
133
|
+
# options
|
134
|
+
if pager.strip.empty? or pager =~ /^less\b/
|
135
|
+
pager = "less -R -F -X"
|
136
|
+
end
|
137
|
+
|
138
|
+
pager
|
139
|
+
end
|
165
140
|
|
166
|
-
|
167
|
-
|
141
|
+
@system_pager = nil
|
142
|
+
|
143
|
+
def self.available?
|
144
|
+
if @system_pager.nil?
|
145
|
+
@system_pager = begin
|
146
|
+
pager_executable = default_pager.split(' ').first
|
147
|
+
if Helpers::Platform.windows? || Helpers::Platform.windows_ansi?
|
148
|
+
`where /Q #{pager_executable}`
|
149
|
+
else
|
150
|
+
`which #{pager_executable}`
|
151
|
+
end
|
152
|
+
$?.success?
|
153
|
+
rescue
|
154
|
+
false
|
155
|
+
end
|
156
|
+
else
|
157
|
+
@system_pager
|
168
158
|
end
|
169
159
|
end
|
170
|
-
rescue Errno::EPIPE
|
171
|
-
raise StopPaging
|
172
|
-
end
|
173
160
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
@
|
161
|
+
def initialize(*)
|
162
|
+
super
|
163
|
+
@tracker = PageTracker.new(height, width)
|
164
|
+
@buffer = ""
|
165
|
+
@pager = nil
|
179
166
|
end
|
180
|
-
end
|
181
167
|
|
182
|
-
|
168
|
+
def write(str)
|
169
|
+
if invoked_pager?
|
170
|
+
write_to_pager str
|
171
|
+
else
|
172
|
+
@tracker.record str
|
173
|
+
@buffer << str
|
183
174
|
|
184
|
-
|
185
|
-
|
186
|
-
|
175
|
+
if @tracker.page?
|
176
|
+
write_to_pager @buffer
|
177
|
+
end
|
178
|
+
end
|
179
|
+
rescue Errno::EPIPE
|
180
|
+
raise StopPaging
|
181
|
+
end
|
187
182
|
|
188
|
-
|
189
|
-
|
190
|
-
|
183
|
+
def close
|
184
|
+
if invoked_pager?
|
185
|
+
pager.close
|
186
|
+
else
|
187
|
+
@out.puts @buffer
|
188
|
+
end
|
189
|
+
end
|
191
190
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
191
|
+
private
|
192
|
+
|
193
|
+
def write_to_pager(text)
|
194
|
+
pager.write @out.decolorize_maybe(text)
|
195
|
+
end
|
196
|
+
|
197
|
+
def invoked_pager?
|
198
|
+
@pager
|
199
|
+
end
|
196
200
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
#
|
201
|
-
# One simplifying assumption is that we don't need `#page?` to return `true`
|
202
|
-
# on the basis of an incomplete line. Long lines should be counted as
|
203
|
-
# multiple lines, but we don't have to transition from `false` to `true`
|
204
|
-
# until we see a newline.
|
205
|
-
class PageTracker
|
206
|
-
def initialize(rows, cols)
|
207
|
-
@rows, @cols = rows, cols
|
208
|
-
reset
|
201
|
+
def pager
|
202
|
+
@pager ||= IO.popen(self.class.default_pager, 'w')
|
203
|
+
end
|
209
204
|
end
|
210
205
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
206
|
+
# `PageTracker` tracks output to determine whether it's likely to take
|
207
|
+
# up a whole page. This doesn't need to be super precise, but we can
|
208
|
+
# use it for `SimplePager` and to avoid invoking the system pager
|
209
|
+
# unnecessarily.
|
210
|
+
#
|
211
|
+
# One simplifying assumption is that we don't need `#page?` to return
|
212
|
+
# `true` on the basis of an incomplete line. Long lines should be
|
213
|
+
# counted as multiple lines, but we don't have to transition from
|
214
|
+
# `false` to `true` until we see a newline.
|
215
|
+
class PageTracker
|
216
|
+
def initialize(rows, cols)
|
217
|
+
@rows, @cols = rows, cols
|
218
|
+
reset
|
219
|
+
end
|
220
|
+
|
221
|
+
def record(str)
|
222
|
+
str.lines.each do |line|
|
223
|
+
if line.end_with? "\n"
|
224
|
+
@row += ((@col + line_length(line) - 1) / @cols) + 1
|
225
|
+
@col = 0
|
226
|
+
else
|
227
|
+
@col += line_length(line)
|
228
|
+
end
|
218
229
|
end
|
219
230
|
end
|
220
|
-
end
|
221
231
|
|
222
|
-
|
223
|
-
|
224
|
-
|
232
|
+
def page?
|
233
|
+
@row >= @rows
|
234
|
+
end
|
225
235
|
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
236
|
+
def reset
|
237
|
+
@row = 0
|
238
|
+
@col = 0
|
239
|
+
end
|
230
240
|
|
231
|
-
|
241
|
+
private
|
232
242
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
243
|
+
# Approximation of the printable length of a given line, without the
|
244
|
+
# newline and without ANSI color codes.
|
245
|
+
def line_length(line)
|
246
|
+
line.chomp.gsub(/\e\[[\d;]*m/, '').length
|
247
|
+
end
|
237
248
|
end
|
238
249
|
end
|
239
250
|
end
|
data/lib/pry/platform.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
class Pry
|
2
|
+
module Platform
|
3
|
+
extend self
|
4
|
+
|
5
|
+
#
|
6
|
+
# @return [Boolean]
|
7
|
+
# Returns true if Pry is running on Mac OSX.
|
8
|
+
#
|
9
|
+
# @note
|
10
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
11
|
+
#
|
12
|
+
def mac_osx?
|
13
|
+
!!(RbConfig::CONFIG['host_os'] =~ /\Adarwin/i)
|
14
|
+
end
|
15
|
+
|
16
|
+
#
|
17
|
+
# @return [Boolean]
|
18
|
+
# Returns true if Pry is running on Linux.
|
19
|
+
#
|
20
|
+
# @note
|
21
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
22
|
+
#
|
23
|
+
def linux?
|
24
|
+
!!(RbConfig::CONFIG['host_os'] =~ /linux/i)
|
25
|
+
end
|
26
|
+
|
27
|
+
#
|
28
|
+
# @return [Boolean]
|
29
|
+
# Returns true if Pry is running on Windows.
|
30
|
+
#
|
31
|
+
# @note
|
32
|
+
# Queries RbConfig::CONFIG['host_os'] with a best guess.
|
33
|
+
#
|
34
|
+
def windows?
|
35
|
+
!!(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/)
|
36
|
+
end
|
37
|
+
|
38
|
+
#
|
39
|
+
# @return [Boolean]
|
40
|
+
# Returns true when Pry is running on Windows with ANSI support.
|
41
|
+
#
|
42
|
+
def windows_ansi?
|
43
|
+
return false if not windows?
|
44
|
+
|
45
|
+
!!(defined?(Win32::Console) or ENV['ANSICON'] or mri_2?)
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# @return [Boolean]
|
50
|
+
# Returns true when Pry is being run from JRuby.
|
51
|
+
#
|
52
|
+
def jruby?
|
53
|
+
RbConfig::CONFIG['ruby_install_name'] == 'jruby'
|
54
|
+
end
|
55
|
+
|
56
|
+
#
|
57
|
+
# @return [Boolean]
|
58
|
+
# Returns true when Pry is being run from JRuby in 1.9 mode.
|
59
|
+
#
|
60
|
+
def jruby_19?
|
61
|
+
jruby? and RbConfig::CONFIG['ruby_version'] == '1.9'
|
62
|
+
end
|
63
|
+
|
64
|
+
#
|
65
|
+
# @return [Boolean]
|
66
|
+
# Returns true when Pry is being run from MRI (CRuby).
|
67
|
+
#
|
68
|
+
def mri?
|
69
|
+
RbConfig::CONFIG['ruby_install_name'] == 'ruby'
|
70
|
+
end
|
71
|
+
|
72
|
+
#
|
73
|
+
# @return [Boolean]
|
74
|
+
# Returns true when Pry is being run from MRI v1.9+ (CRuby).
|
75
|
+
#
|
76
|
+
def mri_19?
|
77
|
+
!!(mri? and RUBY_VERSION =~ /\A1\.9/)
|
78
|
+
end
|
79
|
+
|
80
|
+
#
|
81
|
+
# @return [Boolean]
|
82
|
+
# Returns true when Pry is being run from MRI v2+ (CRuby).
|
83
|
+
#
|
84
|
+
def mri_2?
|
85
|
+
!!(mri? and RUBY_VERSION =~ /\A2/)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
# Not supported on MRI 2.2 and lower.
|
90
|
+
deprecate_constant(:Platform) if respond_to?(:deprecate_constant)
|
91
|
+
end
|
data/lib/pry/plugins.rb
CHANGED
@@ -8,7 +8,7 @@ class Pry
|
|
8
8
|
@name = name
|
9
9
|
end
|
10
10
|
|
11
|
-
def method_missing(*
|
11
|
+
def method_missing(*_args)
|
12
12
|
warn "Warning: The plugin '#{@name}' was not found! (no gem found)"
|
13
13
|
end
|
14
14
|
end
|
@@ -35,8 +35,12 @@ class Pry
|
|
35
35
|
# Load the Command line options defined by this plugin (if they exist)
|
36
36
|
def load_cli_options
|
37
37
|
cli_options_file = File.join(spec.full_gem_path, "lib/#{spec.name}/cli.rb")
|
38
|
-
|
38
|
+
return unless File.exist?(cli_options_file)
|
39
|
+
|
40
|
+
cli_options_file = File.realpath(cli_options_file) if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.4.4")
|
41
|
+
require cli_options_file
|
39
42
|
end
|
43
|
+
|
40
44
|
# Activate the plugin (require the gem - enables/loads the
|
41
45
|
# plugin immediately at point of call, even if plugin is
|
42
46
|
# disabled)
|
@@ -60,6 +64,16 @@ class Pry
|
|
60
64
|
|
61
65
|
alias active? active
|
62
66
|
alias enabled? enabled
|
67
|
+
|
68
|
+
def supported?
|
69
|
+
pry_version = Gem::Version.new(VERSION)
|
70
|
+
spec.dependencies.each do |dependency|
|
71
|
+
if dependency.name == "pry"
|
72
|
+
return dependency.requirement.satisfied_by?(pry_version)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
true
|
76
|
+
end
|
63
77
|
end
|
64
78
|
|
65
79
|
def initialize
|
@@ -68,11 +82,12 @@ class Pry
|
|
68
82
|
|
69
83
|
# Find all installed Pry plugins and store them in an internal array.
|
70
84
|
def locate_plugins
|
71
|
-
|
72
|
-
(Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')).each do |gem|
|
85
|
+
gem_list.each do |gem|
|
73
86
|
next if gem.name !~ PRY_PLUGIN_PREFIX
|
87
|
+
|
74
88
|
plugin_name = gem.name.split('-', 2).last
|
75
|
-
|
89
|
+
plugin = Plugin.new(plugin_name, gem.name, gem, false)
|
90
|
+
@plugins << plugin.tap(&:enable!) if plugin.supported? && !plugin_located?(plugin)
|
76
91
|
end
|
77
92
|
@plugins
|
78
93
|
end
|
@@ -95,9 +110,13 @@ class Pry
|
|
95
110
|
end
|
96
111
|
|
97
112
|
private
|
98
|
-
def
|
99
|
-
@plugins.any? { |
|
113
|
+
def plugin_located?(plugin)
|
114
|
+
@plugins.any? { |existing| existing.gem_name == plugin.gem_name }
|
100
115
|
end
|
101
|
-
end
|
102
116
|
|
117
|
+
def gem_list
|
118
|
+
Gem.refresh
|
119
|
+
Gem::Specification.respond_to?(:each) ? Gem::Specification : Gem.source_index.find_name('')
|
120
|
+
end
|
121
|
+
end
|
103
122
|
end
|