pry 0.11.3 → 0.12.2

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.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +157 -1
  3. data/LICENSE +1 -1
  4. data/README.md +13 -30
  5. data/bin/pry +0 -4
  6. data/lib/pry/cli.rb +17 -24
  7. data/lib/pry/code/code_file.rb +5 -4
  8. data/lib/pry/code/code_range.rb +3 -3
  9. data/lib/pry/code/loc.rb +14 -8
  10. data/lib/pry/code.rb +6 -6
  11. data/lib/pry/code_object.rb +4 -4
  12. data/lib/pry/color_printer.rb +1 -0
  13. data/lib/pry/command.rb +36 -29
  14. data/lib/pry/command_set.rb +17 -52
  15. data/lib/pry/commands/amend_line.rb +3 -4
  16. data/lib/pry/commands/bang.rb +1 -1
  17. data/lib/pry/commands/cat/exception_formatter.rb +9 -8
  18. data/lib/pry/commands/cat/input_expression_formatter.rb +1 -1
  19. data/lib/pry/commands/cat.rb +7 -6
  20. data/lib/pry/commands/change_prompt.rb +29 -9
  21. data/lib/pry/commands/clear_screen.rb +14 -0
  22. data/lib/pry/commands/code_collector.rb +9 -9
  23. data/lib/pry/commands/easter_eggs.rb +3 -3
  24. data/lib/pry/commands/edit.rb +8 -7
  25. data/lib/pry/commands/exit.rb +2 -1
  26. data/lib/pry/commands/find_method.rb +11 -13
  27. data/lib/pry/commands/gem_cd.rb +1 -1
  28. data/lib/pry/commands/gem_install.rb +2 -2
  29. data/lib/pry/commands/gem_list.rb +2 -2
  30. data/lib/pry/commands/gem_open.rb +1 -1
  31. data/lib/pry/commands/gem_search.rb +2 -2
  32. data/lib/pry/commands/gem_stats.rb +83 -0
  33. data/lib/pry/commands/gist.rb +7 -6
  34. data/lib/pry/commands/help.rb +3 -3
  35. data/lib/pry/commands/hist.rb +9 -8
  36. data/lib/pry/commands/import_set.rb +2 -1
  37. data/lib/pry/commands/install_command.rb +7 -6
  38. data/lib/pry/commands/list_inspectors.rb +2 -2
  39. data/lib/pry/commands/ls/constants.rb +4 -4
  40. data/lib/pry/commands/ls/formatter.rb +3 -2
  41. data/lib/pry/commands/ls/globals.rb +0 -2
  42. data/lib/pry/commands/ls/grep.rb +0 -2
  43. data/lib/pry/commands/ls/instance_vars.rb +0 -1
  44. data/lib/pry/commands/ls/local_names.rb +0 -2
  45. data/lib/pry/commands/ls/local_vars.rb +0 -2
  46. data/lib/pry/commands/ls/ls_entity.rb +0 -1
  47. data/lib/pry/commands/ls/methods.rb +0 -3
  48. data/lib/pry/commands/ls/methods_helper.rb +1 -1
  49. data/lib/pry/commands/ls/self_methods.rb +0 -1
  50. data/lib/pry/commands/ls.rb +27 -30
  51. data/lib/pry/commands/play.rb +1 -2
  52. data/lib/pry/commands/pry_backtrace.rb +1 -1
  53. data/lib/pry/commands/raise_up.rb +2 -1
  54. data/lib/pry/commands/ri.rb +5 -4
  55. data/lib/pry/commands/shell_command.rb +3 -2
  56. data/lib/pry/commands/shell_mode.rb +6 -6
  57. data/lib/pry/commands/show_doc.rb +5 -7
  58. data/lib/pry/commands/show_info.rb +25 -18
  59. data/lib/pry/commands/show_source.rb +5 -2
  60. data/lib/pry/commands/stat.rb +1 -1
  61. data/lib/pry/commands/watch_expression.rb +9 -7
  62. data/lib/pry/commands/whereami.rb +4 -4
  63. data/lib/pry/commands/wtf.rb +15 -2
  64. data/lib/pry/config/behavior.rb +229 -205
  65. data/lib/pry/config/convenience.rb +24 -21
  66. data/lib/pry/config/default.rb +153 -143
  67. data/lib/pry/config/memoization.rb +41 -37
  68. data/lib/pry/config.rb +33 -9
  69. data/lib/pry/core_extensions.rb +4 -3
  70. data/lib/pry/editor.rb +5 -12
  71. data/lib/pry/exceptions.rb +0 -2
  72. data/lib/pry/helpers/base_helpers.rb +133 -4
  73. data/lib/pry/helpers/command_helpers.rb +5 -4
  74. data/lib/pry/helpers/documentation_helpers.rb +2 -2
  75. data/lib/pry/helpers/options_helpers.rb +5 -5
  76. data/lib/pry/helpers/platform.rb +58 -0
  77. data/lib/pry/helpers/table.rb +20 -15
  78. data/lib/pry/helpers/text.rb +3 -4
  79. data/lib/pry/helpers.rb +1 -0
  80. data/lib/pry/history.rb +21 -8
  81. data/lib/pry/hooks.rb +3 -3
  82. data/lib/pry/indent.rb +15 -17
  83. data/lib/pry/input_completer.rb +12 -7
  84. data/lib/pry/input_lock.rb +0 -2
  85. data/lib/pry/last_exception.rb +1 -1
  86. data/lib/pry/method/disowned.rb +2 -1
  87. data/lib/pry/method/patcher.rb +2 -2
  88. data/lib/pry/method/weird_method_locator.rb +7 -8
  89. data/lib/pry/method.rb +37 -31
  90. data/lib/pry/object_path.rb +5 -4
  91. data/lib/pry/output.rb +3 -2
  92. data/lib/pry/pager.rb +194 -186
  93. data/lib/pry/platform.rb +79 -81
  94. data/lib/pry/plugins.rb +7 -3
  95. data/lib/pry/prompt.rb +144 -25
  96. data/lib/pry/pry_class.rb +53 -29
  97. data/lib/pry/pry_instance.rb +88 -55
  98. data/lib/pry/repl.rb +33 -4
  99. data/lib/pry/repl_file_loader.rb +1 -2
  100. data/lib/pry/ring.rb +84 -0
  101. data/lib/pry/rubygem.rb +6 -6
  102. data/lib/pry/slop/commands.rb +3 -4
  103. data/lib/pry/slop/option.rb +19 -21
  104. data/lib/pry/slop.rb +17 -17
  105. data/lib/pry/terminal.rb +2 -1
  106. data/lib/pry/testable/mockable.rb +2 -2
  107. data/lib/pry/testable/pry_tester.rb +1 -1
  108. data/lib/pry/testable/utility.rb +2 -2
  109. data/lib/pry/testable/variables.rb +1 -1
  110. data/lib/pry/version.rb +1 -1
  111. data/lib/pry/wrapped_module/candidate.rb +2 -2
  112. data/lib/pry/wrapped_module.rb +15 -15
  113. data/lib/pry.rb +17 -47
  114. metadata +8 -20
  115. data/lib/pry/commands/list_prompts.rb +0 -35
  116. data/lib/pry/commands/simple_prompt.rb +0 -22
  117. data/lib/pry/history_array.rb +0 -121
  118. data/lib/pry/rbx_path.rb +0 -22
