pry 0.11.1 → 0.12.0
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.
- checksums.yaml +5 -5
- data/CHANGELOG.md +184 -1
- data/LICENSE +1 -1
- data/README.md +13 -30
- data/bin/pry +0 -4
- data/lib/pry/cli.rb +17 -24
- data/lib/pry/code/code_file.rb +5 -4
- data/lib/pry/code/code_range.rb +3 -3
- data/lib/pry/code/loc.rb +14 -8
- data/lib/pry/code.rb +6 -6
- data/lib/pry/code_object.rb +4 -4
- data/lib/pry/color_printer.rb +2 -1
- data/lib/pry/command.rb +36 -29
- data/lib/pry/command_set.rb +17 -52
- 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 +9 -8
- 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 +9 -9
- data/lib/pry/commands/easter_eggs.rb +3 -3
- data/lib/pry/commands/edit.rb +8 -7
- data/lib/pry/commands/exit.rb +2 -1
- data/lib/pry/commands/find_method.rb +11 -13
- 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 +1 -1
- data/lib/pry/commands/gem_search.rb +2 -2
- 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 +9 -8
- data/lib/pry/commands/import_set.rb +2 -1
- data/lib/pry/commands/install_command.rb +7 -6
- data/lib/pry/commands/list_inspectors.rb +2 -2
- data/lib/pry/commands/ls/constants.rb +4 -4
- data/lib/pry/commands/ls/formatter.rb +3 -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/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 +0 -1
- data/lib/pry/commands/ls.rb +27 -30
- data/lib/pry/commands/play.rb +1 -2
- data/lib/pry/commands/pry_backtrace.rb +1 -1
- data/lib/pry/commands/raise_up.rb +2 -1
- data/lib/pry/commands/ri.rb +5 -4
- data/lib/pry/commands/shell_command.rb +3 -2
- 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 +25 -18
- data/lib/pry/commands/show_source.rb +5 -2
- data/lib/pry/commands/stat.rb +1 -1
- data/lib/pry/commands/watch_expression.rb +9 -7
- data/lib/pry/commands/whereami.rb +5 -5
- data/lib/pry/commands/wtf.rb +15 -2
- data/lib/pry/config/behavior.rb +229 -204
- data/lib/pry/config/convenience.rb +24 -21
- data/lib/pry/config/default.rb +153 -143
- data/lib/pry/config/memoization.rb +41 -37
- data/lib/pry/config.rb +33 -9
- data/lib/pry/core_extensions.rb +4 -3
- data/lib/pry/editor.rb +5 -12
- data/lib/pry/exceptions.rb +0 -2
- data/lib/pry/helpers/base_helpers.rb +197 -106
- data/lib/pry/helpers/command_helpers.rb +5 -4
- data/lib/pry/helpers/documentation_helpers.rb +2 -2
- data/lib/pry/helpers/options_helpers.rb +5 -5
- data/lib/pry/helpers/platform.rb +58 -0
- data/lib/pry/helpers/table.rb +20 -15
- data/lib/pry/helpers/text.rb +23 -9
- data/lib/pry/helpers.rb +1 -0
- data/lib/pry/history.rb +21 -8
- data/lib/pry/hooks.rb +3 -3
- data/lib/pry/indent.rb +15 -17
- data/lib/pry/input_completer.rb +12 -7
- data/lib/pry/input_lock.rb +0 -2
- data/lib/pry/last_exception.rb +1 -1
- data/lib/pry/method/disowned.rb +2 -1
- data/lib/pry/method/patcher.rb +2 -2
- data/lib/pry/method/weird_method_locator.rb +21 -11
- data/lib/pry/method.rb +37 -31
- data/lib/pry/object_path.rb +5 -4
- data/lib/pry/output.rb +3 -2
- data/lib/pry/pager.rb +4 -3
- data/lib/pry/platform.rb +91 -0
- data/lib/pry/plugins.rb +7 -3
- data/lib/pry/prompt.rb +144 -25
- data/lib/pry/pry_class.rb +53 -29
- data/lib/pry/pry_instance.rb +88 -55
- data/lib/pry/repl.rb +33 -4
- data/lib/pry/repl_file_loader.rb +1 -2
- data/lib/pry/ring.rb +84 -0
- data/lib/pry/rubygem.rb +6 -6
- data/lib/pry/slop/commands.rb +3 -4
- data/lib/pry/slop/option.rb +19 -21
- data/lib/pry/slop.rb +17 -17
- data/lib/pry/terminal.rb +2 -1
- 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/wrapped_module/candidate.rb +2 -2
- data/lib/pry/wrapped_module.rb +15 -15
- data/lib/pry.rb +18 -47
- metadata +24 -30
- 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 -179
data/lib/pry/pry_instance.rb
CHANGED
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
# * the IRC channel, which is #pry on the Freenode network
|
|
22
22
|
#
|
|
23
23
|
|
|
24
|
+
# rubocop:disable Metrics/ClassLength
|
|
24
25
|
class Pry
|
|
25
26
|
attr_accessor :binding_stack
|
|
26
27
|
attr_accessor :custom_completions
|
|
@@ -34,8 +35,13 @@ class Pry
|
|
|
34
35
|
attr_reader :last_exception
|
|
35
36
|
attr_reader :command_state
|
|
36
37
|
attr_reader :exit_value
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
|
|
39
|
+
# @since v0.12.0
|
|
40
|
+
attr_reader :input_ring
|
|
41
|
+
|
|
42
|
+
# @since v0.12.0
|
|
43
|
+
attr_reader :output_ring
|
|
44
|
+
|
|
39
45
|
attr_reader :config
|
|
40
46
|
|
|
41
47
|
extend Pry::Config::Convenience
|
|
@@ -62,7 +68,7 @@ class Pry
|
|
|
62
68
|
# The backtrace of the session's `binding.pry` line, if applicable.
|
|
63
69
|
# @option options [Object] :target
|
|
64
70
|
# The initial context for this session.
|
|
65
|
-
def initialize(options={})
|
|
71
|
+
def initialize(options = {})
|
|
66
72
|
@binding_stack = []
|
|
67
73
|
@indent = Pry::Indent.new
|
|
68
74
|
@command_state = {}
|
|
@@ -72,23 +78,47 @@ class Pry
|
|
|
72
78
|
@config = Pry::Config.new
|
|
73
79
|
config.merge!(options)
|
|
74
80
|
push_prompt(config.prompt)
|
|
75
|
-
@
|
|
76
|
-
@
|
|
81
|
+
@input_ring = Pry::Ring.new(config.memory_size)
|
|
82
|
+
@output_ring = Pry::Ring.new(config.memory_size)
|
|
77
83
|
@custom_completions = config.command_completions
|
|
78
84
|
set_last_result nil
|
|
79
|
-
@
|
|
85
|
+
@input_ring << nil
|
|
80
86
|
push_initial_binding(target)
|
|
81
87
|
exec_hook(:when_started, target, options, self)
|
|
82
88
|
end
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
@input_array_warn = false
|
|
91
|
+
# @deprecated Use {#input_ring} instead.
|
|
92
|
+
def input_array
|
|
93
|
+
unless @input_array_warn
|
|
94
|
+
loc = caller_locations(1..1).first
|
|
95
|
+
warn(
|
|
96
|
+
"#{loc.path}:#{loc.lineno}: warning: method #{self.class}##{__method__} " \
|
|
97
|
+
"is deprecated. Use #{self.class}#input_ring instead"
|
|
98
|
+
)
|
|
99
|
+
@input_array_warn = true
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
@input_ring
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
@output_array_warn = false
|
|
106
|
+
# @deprecated Use {#output_ring} instead.
|
|
107
|
+
def output_array
|
|
108
|
+
unless @output_array_warn
|
|
109
|
+
loc = caller_locations(1..1).first
|
|
110
|
+
warn(
|
|
111
|
+
"#{loc.path}:#{loc.lineno}: warning: method #{self.class}##{__method__} " \
|
|
112
|
+
"is deprecated. Use #{self.class}#output_ring instead"
|
|
113
|
+
)
|
|
114
|
+
@output_array_warn = true
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
@output_ring
|
|
118
|
+
end
|
|
119
|
+
|
|
85
120
|
# This is the prompt at the top of the prompt stack.
|
|
86
|
-
#
|
|
87
|
-
# @example
|
|
88
|
-
# self.prompt = Pry::SIMPLE_PROMPT
|
|
89
|
-
# self.prompt # => Pry::SIMPLE_PROMPT
|
|
90
|
-
#
|
|
91
|
-
# @return [Array<Proc>] Current prompt.
|
|
121
|
+
# @return [Array<Proc>] the current prompt
|
|
92
122
|
def prompt
|
|
93
123
|
prompt_stack.last
|
|
94
124
|
end
|
|
@@ -103,7 +133,7 @@ class Pry
|
|
|
103
133
|
|
|
104
134
|
# Initialize this instance by pushing its initial context into the binding
|
|
105
135
|
# stack. If no target is given, start at the top level.
|
|
106
|
-
def push_initial_binding(target=nil)
|
|
136
|
+
def push_initial_binding(target = nil)
|
|
107
137
|
push_binding(target || Pry.toplevel_binding)
|
|
108
138
|
end
|
|
109
139
|
|
|
@@ -132,6 +162,7 @@ class Pry
|
|
|
132
162
|
#
|
|
133
163
|
def complete(str)
|
|
134
164
|
return EMPTY_COMPLETIONS unless config.completer
|
|
165
|
+
|
|
135
166
|
Pry.critical_section do
|
|
136
167
|
completer = config.completer.new(config.input, self)
|
|
137
168
|
completer.call str, target: current_binding, custom_completions: custom_completions.call.push(*sticky_locals.keys)
|
|
@@ -171,13 +202,13 @@ class Pry
|
|
|
171
202
|
# @return [Integer] The maximum amount of objects remembered by the inp and
|
|
172
203
|
# out arrays. Defaults to 100.
|
|
173
204
|
def memory_size
|
|
174
|
-
@
|
|
205
|
+
@output_ring.max_size
|
|
175
206
|
end
|
|
176
207
|
|
|
177
208
|
undef :memory_size= if method_defined? :memory_size=
|
|
178
209
|
def memory_size=(size)
|
|
179
|
-
@
|
|
180
|
-
@
|
|
210
|
+
@input_ring = Pry::Ring.new(size)
|
|
211
|
+
@output_ring = Pry::Ring.new(size)
|
|
181
212
|
end
|
|
182
213
|
|
|
183
214
|
# Inject all the sticky locals into the current binding.
|
|
@@ -197,14 +228,14 @@ class Pry
|
|
|
197
228
|
end
|
|
198
229
|
|
|
199
230
|
def sticky_locals
|
|
200
|
-
{ _in_:
|
|
201
|
-
_out_:
|
|
231
|
+
{ _in_: input_ring,
|
|
232
|
+
_out_: output_ring,
|
|
202
233
|
_pry_: self,
|
|
203
234
|
_ex_: last_exception && last_exception.wrapped_exception,
|
|
204
235
|
_file_: last_file,
|
|
205
236
|
_dir_: last_dir,
|
|
206
237
|
_: proc { last_result },
|
|
207
|
-
__: proc {
|
|
238
|
+
__: proc { output_ring[-2] }
|
|
208
239
|
}.merge(config.extra_sticky_locals)
|
|
209
240
|
end
|
|
210
241
|
|
|
@@ -234,7 +265,7 @@ class Pry
|
|
|
234
265
|
# @return [Boolean] Is Pry ready to accept more input?
|
|
235
266
|
# @raise [Exception] If the user uses the `raise-up` command, this method
|
|
236
267
|
# will raise that exception.
|
|
237
|
-
def eval(line, options={})
|
|
268
|
+
def eval(line, options = {})
|
|
238
269
|
return false if @stopped
|
|
239
270
|
|
|
240
271
|
exit_value = nil
|
|
@@ -254,6 +285,7 @@ class Pry
|
|
|
254
285
|
|
|
255
286
|
# TODO: make this configurable?
|
|
256
287
|
raise exception if exception
|
|
288
|
+
|
|
257
289
|
return false
|
|
258
290
|
end
|
|
259
291
|
|
|
@@ -310,7 +342,7 @@ class Pry
|
|
|
310
342
|
# This workaround has a side effect: java exceptions specified
|
|
311
343
|
# in `Pry.config.exception_whitelist` are ignored.
|
|
312
344
|
jruby_exceptions = []
|
|
313
|
-
if
|
|
345
|
+
if Helpers::Platform.jruby?
|
|
314
346
|
jruby_exceptions << Java::JavaLang::Exception
|
|
315
347
|
end
|
|
316
348
|
|
|
@@ -325,7 +357,7 @@ class Pry
|
|
|
325
357
|
# Eliminate following warning:
|
|
326
358
|
# warning: singleton on non-persistent Java type X
|
|
327
359
|
# (http://wiki.jruby.org/Persistence)
|
|
328
|
-
if
|
|
360
|
+
if Helpers::Platform.jruby? && e.class.respond_to?('__persistent__')
|
|
329
361
|
e.class.__persistent__ = true
|
|
330
362
|
end
|
|
331
363
|
self.last_exception = e
|
|
@@ -345,7 +377,7 @@ class Pry
|
|
|
345
377
|
# (If nested sessions are going to exist, this method is fine, but a goal is
|
|
346
378
|
# to come up with an alternative to nested sessions altogether.)
|
|
347
379
|
def repl(target = nil)
|
|
348
|
-
Pry::REPL.new(self, :
|
|
380
|
+
Pry::REPL.new(self, target: target).start
|
|
349
381
|
end
|
|
350
382
|
|
|
351
383
|
def evaluate_ruby(code)
|
|
@@ -403,11 +435,11 @@ class Pry
|
|
|
403
435
|
val = val.lstrip if /^\s\S/ !~ val
|
|
404
436
|
val = val.chomp
|
|
405
437
|
result = commands.process_line(val,
|
|
406
|
-
:
|
|
407
|
-
:
|
|
408
|
-
:
|
|
409
|
-
:
|
|
410
|
-
:
|
|
438
|
+
target: current_binding,
|
|
439
|
+
output: output,
|
|
440
|
+
eval_string: @eval_string,
|
|
441
|
+
pry_instance: self,
|
|
442
|
+
hooks: hooks
|
|
411
443
|
)
|
|
412
444
|
|
|
413
445
|
# set a temporary (just so we can inject the value we want into eval_string)
|
|
@@ -448,10 +480,10 @@ class Pry
|
|
|
448
480
|
# pry_instance.run_command("ls -m")
|
|
449
481
|
def run_command(val)
|
|
450
482
|
commands.process_line(val,
|
|
451
|
-
:
|
|
452
|
-
:
|
|
453
|
-
:
|
|
454
|
-
:
|
|
483
|
+
eval_string: @eval_string,
|
|
484
|
+
target: current_binding,
|
|
485
|
+
pry_instance: self,
|
|
486
|
+
output: output
|
|
455
487
|
)
|
|
456
488
|
Pry::Command::VOID_VALUE
|
|
457
489
|
end
|
|
@@ -479,9 +511,9 @@ class Pry
|
|
|
479
511
|
# This method should not need to be invoked directly.
|
|
480
512
|
# @param [Object] result The result.
|
|
481
513
|
# @param [String] code The code that was run.
|
|
482
|
-
def set_last_result(result, code="")
|
|
514
|
+
def set_last_result(result, code = "")
|
|
483
515
|
@last_result_is_exception = false
|
|
484
|
-
@
|
|
516
|
+
@output_ring << result
|
|
485
517
|
|
|
486
518
|
self.last_result = result unless code =~ /\A\s*\z/
|
|
487
519
|
end
|
|
@@ -495,7 +527,7 @@ class Pry
|
|
|
495
527
|
def last_exception=(e)
|
|
496
528
|
last_exception = Pry::LastException.new(e)
|
|
497
529
|
@last_result_is_exception = true
|
|
498
|
-
@
|
|
530
|
+
@output_ring << last_exception
|
|
499
531
|
@last_exception = last_exception
|
|
500
532
|
end
|
|
501
533
|
|
|
@@ -503,8 +535,8 @@ class Pry
|
|
|
503
535
|
# This method should not need to be invoked directly.
|
|
504
536
|
# @param [String] code The code we just eval'd
|
|
505
537
|
def update_input_history(code)
|
|
506
|
-
# Always push to the @
|
|
507
|
-
@
|
|
538
|
+
# Always push to the @input_ring as the @output_ring is always pushed to.
|
|
539
|
+
@input_ring << code
|
|
508
540
|
if code
|
|
509
541
|
Pry.line_buffer.push(*code.each_line)
|
|
510
542
|
Pry.current_line += code.lines.count
|
|
@@ -529,28 +561,26 @@ class Pry
|
|
|
529
561
|
# @return [String] The prompt.
|
|
530
562
|
def select_prompt
|
|
531
563
|
object = current_binding.eval('self')
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
:cont => !@eval_string.empty?})
|
|
564
|
+
open_token = @indent.open_delimiters.last || @indent.stack.last
|
|
565
|
+
|
|
566
|
+
c = Pry::Config.assign({
|
|
567
|
+
object: object,
|
|
568
|
+
nesting_level: binding_stack.size - 1,
|
|
569
|
+
open_token: open_token,
|
|
570
|
+
session_line: Pry.history.session_line_count + 1,
|
|
571
|
+
history_line: Pry.history.history_line_count + 1,
|
|
572
|
+
expr_number: input_ring.count,
|
|
573
|
+
_pry_: self,
|
|
574
|
+
binding_stack: binding_stack,
|
|
575
|
+
input_ring: input_ring,
|
|
576
|
+
eval_string: @eval_string,
|
|
577
|
+
cont: !@eval_string.empty?
|
|
578
|
+
})
|
|
548
579
|
|
|
549
580
|
Pry.critical_section do
|
|
550
581
|
# If input buffer is empty then use normal prompt
|
|
551
582
|
if eval_string.empty?
|
|
552
583
|
generate_prompt(Array(prompt).first, c)
|
|
553
|
-
|
|
554
584
|
# Otherwise use the wait prompt (indicating multi-line expression)
|
|
555
585
|
else
|
|
556
586
|
generate_prompt(Array(prompt).last, c)
|
|
@@ -655,7 +685,9 @@ class Pry
|
|
|
655
685
|
raise exception
|
|
656
686
|
end
|
|
657
687
|
end
|
|
688
|
+
|
|
658
689
|
def raise_up(*args); raise_up_common(false, *args); end
|
|
690
|
+
|
|
659
691
|
def raise_up!(*args); raise_up_common(true, *args); end
|
|
660
692
|
|
|
661
693
|
# Convenience accessor for the `quiet` config key.
|
|
@@ -664,3 +696,4 @@ class Pry
|
|
|
664
696
|
config.quiet
|
|
665
697
|
end
|
|
666
698
|
end
|
|
699
|
+
# rubocop:enable Metrics/ClassLength
|
data/lib/pry/repl.rb
CHANGED
|
@@ -49,7 +49,7 @@ class Pry
|
|
|
49
49
|
|
|
50
50
|
# Clear the line before starting Pry. This fixes issue #566.
|
|
51
51
|
if pry.config.correct_indent
|
|
52
|
-
Kernel.print
|
|
52
|
+
Kernel.print(Helpers::Platform.windows_ansi? ? "\e[0F" : "\e[0G")
|
|
53
53
|
end
|
|
54
54
|
end
|
|
55
55
|
|
|
@@ -106,8 +106,9 @@ class Pry
|
|
|
106
106
|
|
|
107
107
|
if output.tty? && pry.config.correct_indent && Pry::Helpers::BaseHelpers.use_ansi_codes?
|
|
108
108
|
output.print @indent.correct_indentation(
|
|
109
|
-
current_prompt,
|
|
110
|
-
|
|
109
|
+
current_prompt,
|
|
110
|
+
indented_val,
|
|
111
|
+
calculate_overhang(current_prompt, original_val, indented_val)
|
|
111
112
|
)
|
|
112
113
|
output.flush
|
|
113
114
|
end
|
|
@@ -218,15 +219,43 @@ class Pry
|
|
|
218
219
|
# % pry | tee log
|
|
219
220
|
def piping?
|
|
220
221
|
return false unless $stdout.respond_to?(:tty?)
|
|
221
|
-
|
|
222
|
+
|
|
223
|
+
!$stdout.tty? && $stdin.tty? && !Helpers::Platform.windows?
|
|
222
224
|
end
|
|
223
225
|
|
|
224
226
|
# @return [void]
|
|
225
227
|
def set_readline_output
|
|
226
228
|
return if @readline_output
|
|
229
|
+
|
|
227
230
|
if piping?
|
|
228
231
|
@readline_output = (Readline.output = Pry.config.output)
|
|
229
232
|
end
|
|
230
233
|
end
|
|
234
|
+
|
|
235
|
+
# Calculates correct overhang for current line. Supports vi Readline
|
|
236
|
+
# mode and its indicators such as "(ins)" or "(cmd)".
|
|
237
|
+
#
|
|
238
|
+
# @return [Integer]
|
|
239
|
+
# @note This doesn't calculate overhang for Readline's emacs mode with an
|
|
240
|
+
# indicator because emacs is the default mode and it doesn't use
|
|
241
|
+
# indicators in 99% of cases.
|
|
242
|
+
def calculate_overhang(current_prompt, original_val, indented_val)
|
|
243
|
+
overhang = original_val.length - indented_val.length
|
|
244
|
+
|
|
245
|
+
if readline_available? && Readline.respond_to?(:vi_editing_mode?)
|
|
246
|
+
begin
|
|
247
|
+
# rb-readline doesn't support this method:
|
|
248
|
+
# https://github.com/ConnorAtherton/rb-readline/issues/152
|
|
249
|
+
if Readline.vi_editing_mode?
|
|
250
|
+
overhang += current_prompt.length - indented_val.length
|
|
251
|
+
end
|
|
252
|
+
rescue NotImplementedError
|
|
253
|
+
# VI editing mode is unsupported on JRuby.
|
|
254
|
+
# https://github.com/pry/pry/issues/1840
|
|
255
|
+
nil
|
|
256
|
+
end
|
|
257
|
+
end
|
|
258
|
+
[0, overhang].max
|
|
259
|
+
end
|
|
231
260
|
end
|
|
232
261
|
end
|
data/lib/pry/repl_file_loader.rb
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
class Pry
|
|
2
|
-
|
|
3
2
|
# A class to manage the loading of files through the REPL loop.
|
|
4
3
|
# This is an interesting trick as it processes your file as if it
|
|
5
4
|
# was user input in an interactive session. As a result, all Pry
|
|
@@ -42,7 +41,7 @@ class Pry
|
|
|
42
41
|
end
|
|
43
42
|
|
|
44
43
|
content.lines.each do |line|
|
|
45
|
-
break unless _pry_.eval line, :
|
|
44
|
+
break unless _pry_.eval line, generated: true
|
|
46
45
|
end
|
|
47
46
|
|
|
48
47
|
unless _pry_.eval_string.empty?
|
data/lib/pry/ring.rb
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
class Pry
|
|
2
|
+
# A ring is a thread-safe fixed-capacity array to which you can only add
|
|
3
|
+
# elements. Older entries are overwritten as you add new elements, so that the
|
|
4
|
+
# ring can never contain more than `max_size` elemens.
|
|
5
|
+
#
|
|
6
|
+
# @example
|
|
7
|
+
# ring = Pry::Ring.new(3)
|
|
8
|
+
# ring << 1 << 2 << 3
|
|
9
|
+
# ring.to_a #=> [1, 2, 3]
|
|
10
|
+
# ring << 4
|
|
11
|
+
# ring.to_a #=> [2, 3, 4]
|
|
12
|
+
#
|
|
13
|
+
# ring[0] #=> 2
|
|
14
|
+
# ring[-1] #=> 4
|
|
15
|
+
# ring.clear
|
|
16
|
+
# ring[0] #=> nil
|
|
17
|
+
#
|
|
18
|
+
# @api public
|
|
19
|
+
# @since v0.12.0
|
|
20
|
+
class Ring
|
|
21
|
+
# @return [Integer] maximum buffer size
|
|
22
|
+
attr_reader :max_size
|
|
23
|
+
|
|
24
|
+
# @return [Integer] how many objects were added during the lifetime of the
|
|
25
|
+
# ring
|
|
26
|
+
attr_reader :count
|
|
27
|
+
alias size count
|
|
28
|
+
|
|
29
|
+
# @param [Integer] max_size Maximum buffer size. The buffer will start
|
|
30
|
+
# overwriting elements once its reaches its maximum capacity
|
|
31
|
+
def initialize(max_size)
|
|
32
|
+
@max_size = max_size
|
|
33
|
+
@mutex = Mutex.new
|
|
34
|
+
clear
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Push `value` to the current index.
|
|
38
|
+
#
|
|
39
|
+
# @param [Object] value
|
|
40
|
+
# @return [self]
|
|
41
|
+
def <<(value)
|
|
42
|
+
@mutex.synchronize do
|
|
43
|
+
@buffer[count % max_size] = value
|
|
44
|
+
@count += 1
|
|
45
|
+
self
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Read the value stored at `index`.
|
|
50
|
+
#
|
|
51
|
+
# @param [Integer, Range] index The element (if Integer) or elements
|
|
52
|
+
# (if Range) associated with `index`
|
|
53
|
+
# @return [Object, Array<Object>, nil] element(s) at `index`, `nil` if none
|
|
54
|
+
# exist
|
|
55
|
+
def [](index)
|
|
56
|
+
@mutex.synchronize do
|
|
57
|
+
return @buffer[(count + index) % max_size] if index.is_a?(Integer)
|
|
58
|
+
return @buffer[index] if count <= max_size
|
|
59
|
+
|
|
60
|
+
# Swap parts of array when the array turns page and starts overwriting
|
|
61
|
+
# from the beginning, then apply the range.
|
|
62
|
+
last_part = @buffer.slice([index.end, max_size - 1].min, count % max_size)
|
|
63
|
+
(last_part + (@buffer - last_part))[index]
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# @return [Array<Object>] the buffer as unwinded array
|
|
68
|
+
def to_a
|
|
69
|
+
return @buffer.dup if count <= max_size
|
|
70
|
+
|
|
71
|
+
last_part = @buffer.slice(count % max_size, @buffer.size)
|
|
72
|
+
last_part + (@buffer - last_part)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Clear the buffer and reset count.
|
|
76
|
+
# @return [void]
|
|
77
|
+
def clear
|
|
78
|
+
@mutex.synchronize do
|
|
79
|
+
@buffer = []
|
|
80
|
+
@count = 0
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
data/lib/pry/rubygem.rb
CHANGED
|
@@ -23,7 +23,7 @@ class Pry
|
|
|
23
23
|
Gem.source_index.find_name(name)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
-
first_spec = specs.sort_by{ |spec| Gem::Version.new(spec.version) }.last
|
|
26
|
+
first_spec = specs.sort_by { |spec| Gem::Version.new(spec.version) }.last
|
|
27
27
|
|
|
28
28
|
first_spec or raise CommandError, "Gem `#{name}` not found"
|
|
29
29
|
end
|
|
@@ -34,9 +34,9 @@ class Pry
|
|
|
34
34
|
# @return [Array<Gem::Specification>]
|
|
35
35
|
def list(pattern = /.*/)
|
|
36
36
|
if Gem::Specification.respond_to?(:each)
|
|
37
|
-
Gem::Specification.select{|spec| spec.name =~ pattern }
|
|
37
|
+
Gem::Specification.select { |spec| spec.name =~ pattern }
|
|
38
38
|
else
|
|
39
|
-
Gem.source_index.gems.values.select{|spec| spec.name =~ pattern }
|
|
39
|
+
Gem.source_index.gems.values.select { |spec| spec.name =~ pattern }
|
|
40
40
|
end
|
|
41
41
|
end
|
|
42
42
|
|
|
@@ -67,14 +67,14 @@ class Pry
|
|
|
67
67
|
else
|
|
68
68
|
Gem.user_dir
|
|
69
69
|
end
|
|
70
|
-
installer = Gem::DependencyInstaller.new(:
|
|
70
|
+
installer = Gem::DependencyInstaller.new(install_dir: destination)
|
|
71
71
|
installer.install(name)
|
|
72
72
|
rescue Errno::EACCES
|
|
73
73
|
raise CommandError,
|
|
74
|
-
"Insufficient permissions to install #{
|
|
74
|
+
"Insufficient permissions to install #{green(name)}."
|
|
75
75
|
rescue Gem::GemNotFoundException
|
|
76
76
|
raise CommandError,
|
|
77
|
-
"Gem #{
|
|
77
|
+
"Gem #{green(name)} not found. Aborting installation."
|
|
78
78
|
else
|
|
79
79
|
Gem.refresh
|
|
80
80
|
end
|
data/lib/pry/slop/commands.rb
CHANGED
|
@@ -133,13 +133,13 @@ class Pry::Slop
|
|
|
133
133
|
#
|
|
134
134
|
# Returns the original Array of items with options removed.
|
|
135
135
|
def parse!(items = ARGV)
|
|
136
|
-
if opts = commands[items[0].to_s]
|
|
136
|
+
if (opts = commands[items[0].to_s])
|
|
137
137
|
@triggered_command = items.shift
|
|
138
138
|
execute_arguments! items
|
|
139
139
|
opts.parse! items
|
|
140
140
|
execute_global_opts! items
|
|
141
141
|
else
|
|
142
|
-
if opts = commands['default']
|
|
142
|
+
if (opts = commands['default'])
|
|
143
143
|
opts.parse! items
|
|
144
144
|
else
|
|
145
145
|
if config[:strict] && items[0]
|
|
@@ -187,10 +187,9 @@ class Pry::Slop
|
|
|
187
187
|
|
|
188
188
|
# Returns nothing.
|
|
189
189
|
def execute_global_opts!(items)
|
|
190
|
-
if global_opts = commands['global']
|
|
190
|
+
if (global_opts = commands['global'])
|
|
191
191
|
global_opts.parse! items
|
|
192
192
|
end
|
|
193
193
|
end
|
|
194
|
-
|
|
195
194
|
end
|
|
196
195
|
end
|
data/lib/pry/slop/option.rb
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
class Pry::Slop
|
|
2
2
|
class Option
|
|
3
|
-
|
|
4
3
|
# The default Hash of configuration options this class uses.
|
|
5
4
|
DEFAULT_OPTIONS = {
|
|
6
|
-
:
|
|
7
|
-
:
|
|
8
|
-
:
|
|
9
|
-
:
|
|
10
|
-
:
|
|
11
|
-
:
|
|
12
|
-
:
|
|
13
|
-
:
|
|
14
|
-
:
|
|
15
|
-
:
|
|
16
|
-
:
|
|
17
|
-
:
|
|
5
|
+
argument: false,
|
|
6
|
+
optional_argument: false,
|
|
7
|
+
tail: false,
|
|
8
|
+
default: nil,
|
|
9
|
+
callback: nil,
|
|
10
|
+
delimiter: ',',
|
|
11
|
+
limit: 0,
|
|
12
|
+
match: nil,
|
|
13
|
+
optional: true,
|
|
14
|
+
required: false,
|
|
15
|
+
as: String,
|
|
16
|
+
autocreated: false
|
|
18
17
|
}
|
|
19
18
|
|
|
20
19
|
attr_reader :short, :long, :description, :config, :types
|
|
@@ -41,12 +40,12 @@ class Pry::Slop
|
|
|
41
40
|
@value = nil
|
|
42
41
|
|
|
43
42
|
@types = {
|
|
44
|
-
:
|
|
45
|
-
:
|
|
46
|
-
:
|
|
47
|
-
:
|
|
48
|
-
:
|
|
49
|
-
:
|
|
43
|
+
string: proc { |v| v.to_s },
|
|
44
|
+
symbol: proc { |v| v.to_sym },
|
|
45
|
+
integer: proc { |v| value_to_integer(v) },
|
|
46
|
+
float: proc { |v| value_to_float(v) },
|
|
47
|
+
range: proc { |v| value_to_range(v) },
|
|
48
|
+
count: proc { |v| @count }
|
|
50
49
|
}
|
|
51
50
|
|
|
52
51
|
if long && long.size > @slop.config[:longest_flag]
|
|
@@ -114,7 +113,7 @@ class Pry::Slop
|
|
|
114
113
|
if type.respond_to?(:call)
|
|
115
114
|
type.call(value)
|
|
116
115
|
else
|
|
117
|
-
if callable = types[type.to_s.downcase.to_sym]
|
|
116
|
+
if (callable = types[type.to_s.downcase.to_sym])
|
|
118
117
|
callable.call(value)
|
|
119
118
|
else
|
|
120
119
|
value
|
|
@@ -203,6 +202,5 @@ class Pry::Slop
|
|
|
203
202
|
end
|
|
204
203
|
end
|
|
205
204
|
end
|
|
206
|
-
|
|
207
205
|
end
|
|
208
206
|
end
|