data/lib/pry/command.rb CHANGED
@@ -2,7 +2,6 @@ require 'delegate'
2
2
  require 'pry/helpers/documentation_helpers'
3
3
 
4
4
  class Pry
5
-
6
5
  # The super-class of all commands, new commands should be created by calling
7
6
  # {Pry::CommandSet#command} which creates a BlockCommand or {Pry::CommandSet#create_command}
8
7
  # which creates a ClassCommand. Please don't use this class directly.
@@ -24,7 +23,7 @@ class Pry
24
23
  attr_writer :command_options
25
24
  attr_writer :match
26
25
 
27
- def match(arg=nil)
26
+ def match(arg = nil)
28
27
  if arg
29
28
  @command_options ||= default_options(arg)
30
29
  @command_options[:listing] = arg.is_a?(String) ? arg : arg.inspect
@@ -34,13 +33,13 @@ class Pry
34
33
  end
35
34
 
36
35
  # Define or get the command's description
37
- def description(arg=nil)
36
+ def description(arg = nil)
38
37
  @description = arg if arg
39
38
  @description ||= nil
40
39
  end
41
40
 
42
41
  # Define or get the command's options
43
- def command_options(arg=nil)
42
+ def command_options(arg = nil)
44
43
  @command_options ||= default_options(match)
45
44
  @command_options.merge!(arg) if arg
46
45
  @command_options
@@ -50,7 +49,7 @@ class Pry
50
49
  alias_method :options=, :command_options=
51
50
 
52
51
  # Define or get the command's banner
53
- def banner(arg=nil)
52
+ def banner(arg = nil)
54
53
  @banner = arg if arg
55
54
  @banner ||= description
56
55
  end
@@ -68,10 +67,6 @@ class Pry
68
67
  new.help
69
68
  end
70
69
 
71
- def source_location
72
- block.source_location
73
- end
74
-
75
70
  def source_file
76
71
  Array(block.source_location).first
77
72
  end
@@ -84,27 +79,32 @@ class Pry
84
79
 
85
80
  def default_options(match)
86
81
  {
87
- :requires_gem => [],
88
- :keep_retval => false,
89
- :argument_required => false,
90
- :interpolate => true,
91
- :shellwords => true,
92
- :listing => (String === match ? match : match.inspect),
93
- :use_prefix => true,
94
- :takes_block => false
82
+ requires_gem: [],
83
+ keep_retval: false,
84
+ argument_required: false,
85
+ interpolate: true,
86
+ shellwords: true,
87
+ listing: (String === match ? match : match.inspect),
88
+ use_prefix: true,
89
+ takes_block: false
95
90
  }
96
91
  end
97
92
  end
98
93
 
99
94
  # Make those properties accessible to instances
100
95
  def name; self.class.name; end
96
+
101
97
  def match; self.class.match; end
98
+
102
99
  def description; self.class.description; end
100
+
103
101
  def block; self.class.block; end
102
+
104
103
  def command_options; self.class.options; end
104
+
105
105
  def command_name; self.class.command_name; end
106
+
106
107
  def source; self.class.source; end
107
- def source_location; self.class.source_location; end
108
108
 
109
109
  class << self
110
110
  def name
@@ -169,8 +169,6 @@ class Pry
169
169
 
170
170
  # @deprecated Replaced with {Pry::Hooks#add_hook}. Left for compatibility.
171
171
  # Store hooks to be run before or after the command body.
172
- # @see {Pry::CommandSet#before_command}
173
- # @see {Pry::CommandSet#after_command}
174
172
  def hooks
175
173
  Pry.hooks
176
174
  end
@@ -196,7 +194,7 @@ class Pry
196
194
  # This is usually auto-generated from directory naming, but it can be
197
195
  # manually overridden if necessary.
198
196
  # Group should not be changed once it is initialized.
199
- def group(name=nil)
197
+ def group(name = nil)
200
198
  @group ||= if name
201
199
  name
202
200
  else
@@ -205,9 +203,9 @@ class Pry
205
203
  $1.capitalize.gsub(/_/, " ")
206
204
  when %r{(pry-\w+)-([\d\.]+([\w\.]+)?)}
207
205
  name, version = $1, $2
208
- "#{name.to_s} (v#{version.to_s})"
206
+ "#{name} (v#{version})"
209
207
  when /pryrc/
210
- "~/.pryrc"
208
+ "pryrc"
211
209
  else
212
210
  "(other)"
213
211
  end
@@ -254,6 +252,14 @@ class Pry
254
252
  command_set.to_hash
255
253
  end
256
254
 
255
+ #
256
+ # @deprecated
257
+ # Please use black(), white(), etc directly instead (as you would with helper
258
+ # functions from BaseHelpers and CommandHelpers)
259
+ #
260
+ # @return [Module]
261
+ # Returns Pry::Helpers::Text
262
+ #
257
263
  def text
258
264
  Pry::Helpers::Text
259
265
  end
@@ -264,10 +270,11 @@ class Pry
264
270
 
265
271
  include Pry::Helpers::BaseHelpers
266
272
  include Pry::Helpers::CommandHelpers
273
+ include Pry::Helpers::Text
267
274
 
268
275
  # Instantiate a command, in preparation for calling it.
269
276
  # @param [Hash] context The runtime context to use with this command.
270
- def initialize(context={})
277
+ def initialize(context = {})
271
278
  self.context = context
272
279
  self.target = context[:target]
273
280
  self.output = context[:output]
@@ -338,6 +345,7 @@ class Pry
338
345
 
339
346
  # please call Command.matches? before Command#call_safely
340
347
  raise CommandError, "fatal: called a command which didn't match?!" unless Regexp.last_match
348
+
341
349
  captures = Regexp.last_match.captures
342
350
  pos = Regexp.last_match.end(0)
343
351
 
@@ -450,9 +458,9 @@ class Pry
450
458
 
451
459
  # Generate completions for this command
452
460
  #
453
- # @param [String] search The line typed so far
461
+ # @param [String] _search The line typed so far
454
462
  # @return [Array<String>] Completion words
455
- def complete(search)
463
+ def complete(_search)
456
464
  []
457
465
  end
458
466
 
@@ -537,12 +545,11 @@ class Pry
537
545
  # gems your command needs to run, or to set up state.
538
546
  class ClassCommand < Command
539
547
  class << self
540
-
541
548
  # Ensure that subclasses inherit the options, description and
542
549
  # match from a ClassCommand super class.
543
550
  def inherited(klass)
544
- klass.match match
545
- klass.description description
551
+ klass.match match
552
+ klass.description description
546
553
  klass.command_options options
547
554
  end
548
555
 
@@ -75,7 +75,7 @@ class Pry
75
75
  # # hello john, nice number: 10
76
76
  # # pry(main)> help number
77
77
  # # number-N regex command
78
- def block_command(match, description="No description.", options={}, &block)
78
+ def block_command(match, description = "No description.", options = {}, &block)
79
79
  description, options = ["No description.", description] if description.is_a?(Hash)
80
80
  options = Pry::Command.default_options(match).merge!(options)
81
81
 
@@ -107,7 +107,7 @@ class Pry
107
107
  # end
108
108
  # end
109
109
  #
110
- def create_command(match, description="No description.", options={}, &block)
110
+ def create_command(match, description = "No description.", options = {}, &block)
111
111
  description, options = ["No description.", description] if description.is_a?(Hash)
112
112
  options = Pry::Command.default_options(match).merge!(options)
113
113
 
@@ -116,41 +116,6 @@ class Pry
116
116
  @commands[match]
117
117
  end
118
118
 
119
- # Execute a block of code before a command is invoked. The block also
120
- # gets access to parameters that will be passed to the command and
121
- # is evaluated in the same context.
122
- # @param [String, Regexp] search The match or listing of the command.
123
- # @yield The block to be run before the command.
124
- # @example Display parameter before invoking command
125
- # Pry.config.commands.before_command("whereami") do |n|
126
- # output.puts "parameter passed was #{n}"
127
- # end
128
- # @deprecated Use {Pry::Hooks#add_hook} instead.
129
- def before_command(search, &block)
130
- cmd = find_command_by_match_or_listing(search)
131
- cmd.hooks.add_hook("before_#{cmd.command_name}", random_hook_name, block)
132
- end
133
-
134
- # Execute a block of code after a command is invoked. The block also
135
- # gets access to parameters that will be passed to the command and
136
- # is evaluated in the same context.
137
- # @param [String, Regexp] search The match or listing of the command.
138
- # @yield The block to be run after the command.
139
- # @example Display text 'command complete' after invoking command
140
- # Pry.config.commands.after_command("whereami") do |n|
141
- # output.puts "command complete!"
142
- # end
143
- # @deprecated Use {Pry::Hooks#add_hook} instead.
144
- def after_command(search, &block)
145
- cmd = find_command_by_match_or_listing(search)
146
- cmd.hooks.add_hook("after_#{cmd.command_name}", random_hook_name, block)
147
- end
148
-
149
- def random_hook_name
150
- (0...8).map { ('a'..'z').to_a[rand(26)] }.join
151
- end
152
- private :random_hook_name
153
-
154
119
  def each(&block)
155
120
  @commands.each(&block)
156
121
  end
@@ -209,13 +174,13 @@ class Pry
209
174
  # Pry.config.commands.alias_command "lM", "ls -M"
210
175
  # @example Pass explicit description (overriding default).
211
176
  # Pry.config.commands.alias_command "lM", "ls -M", :desc => "cutiepie"
212
- def alias_command(match, action, options={})
177
+ def alias_command(match, action, options = {})
213
178
  cmd = find_command(action) or fail "Command: `#{action}` not found"
214
179
  original_options = cmd.options.dup
215
180
 
216
181
  options = original_options.merge!({
217
- :desc => "Alias for `#{action}`",
218
- :listing => match
182
+ desc: "Alias for `#{action}`",
183
+ listing: match
219
184
  }).merge!(options)
220
185
 
221
186
  # ensure default description is used if desc is nil
@@ -245,12 +210,12 @@ class Pry
245
210
  # command description to be passed this way too.
246
211
  # @example Renaming the `ls` command and changing its description.
247
212
  # Pry.config.commands.rename "dir", "ls", :description => "DOS friendly ls"
248
- def rename_command(new_match, search, options={})
213
+ def rename_command(new_match, search, options = {})
249
214
  cmd = find_command_by_match_or_listing(search)
250
215
 
251
216
  options = {
252
- :listing => new_match,
253
- :description => cmd.description
217
+ listing: new_match,
218
+ description: cmd.description
254
219
  }.merge!(options)
255
220
 
256
221
  @commands[new_match] = cmd.dup
@@ -260,7 +225,7 @@ class Pry
260
225
  @commands.delete(cmd.match)
261
226
  end
262
227
 
263
- def disabled_command(name_of_disabled_command, message, matcher=name_of_disabled_command)
228
+ def disabled_command(name_of_disabled_command, message, matcher = name_of_disabled_command)
264
229
  create_command name_of_disabled_command do
265
230
  match matcher
266
231
  description ""
@@ -282,7 +247,7 @@ class Pry
282
247
  # end
283
248
  # @example Getting
284
249
  # Pry.config.commands.desc "amend-line"
285
- def desc(search, description=nil)
250
+ def desc(search, description = nil)
286
251
  cmd = find_command_by_match_or_listing(search)
287
252
  return cmd.description if !description
288
253
 
@@ -305,7 +270,6 @@ class Pry
305
270
  helper_module.class_eval(&block)
306
271
  end
307
272
 
308
-
309
273
  # @return [Array]
310
274
  # The list of commands provided by the command set.
311
275
  def list_commands
@@ -352,6 +316,7 @@ class Pry
352
316
  unless Class === command && command < Pry::Command
353
317
  raise TypeError, "command is not a subclass of Pry::Command"
354
318
  end
319
+
355
320
  bind_command_to_pattern = pattern != command.match
356
321
  if bind_command_to_pattern
357
322
  command_copy = command.dup
@@ -394,9 +359,9 @@ class Pry
394
359
  # @param [String] val The line to execute
395
360
  # @param [Hash] context The context to execute the commands with
396
361
  # @return [CommandSet::Result]
397
- def process_line(val, context={})
398
- if command = find_command(val)
399
- context = context.merge(:command_set => self)
362
+ def process_line(val, context = {})
363
+ if (command = find_command(val))
364
+ context = context.merge(command_set: self)
400
365
  retval = command.new(context).process_line(val)
401
366
  Result.new(true, retval)
402
367
  else
@@ -414,13 +379,13 @@ class Pry
414
379
  # @param [String] search The line to search for
415
380
  # @param [Hash] context The context to create the command with
416
381
  # @return [Array<String>]
417
- def complete(search, context={})
418
- if command = find_command(search)
382
+ def complete(search, context = {})
383
+ if (command = find_command(search))
419
384
  command.new(context).complete(search)
420
385
  else
421
386
  @commands.keys.select do |key|
422
387
  String === key && key.start_with?(search)
423
- end.map{ |key| key + " " }
388
+ end.map { |key| key + " " }
424
389
  end
425
390
  end
426
391
  end
@@ -3,7 +3,7 @@ class Pry
3
3
  match(/amend-line(?: (-?\d+)(?:\.\.(-?\d+))?)?/)
4
4
  group 'Editing'
5
5
  description 'Amend a line of input in multi-line mode.'
6
- command_options :interpolate => false, :listing => 'amend-line'
6
+ command_options interpolate: false, listing: 'amend-line'
7
7
 
8
8
  banner <<-'BANNER'
9
9
  Amend a line of input in multi-line mode. `amend-line N`, where the N represents
@@ -19,16 +19,15 @@ class Pry
19
19
  def process
20
20
  raise CommandError, "No input to amend." if eval_string.empty?
21
21
 
22
- eval_string.replace amended_input(eval_string)
22
+ eval_string.replace(amend_input)
23
23
  run "fix-indent"
24
24
  run "show-input"
25
25
  end
26
26
 
27
27
  private
28
28
 
29
- # @param [String] string The string to amend.
30
29
  # @return [String] A new string with the amendments applied to it.
31
- def amended_input(string)
30
+ def amend_input
32
31
  input_array = eval_string.each_line.to_a
33
32
 
34
33
  if arg_string == "!"
@@ -3,7 +3,7 @@ class Pry
3
3
  match(/^\s*!\s*$/)
4
4
  group 'Editing'
5
5
  description 'Clear the input buffer.'
6
- command_options :use_prefix => false
6
+ command_options use_prefix: false
7
7
 
8
8
  banner <<-'BANNER'
9
9
  Clear the input buffer. Useful if the parsing process goes wrong and you get
@@ -4,6 +4,7 @@ class Pry
4
4
  attr_reader :ex
5
5
  attr_reader :opts
6
6
  attr_reader :_pry_
7
+ include Pry::Helpers::Text
7
8
 
8
9
  def initialize(exception, _pry_, opts)
9
10
  @ex = exception
@@ -29,11 +30,12 @@ class Pry
29
30
  def backtrace_level
30
31
  @backtrace_level ||=
31
32
  begin
32
- bl = if opts[:ex].nil?
33
- ex.bt_index
34
- else
35
- ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
36
- end
33
+ bl =
34
+ if opts[:ex].nil?
35
+ ex.bt_index
36
+ else
37
+ ex.bt_index = absolute_index_number(opts[:ex], ex.backtrace.size)
38
+ end
37
39
 
38
40
  increment_backtrace_level
39
41
  bl
@@ -66,13 +68,12 @@ class Pry
66
68
 
67
69
  def header
68
70
  unindent %{
69
- #{Helpers::Text.bold 'Exception:'} #{ex.class}: #{ex.message}
71
+ #{bold 'Exception:'} #{ex.class}: #{ex.message}
70
72
  --
71
- #{Helpers::Text.bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{Helpers::Text.bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
73
+ #{bold('From:')} #{backtrace_file} @ line #{backtrace_line} @ #{bold("level: #{backtrace_level}")} of backtrace (of #{ex.backtrace.size - 1}).
72
74
 
73
75
  }
74
76
  end
75
-
76
77
  end
77
78
  end
78
79
  end
@@ -36,7 +36,7 @@ class Pry
36
36
  end
37
37
 
38
38
  def normalized_expression_range
39
- absolute_index_range(opts[:i], input_expressions.length)
39
+ absolute_index_range(opts[:i], input_expressions.count)
40
40
  end
41
41
  end
42
42
  end
@@ -23,12 +23,12 @@ class Pry
23
23
  BANNER
24
24
 
25
25
  def options(opt)
26
- opt.on :ex, "Show the context of the last exception", :optional_argument => true, :as => Integer
27
- opt.on :i, :in, "Show one or more entries from Pry's expression history", :optional_argument => true, :as => Range, :default => -5..-1
28
- opt.on :s, :start, "Starting line (defaults to the first line)", :optional_argument => true, :as => Integer
29
- opt.on :e, :end, "Ending line (defaults to the last line)", :optional_argument => true, :as => Integer
26
+ opt.on :ex, "Show the context of the last exception", optional_argument: true, as: Integer
27
+ opt.on :i, :in, "Show one or more entries from Pry's expression history", optional_argument: true, as: Range, default: -5..-1
28
+ opt.on :s, :start, "Starting line (defaults to the first line)", optional_argument: true, as: Integer
29
+ opt.on :e, :end, "Ending line (defaults to the last line)", optional_argument: true, as: Integer
30
30
  opt.on :l, :'line-numbers', "Show line numbers"
31
- opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", :argument => true, :as => Symbol
31
+ opt.on :t, :type, "The file type for syntax highlighting (e.g., 'ruby' or 'python')", argument: true, as: Symbol
32
32
  end
33
33
 
34
34
  def process
@@ -36,7 +36,7 @@ class Pry
36
36
  when opts.present?(:ex)
37
37
  ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format
38
38
  when opts.present?(:in)
39
- InputExpressionFormatter.new(_pry_.input_array, opts).format
39
+ InputExpressionFormatter.new(_pry_.input_ring, opts).format
40
40
  else
41
41
  FileFormatter.new(args.first, _pry_, opts).format
42
42
  end
@@ -52,6 +52,7 @@ class Pry
52
52
  $LOAD_PATH.flat_map do |path|
53
53
  Dir[path + '/**/*'].map { |f|
54
54
  next if File.directory?(f)
55
+
55
56
  f.sub!(path + '/', '')
56
57
  }
57
58
  end
@@ -4,23 +4,43 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand
4
4
  description 'Change the current prompt.'
5
5
  command_options argument_required: true
6
6
  banner <<-BANNER
7
- Usage: change-prompt NAME
7
+ Usage: change-prompt [OPTIONS] [NAME]
8
8
 
9
- Change the current prompt. See list-prompts for a list of available
10
- prompts.
9
+ Change the current prompt.
11
10
  BANNER
12
11
 
12
+ def options(opt)
13
+ opt.on(:l, :list, 'List the available prompts')
14
+ end
15
+
13
16
  def process(prompt)
14
- if prompt_map.key?(prompt)
15
- _pry_.prompt = prompt_map[prompt][:value]
17
+ if opts.present?(:l)
18
+ list_prompts
16
19
  else
17
- raise Pry::CommandError, "'#{prompt}' isn't a known prompt!"
20
+ change_prompt(prompt)
18
21
  end
19
22
  end
20
23
 
21
- private
22
- def prompt_map
23
- Pry::Prompt::MAP
24
+ private
25
+
26
+ def list_prompts
27
+ prompts = Pry::Prompt.all.map do |name, prompt|
28
+ "#{bold(name)}#{red(' (selected)') if _pry_.prompt == prompt[:value]}\n" +
29
+ prompt[:description]
30
+ end
31
+ output.puts(prompts.join("\n"))
24
32
  end
33
+
34
+ def change_prompt(prompt)
35
+ if Pry::Prompt.all.key?(prompt)
36
+ _pry_.prompt = Pry::Prompt.all[prompt][:value]
37
+ else
38
+ raise(Pry::CommandError, <<MSG)
39
+ '#{prompt}' isn't a known prompt. Run `change-prompt --list` to see
40
+ the list of known prompts.
41
+ MSG
42
+ end
43
+ end
44
+
25
45
  Pry::Commands.add_command(self)
26
46
  end
@@ -0,0 +1,14 @@
1
+ class Pry::Command::ClearScreen < Pry::ClassCommand
2
+ match 'clear-screen'
3
+ group 'Input and Output'
4
+ description 'Clear the contents of the screen/window Pry is running in.'
5
+
6
+ def process
7
+ if Helpers::Platform.windows?
8
+ _pry_.config.system.call(_pry_.output, 'cls', _pry_)
9
+ else
10
+ _pry_.config.system.call(_pry_.output, 'clear', _pry_)
11
+ end
12
+ end
13
+ Pry::Commands.add_command(self)
14
+ end
@@ -29,17 +29,17 @@ class Pry
29
29
  @output_result_ranges = []
30
30
 
31
31
  opt.on :l, :lines, "Restrict to a subset of lines. Takes a line number or range",
32
- :optional_argument => true, :as => Range, :default => 1..-1
32
+ optional_argument: true, as: Range, default: 1..-1
33
33
  opt.on :o, :out, "Select lines from Pry's output result history. Takes an index or range",
34
- :optional_argument => true, :as => Range, :default => -5..-1 do |r|
34
+ optional_argument: true, as: Range, default: -5..-1 do |r|
35
35
  output_result_ranges << (r || (-5..-1))
36
36
  end
37
37
  opt.on :i, :in, "Select lines from Pry's input expression history. Takes an index or range",
38
- :optional_argument => true, :as => Range, :default => -5..-1 do |r|
38
+ optional_argument: true, as: Range, default: -5..-1 do |r|
39
39
  input_expression_ranges << (r || (-5..-1))
40
40
  end
41
41
  opt.on :s, :super, "Select the 'super' method. Can be repeated to traverse the ancestors",
42
- :as => :count
42
+ as: :count
43
43
  opt.on :d, :doc, "Select lines from the code object's documentation"
44
44
  end
45
45
 
@@ -74,7 +74,7 @@ class Pry
74
74
  #
75
75
  # @return [Pry::WrappedModule, Pry::Method, Pry::Command]
76
76
  def code_object
77
- Pry::CodeObject.lookup(obj_name, _pry_, :super => opts[:super])
77
+ Pry::CodeObject.lookup(obj_name, _pry_, super: opts[:super])
78
78
  end
79
79
 
80
80
  # Given a string and a range, return the `range` lines of that
@@ -87,22 +87,22 @@ class Pry
87
87
  Array(content.lines.to_a[range]).join
88
88
  end
89
89
 
90
- # The selected `_pry_.output_array` as a string, as specified by
90
+ # The selected `_pry_.output_ring` as a string, as specified by
91
91
  # the `-o` switch.
92
92
  #
93
93
  # @return [String]
94
94
  def pry_output_content
95
- pry_array_content_as_string(_pry_.output_array, self.class.output_result_ranges) do |v|
95
+ pry_array_content_as_string(_pry_.output_ring, self.class.output_result_ranges) do |v|
96
96
  _pry_.config.gist.inspecter.call(v)
97
97
  end
98
98
  end
99
99
 
100
- # The selected `_pry_.input_array` as a string, as specified by
100
+ # The selected `_pry_.input_ring` as a string, as specified by
101
101
  # the `-i` switch.
102
102
  #
103
103
  # @return [String]
104
104
  def pry_input_content
105
- pry_array_content_as_string(_pry_.input_array, self.class.input_expression_ranges) { |v| v }
105
+ pry_array_content_as_string(_pry_.input_ring, self.class.input_expression_ranges) { |v| v }
106
106
  end
107
107
 
108
108
  # The line range passed to `--lines`, converted to a 0-indexed range.
@@ -1,6 +1,6 @@
1
1
  class Pry
2
2
  Pry::Commands.instance_eval do
3
- command "nyan-cat", "", :requires_gem => ["nyancat"] do
3
+ command "nyan-cat", "", requires_gem: ["nyancat"] do
4
4
  run ".nyancat"
5
5
  end
6
6
 
@@ -86,7 +86,7 @@ TEXT
86
86
  prev_color = _pry_.config.color
87
87
  _pry_.config.color = true
88
88
 
89
- picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| text.red(s) }
89
+ picture = unindent <<-'EOS'.gsub(/[[:alpha:]!]/) { |s| red(s) }
90
90
  ____ _______________________
91
91
  / \ | A W G |
92
92
  / O O \ | N I O N ! |
@@ -95,7 +95,7 @@ TEXT
95
95
  \____/ \________________________|
96
96
  EOS
97
97
 
98
- if windows_ansi?
98
+ if Helpers::Platform.windows_ansi?
99
99
  move_up = proc { |n| "\e[#{n}F" }
100
100
  else
101
101
  move_up = proc { |n| "\e[#{n}A\e[0G" }
@@ -24,12 +24,12 @@ class Pry
24
24
 
25
25
  def options(opt)
26
26
  opt.on :e, :ex, "Open the file that raised the most recent exception (_ex_.file)",
27
- :optional_argument => true, :as => Integer
27
+ optional_argument: true, as: Integer
28
28
  opt.on :i, :in, "Open a temporary file containing the Nth input expression. N may be a range",
29
- :optional_argument => true, :as => Range, :default => -1..-1
29
+ optional_argument: true, as: Range, default: -1..-1
30
30
  opt.on :t, :temp, "Open an empty temporary file"
31
31
  opt.on :l, :line, "Jump to this line in the opened file",
32
- :argument => true, :as => Integer
32
+ argument: true, as: Integer
33
33
  opt.on :n, :"no-reload", "Don't automatically reload the edited file"
34
34
  opt.on :c, :current, "Open the current __FILE__ and at __LINE__ (as returned by `whereami`)"
35
35
  opt.on :r, :reload, "Reload the edited code immediately (default for ruby files)"
@@ -65,6 +65,7 @@ class Pry
65
65
  silence_warnings do
66
66
  eval_string.replace content
67
67
  end
68
+ Pry.history.push(content)
68
69
  end
69
70
 
70
71
  def file_based_exception?
@@ -156,9 +157,9 @@ class Pry
156
157
  def input_expression
157
158
  case opts[:i]
158
159
  when Range
159
- (_pry_.input_array[opts[:i]] || []).join
160
+ (_pry_.input_ring[opts[:i]] || []).join
160
161
  when Integer
161
- _pry_.input_array[opts[:i]] || ""
162
+ _pry_.input_ring[opts[:i]] || ""
162
163
  else
163
164
  raise Pry::CommandError, "Not a valid range: #{opts[:i]}"
164
165
  end
@@ -172,7 +173,7 @@ class Pry
172
173
  opts.present?(:'no-reload') || _pry_.config.disable_auto_reload
173
174
  end
174
175
 
175
- def reload?(file_name="")
176
+ def reload?(file_name = "")
176
177
  (reloadable? || file_name.end_with?(".rb")) && !never_reload?
177
178
  end
178
179
 
@@ -185,7 +186,7 @@ class Pry
185
186
  when eval_string.strip != ""
186
187
  eval_string
187
188
  else
188
- _pry_.input_array.reverse_each.find { |x| x && x.strip != "" } || ""
189
+ _pry_.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || ""
189
190
  end
190
191
  end
191
192