pry 0.14.2 → 0.15.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6d8bac7565d29bff46039481c17aa6a88fec28084916dd8dad12cd4e83b146c1
4
- data.tar.gz: 90b46a979aaac6d01ddf589217baca57bc2d7ce8197c8f27bc22f823eeaffcdd
3
+ metadata.gz: e614551c579377a965416df68c4e2a90f0e0e6731d78010f7a570d4b730cfb2a
4
+ data.tar.gz: 86ed82a2dc55f826d38ae2a20f22929dbbf11b7f5d79dcfc0740a20f6779ca01
5
5
  SHA512:
6
- metadata.gz: 2e671cca56deb75c1c47ba9108155bec171ebe34d5ba740b3dd7ea3e848fc789291111e40b7c604835b3d90209873a4a3364ec72a5f4c0f062dea98e5b466a30
7
- data.tar.gz: f4c80ad6f3187823c18e1fff35306fc1e0a0ee4045a06b190f4742c92099b89d7ef5bafcb1c1dd68c8ae09b251a9a9b64bfd33179c2a7778f3122c90d636afa5
6
+ metadata.gz: 902a35c83b2b00518504054939ab688f883ecf78f2358f90462a6b06290a80de7c52735d4d71e40e27e1d47914fd7bac6b537bdf916a322d7da35483b21afef9
7
+ data.tar.gz: b03f296f12ed93fb92e7b6f7243f250cc4ada6c08b70e52a5b8df81c6707aa9c3124d60b03e0e922b5626b543c59059c7300e626858b59706140df7cd19d9fb8
data/CHANGELOG.md CHANGED
@@ -1,4 +1,39 @@
1
- ### master
1
+ ### [v0.15.0][v0.15.0] (November 15, 2024)
2
+
3
+ #### Features
4
+
5
+ * Added support for Reline
6
+ ([#2298](https://github.com/pry/pry/pull/2298))
7
+ * Added support for Ruby 3.3
8
+ ([#2295](https://github.com/pry/pry/pull/2295))
9
+ * Added Pry::Input::SimpleStdio for dumb terminals when Reline is in use
10
+ ([#2304](https://github.com/pry/pry/pull/2304))
11
+ * Remove OpenStruct usage
12
+ ([#2307](https://github.com/pry/pry/pull/2307))
13
+ ([#2309](https://github.com/pry/pry/pull/2309))
14
+ * Disable coloring of output when NO_COLOR is set.
15
+ ([#2323])(https://github.com/pry/pry/pull/2323))
16
+ * Add `pry --no-multiline` flag to keep single line prompt.
17
+ ([#2327](https://github.com/pry/pry/pull/2327))
18
+
19
+ #### Bug Fixes
20
+
21
+ * Fix typos on docs and and comments
22
+ ([#2300](https://github.com/pry/pry/pull/2300))
23
+ ([#2301](https://github.com/pry/pry/pull/2301))
24
+ * Fix 'calling clear method' on user code when defined in pry context.
25
+ ([#2291](https://github.com/pry/pry/pull/2291))
26
+ * Fix arguments WatchExpression#add_expression
27
+ ([#2278](https://github.com/pry/pry/pull/2278))
28
+
29
+ ### Breaking changes
30
+
31
+ * Remove support for deprecated `Pry.config.prompt = [proc {}, proc {}]`
32
+ Use Pry::Prompt API instead
33
+ ([#2308](https://github.com/pry/pry/pull/2308))
34
+ * Remove deprecated `Pry.config.exception_whitelist`.
35
+ Use `Pry.config.unrescued_exceptions` instead.
36
+ ([#2326](https://github.com/pry/pry/pull/2326))
2
37
 
3
38
  ### [v0.14.2][v0.14.2] (January 9, 2023)
4
39
 
@@ -977,7 +1012,7 @@ complete CHANGELOG:
977
1012
  * _pry_ now passed as 3rd parameter to :before_session hook
978
1013
  * ls colors now configurable via Pry.config.ls.local_var_color = :bright_red etc
979
1014
  * ls separator configurable via, e.g Pry.config.ls.separator = " "
980
- * Pry.view_clip() now only calls inspect on a few immediates, otherwise uses the #<> syntax, which has been truncated further to exclude teh mem address, again related to #245
1015
+ * Pry.view_clip() now only calls inspect on a few immediates, otherwise uses the #<> syntax, which has been truncated further to exclude the mem address, again related to #245
981
1016
 
982
1017
  ### 0.9.3 (2011/7/27)
983
1018
  * cat --ex (cats 5 lines above and below line in file where exception was raised)
data/README.md CHANGED
@@ -81,7 +81,7 @@ Installation
81
81
  ### Bundler
82
82
 
83
83
  ```ruby
84
- gem 'pry', '~> 0.13.1'
84
+ gem 'pry', '~> 0.15.0'
85
85
  ```
86
86
 
87
87
  ### Manual
@@ -413,18 +413,21 @@ description if the `--help` option is available.
413
413
 
414
414
  ### Use Pry as your Rails Console
415
415
 
416
- The recommended way to use Pry as your Rails console is to add [the `pry-rails`
417
- gem](https://github.com/rweng/pry-rails) to your Gemfile. This replaces the
418
- default console with Pry, in addition to loading the Rails console helpers and
419
- adding some useful Rails-specific commands.
420
-
421
- If you don't want to change your Gemfile, you can still run a Pry console in
422
- your app's environment using Pry's `-r` flag:
416
+ You can run a Pry console in your app's environment using Pry's `-r` flag:
423
417
 
424
418
  ```sh
425
419
  pry -r ./config/environment
426
420
  ```
427
421
 
422
+ Or start the rails console (`bin/rails console`) and then type `pry`.
423
+
424
+ It's also possible to use Pry as your Rails console by adding [the pry-rails
425
+ gem](https://github.com/pry/pry-rails) to your Gemfile. This replaces the
426
+ default console with Pry, in addition to loading the Rails console helpers and
427
+ adding some useful Rails-specific commands.
428
+
429
+ **Note that `pry-rails` is not currently maintained.**
430
+
428
431
  Also check out the
429
432
  [wiki](https://github.com/pry/pry/wiki/Setting-up-Rails-or-Heroku-to-use-Pry)
430
433
  for more information about integrating Pry with Rails.
@@ -137,7 +137,7 @@ class Pry
137
137
  # end
138
138
  # end
139
139
  #
140
- # @example Define the invokation block anywhere you want
140
+ # @example Define the invocation block anywhere you want
141
141
  # def subcommands(cmd)
142
142
  # cmd.command :download do |opt|
143
143
  # description 'Downloads a content from a server'
@@ -172,7 +172,7 @@ class Pry
172
172
 
173
173
  # The actual body of your command should go here.
174
174
  #
175
- # The `opts` mehod can be called to get the options that Pry::Slop has passed,
175
+ # The `opts` method can be called to get the options that Pry::Slop has passed,
176
176
  # and `args` gives the remaining, unparsed arguments.
177
177
  #
178
178
  # The return value of this method is discarded unless the command was
data/lib/pry/cli.rb CHANGED
@@ -145,6 +145,10 @@ Pry::CLI.add_options do
145
145
  Pry.config.color = false
146
146
  end
147
147
 
148
+ on "no-multiline", "Disables multiline (defaults to true with Reline)" do
149
+ Pry.config.multiline = false
150
+ end
151
+
148
152
  on :f, "Suppress loading of pryrc" do
149
153
  Pry.config.should_load_rc = false
150
154
  Pry.config.should_load_local_rc = false
@@ -11,7 +11,7 @@ class Pry
11
11
  # object the user wants (applying precedence rules in doing so -- i.e methods
12
12
  # get precedence over commands with the same name) and 2. Returning
13
13
  # the appropriate object. If the user fails to provide a string
14
- # identifer for the object (i.e they pass in `nil` or "") then the
14
+ # identifier for the object (i.e they pass in `nil` or "") then the
15
15
  # object looked up will be the 'current method' or 'current class'
16
16
  # associated with the Binding.
17
17
  #
@@ -97,7 +97,7 @@ class Pry
97
97
  nil
98
98
  end
99
99
 
100
- # when no paramter is given (i.e CodeObject.lookup(nil)), then we
100
+ # when no parameter is given (i.e CodeObject.lookup(nil)), then we
101
101
  # lookup the 'current object' from the binding.
102
102
  def empty_lookup
103
103
  return nil if str && !str.empty?
data/lib/pry/command.rb CHANGED
@@ -200,7 +200,7 @@ class Pry
200
200
  end
201
201
 
202
202
  def state
203
- Pry::CommandState.default.state_for(match)
203
+ Pry::CommandState.default.state_for(self)
204
204
  end
205
205
  end
206
206
 
@@ -145,7 +145,7 @@ class Pry
145
145
  # Imports all the commands from one or more sets.
146
146
  # @param [Array<CommandSet>] sets Command sets, all of the commands of which
147
147
  # will be imported.
148
- # @return [Pry::CommandSet] Returns the reciever (a command set).
148
+ # @return [Pry::CommandSet] Returns the receiver (a command set).
149
149
  def import(*sets)
150
150
  sets.each do |set|
151
151
  @commands.merge! set.to_hash
@@ -157,7 +157,7 @@ class Pry
157
157
  # Imports some commands from a set
158
158
  # @param [CommandSet] set Set to import commands from
159
159
  # @param [Array<String>] matches Commands to import
160
- # @return [Pry::CommandSet] Returns the reciever (a command set).
160
+ # @return [Pry::CommandSet] Returns the receiver (a command set).
161
161
  def import_from(set, *matches)
162
162
  helper_module.send :include, set.helper_module
163
163
  matches.each do |match|
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
-
5
3
  class Pry
6
4
  # CommandState is a data structure to hold per-command state.
7
5
  #
@@ -20,12 +18,19 @@ class Pry
20
18
  @command_state = {}
21
19
  end
22
20
 
23
- def state_for(command_name)
24
- @command_state[command_name] ||= OpenStruct.new
21
+ def state_for(command_class)
22
+ @command_state[command_class] ||= command_struct(command_class)
23
+ end
24
+
25
+ def reset(command_class)
26
+ @command_state[command_class] = command_struct(command_class)
25
27
  end
26
28
 
27
- def reset(command_name)
28
- @command_state[command_name] = OpenStruct.new
29
+ private
30
+
31
+ def command_struct(command_class)
32
+ Struct.new(:command, *command_class.command_options[:state])
33
+ .new(command: command_class)
29
34
  end
30
35
  end
31
36
  end
@@ -76,7 +76,7 @@ class Pry
76
76
 
77
77
  # Takes two numbers that are 1-indexed, and returns a range (or
78
78
  # number) that is 0-indexed. 1-indexed means the first element is
79
- # indentified by 1 rather than by 0 (as is the case for Ruby arrays).
79
+ # identified by 1 rather than by 0 (as is the case for Ruby arrays).
80
80
  # @param [Fixnum] start_line_number One-indexed number.
81
81
  # @param [Fixnum] end_line_number One-indexed number.
82
82
  # @return [Range] The zero-indexed range.
@@ -22,6 +22,8 @@ class Pry
22
22
  https://github.com/pry/pry/wiki/State-navigation#wiki-Changing_scope
23
23
  BANNER
24
24
 
25
+ command_options state: %i[old_stack]
26
+
25
27
  def process
26
28
  state.old_stack ||= []
27
29
 
@@ -22,6 +22,8 @@ class Pry
22
22
  https://github.com/pry/pry/wiki/Editor-integration#wiki-Edit_command
23
23
  BANNER
24
24
 
25
+ command_options state: %i[dynamical_ex_file]
26
+
25
27
  def options(opt)
26
28
  opt.on :e, :ex, "Open the file that raised the most recent exception " \
27
29
  "(_ex_.file)",
@@ -128,7 +128,7 @@ class Pry
128
128
  next if klass.autoload?(name)
129
129
 
130
130
  begin
131
- const = klass.const_get(name)
131
+ const = Pry::Method.singleton_class_of(klass.const_get(name))
132
132
  rescue RescuableException # rubocop:disable Lint/HandleExceptions
133
133
  # constant loading is an inexact science at the best of times,
134
134
  # this often happens when a constant was .autoload? but someone
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ class Command
5
+ class Ls < Pry::ClassCommand
6
+ class Config
7
+ attr_accessor :heading_color,
8
+ :public_method_color,
9
+ :private_method_color,
10
+ :protected_method_color,
11
+ :method_missing_color,
12
+ :local_var_color,
13
+ :pry_var_color, # e.g. _, pry_instance, _file_
14
+ :instance_var_color, # e.g. @foo
15
+ :class_var_color, # e.g. @@foo
16
+ :global_var_color, # e.g. $CODERAY_DEBUG, $foo
17
+ :builtin_global_color, # e.g. $stdin, $-w, $PID
18
+ :pseudo_global_color, # e.g. $~, $1..$9, $LAST_MATCH_INFO
19
+ :constant_color, # e.g. VERSION, ARGF
20
+ :class_constant_color, # e.g. Object, Kernel
21
+ :exception_constant_color, # e.g. Exception, RuntimeError
22
+ :unloaded_constant_color, # Constant that is still in .autoload?
23
+ :separator,
24
+ :ceiling
25
+
26
+ def self.default
27
+ config = new
28
+ config.heading_color = :bright_blue
29
+ config.public_method_color = :default
30
+ config.private_method_color = :blue
31
+ config.protected_method_color = :blue
32
+ config.method_missing_color = :bright_red
33
+ config.local_var_color = :yellow
34
+ config.pry_var_color = :default
35
+ config.instance_var_color = :blue
36
+ config.class_var_color = :bright_blue
37
+ config.global_var_color = :default
38
+ config.builtin_global_color = :cyan
39
+ config.pseudo_global_color = :cyan
40
+ config.constant_color = :default
41
+ config.class_constant_color = :blue
42
+ config.exception_constant_color = :magenta
43
+ config.unloaded_constant_color = :yellow
44
+ config.separator = " "
45
+ config.ceiling = [Object, Module, Class]
46
+ config
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -3,27 +3,6 @@
3
3
  class Pry
4
4
  class Command
5
5
  class Ls < Pry::ClassCommand
6
- DEFAULT_OPTIONS = {
7
- heading_color: :bright_blue,
8
- public_method_color: :default,
9
- private_method_color: :blue,
10
- protected_method_color: :blue,
11
- method_missing_color: :bright_red,
12
- local_var_color: :yellow,
13
- pry_var_color: :default, # e.g. _, pry_instance, _file_
14
- instance_var_color: :blue, # e.g. @foo
15
- class_var_color: :bright_blue, # e.g. @@foo
16
- global_var_color: :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
17
- builtin_global_color: :cyan, # e.g. $stdin, $-w, $PID
18
- pseudo_global_color: :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
19
- constant_color: :default, # e.g. VERSION, ARGF
20
- class_constant_color: :blue, # e.g. Object, Kernel
21
- exception_constant_color: :magenta, # e.g. Exception, RuntimeError
22
- unloaded_constant_color: :yellow, # Any constant that is still in .autoload? state
23
- separator: " ",
24
- ceiling: [Object, Module, Class]
25
- }.freeze
26
-
27
6
  match 'ls'
28
7
  group 'Context'
29
8
  description 'Show the list of vars and methods in the current scope.'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Pry
4
- # N.B. using a regular expresion here so that "raise-up 'foo'" does the right thing.
4
+ # N.B. using a regular expression here so that "raise-up 'foo'" does the right thing.
5
5
  class Command
6
6
  class RaiseUp < Pry::ClassCommand
7
7
  match(/raise-up(!?\b.*)/)
@@ -57,7 +57,7 @@ class Pry
57
57
  RDoc::RI.const_set :PryDriver, subclass # hook it up!
58
58
  end
59
59
 
60
- # Spin-up an RI insance.
60
+ # Spin-up an RI instance.
61
61
  ri = RDoc::RI::PryDriver.new(
62
62
  pry_instance.pager, use_stdout: true, interactive: false
63
63
  )
@@ -7,7 +7,7 @@ class Pry
7
7
  group 'Input and Output'
8
8
  description "All text following a '.' is forwarded to the shell."
9
9
  command_options listing: '.<shell command>', use_prefix: false,
10
- takes_block: true
10
+ takes_block: true, state: %i[old_pwd]
11
11
 
12
12
  banner <<-'BANNER'
13
13
  Usage: .COMMAND_NAME
@@ -6,6 +6,7 @@ class Pry
6
6
  match 'shell-mode'
7
7
  group 'Input and Output'
8
8
  description 'Toggle shell mode. Bring in pwd prompt and file completion.'
9
+ command_options state: %i[disabled prev_prompt]
9
10
 
10
11
  banner <<-'BANNER'
11
12
  Toggle shell mode. Bring in pwd prompt and file completion.
@@ -23,7 +23,7 @@ class Pry
23
23
 
24
24
  # Has the value of the expression changed?
25
25
  #
26
- # We use the pretty-printed string represenation to detect differences
26
+ # We use the pretty-printed string representation to detect differences
27
27
  # as this avoids problems with dup (causes too many differences) and ==
28
28
  # (causes too few)
29
29
  def changed?
@@ -7,7 +7,7 @@ class Pry
7
7
  group 'Context'
8
8
  description 'Watch the value of an expression and print a notification ' \
9
9
  'whenever it changes.'
10
- command_options use_prefix: false
10
+ command_options use_prefix: false, state: %i[watch_expressions]
11
11
 
12
12
  banner <<-'BANNER'
13
13
  Usage: watch [EXPRESSION]
@@ -46,7 +46,7 @@ class Pry
46
46
  list
47
47
  else
48
48
  add_hook
49
- add_expression(args)
49
+ add_expression
50
50
  end
51
51
  end
52
52
 
@@ -88,9 +88,7 @@ class Pry
88
88
  end
89
89
  end
90
90
 
91
- # TODO: fix arguments.
92
- # https://github.com/pry/pry/commit/b031df2f2f5850ee6e9018f33d35f3485a9b0423
93
- def add_expression(_arguments)
91
+ def add_expression
94
92
  expressions << Expression.new(pry_instance, target, arg_string)
95
93
  output.puts "Watching #{Code.new(arg_string).highlighted}"
96
94
  end
data/lib/pry/config.rb CHANGED
@@ -1,13 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'ostruct'
4
-
5
3
  class Pry
6
4
  # @api private
7
5
  class Config
8
6
  extend Attributable
9
7
 
10
- # @return [IO, #readline] he object from which Pry retrieves its lines of
8
+ # @return [IO, #readline] the object from which Pry retrieves its lines of
11
9
  # input
12
10
  attribute :input
13
11
 
@@ -26,10 +24,6 @@ class Pry
26
24
  # @return [Array] Exception that Pry shouldn't rescue
27
25
  attribute :unrescued_exceptions
28
26
 
29
- # @deprecated
30
- # @return [Array] Exception that Pry shouldn't rescue
31
- attribute :exception_whitelist
32
-
33
27
  # @return [Integer] The number of lines of context to show before and after
34
28
  # exceptions
35
29
  attribute :default_window_size
@@ -67,6 +61,9 @@ class Pry
67
61
  # @return [Boolean]
68
62
  attribute :pager
69
63
 
64
+ # @return [Boolean]
65
+ attribute :multiline
66
+
70
67
  # @return [Boolean] whether the global ~/.pryrc should be loaded
71
68
  attribute :should_load_rc
72
69
 
@@ -153,7 +150,7 @@ class Pry
153
150
 
154
151
  def initialize
155
152
  merge!(
156
- input: MemoizedValue.new { lazy_readline },
153
+ input: MemoizedValue.new { choose_input },
157
154
  output: $stdout.tap { |out| out.sync = true },
158
155
  commands: Pry::Commands,
159
156
  prompt_name: 'pry',
@@ -167,17 +164,10 @@ class Pry
167
164
  ::SystemExit, ::SignalException, Pry::TooSafeException
168
165
  ],
169
166
 
170
- exception_whitelist: MemoizedValue.new do
171
- output.puts(
172
- '[warning] Pry.config.exception_whitelist is deprecated, ' \
173
- 'please use Pry.config.unrescued_exceptions instead.'
174
- )
175
- unrescued_exceptions
176
- end,
177
-
178
167
  hooks: Pry::Hooks.default,
179
168
  pager: true,
180
169
  system: Pry::SystemCommandHandler.method(:default),
170
+ multiline: true,
181
171
  color: Pry::Helpers::BaseHelpers.use_ansi_codes?,
182
172
  default_window_size: 5,
183
173
  editor: Pry::Editor.default,
@@ -199,7 +189,7 @@ class Pry
199
189
  extra_sticky_locals: {},
200
190
  command_completions: proc { commands.keys },
201
191
  file_completions: proc { Dir['.'] },
202
- ls: OpenStruct.new(Pry::Command::Ls::DEFAULT_OPTIONS),
192
+ ls: Pry::Command::Ls::Config.default,
203
193
  completer: Pry::InputCompleter,
204
194
  history_save: true,
205
195
  history_load: true,
@@ -286,7 +276,17 @@ class Pry
286
276
 
287
277
  private
288
278
 
289
- def lazy_readline
279
+ def choose_input
280
+ input = load_readline
281
+
282
+ if Pry::Env['TERM'] == 'dumb' && (defined?(Reline) && input == Reline)
283
+ input = Pry::Input::SimpleStdio
284
+ end
285
+
286
+ input
287
+ end
288
+
289
+ def load_readline
290
290
  require 'readline'
291
291
  ::Readline
292
292
  rescue LoadError
@@ -19,7 +19,7 @@ class Pry
19
19
  else
20
20
  # Otherwise, saves current binding stack as old stack and pops last
21
21
  # binding out of binding stack (the old stack still has that binding).
22
- cd_state = Pry::CommandState.default.state_for('cd')
22
+ cd_state = Pry::CommandState.default.state_for(Pry::Command::Cd)
23
23
  cd_state.old_stack = pry_instance.binding_stack.dup
24
24
  pry_instance.binding_stack.pop
25
25
  end
@@ -30,8 +30,13 @@ class Pry
30
30
  end
31
31
 
32
32
  def exception_text(exception)
33
- "#{exception.class}: #{exception.message}\n" \
34
- "from #{exception.backtrace.first}\n"
33
+ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2')
34
+ "#{exception.class}: #{exception.message}\n" \
35
+ "from #{exception.backtrace.first}\n"
36
+ else
37
+ "#{exception.class}: #{exception.detailed_message}\n" \
38
+ "from #{exception.backtrace.first}\n"
39
+ end
35
40
  end
36
41
 
37
42
  def cause_text(cause)
@@ -70,7 +70,7 @@ class Pry
70
70
 
71
71
  # Find the longest common whitespace to all indented lines. Ignore lines
72
72
  # containing just -- or ++ as these seem to be used by comment authors
73
- # as delimeters.
73
+ # as delimiters.
74
74
  scanned_text = text.scan(/^[ \t]*(?!--\n|\+\+\n)(?=[^ \t\n])/)
75
75
  margin = scanned_text.inject do |current_margin, next_indent|
76
76
  if next_indent.start_with?(current_margin)
data/lib/pry/indent.rb CHANGED
@@ -17,6 +17,9 @@ class Pry
17
17
  # @return [String] String containing the spaces to be inserted before the next line.
18
18
  attr_reader :indent_level
19
19
 
20
+ # @return [String] String containing the spaces for the current line.
21
+ attr_reader :last_indent_level
22
+
20
23
  # @return [Array<String>] The stack of open tokens.
21
24
  attr_reader :stack
22
25
 
@@ -110,6 +113,7 @@ class Pry
110
113
  def reset
111
114
  @stack = []
112
115
  @indent_level = String.new # rubocop:disable Style/EmptyLiteral
116
+ @last_indent_level = @indent_level
113
117
  @heredoc_queue = []
114
118
  @close_heredocs = {}
115
119
  @string_start = nil
@@ -164,11 +168,11 @@ class Pry
164
168
 
165
169
  output += line
166
170
 
171
+ @last_indent_level = prefix
167
172
  prefix = new_prefix
168
173
  end
169
174
 
170
175
  @indent_level = prefix
171
-
172
176
  output
173
177
  end
174
178
 
@@ -281,9 +285,7 @@ class Pry
281
285
  # @param [String] string The Ruby to lex
282
286
  # @return [Array] An Array of pairs of [token_value, token_type]
283
287
  def tokenize(string)
284
- tokens = SyntaxHighlighter.tokenize(string)
285
- tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens) # Coderay 1.0.0
286
- tokens.to_a
288
+ SyntaxHighlighter.tokenize(string).each_slice(2).to_a
287
289
  end
288
290
 
289
291
  # Update the internal state about what kind of strings are open.
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Pry
4
+ module Input
5
+ # Readline replacement for low-capability terminals.
6
+ class SimpleStdio
7
+ def self.readline(prompt)
8
+ Pry.config.output.print(prompt)
9
+ $stdin.gets
10
+ end
11
+ end
12
+ end
13
+ end
@@ -234,7 +234,7 @@ class Pry
234
234
  end.compact
235
235
  end
236
236
 
237
- # build_path seperates the input into two parts: path and input.
237
+ # build_path separates the input into two parts: path and input.
238
238
  # input is the partial string that should be completed
239
239
  # path is a proc that takes an input and builds a full path.
240
240
  def build_path(input)
@@ -43,7 +43,7 @@ class Pry
43
43
  #
44
44
  # When we're redefining aliased methods we will overwrite the method at the
45
45
  # unaliased name (so that super continues to work). By wrapping that code in a
46
- # transation we make that not happen, which means that alias_method_chains, etc.
46
+ # translation we make that not happen, which means that alias_method_chains, etc.
47
47
  # continue to work.
48
48
  #
49
49
  def with_method_transaction
@@ -95,7 +95,7 @@ class Pry
95
95
  # Update the source code so that when it has the right owner when eval'd.
96
96
  #
97
97
  # This (combined with definition_for_owner) is backup for the case that
98
- # wrap_for_nesting fails, to ensure that the method will stil be defined in
98
+ # wrap_for_nesting fails, to ensure that the method will still be defined in
99
99
  # the correct place.
100
100
  #
101
101
  # @param [String] source The source to wrap
@@ -123,7 +123,7 @@ class Pry
123
123
  # know which __FILE__ and __LINE__ the binding is at, we can hope to
124
124
  # disambiguate these cases.
125
125
  #
126
- # This obviously won't work if the source is unavaiable for some reason,
126
+ # This obviously won't work if the source is unavailable for some reason,
127
127
  # or if both methods have the same __FILE__ and __LINE__.
128
128
  #
129
129
  # @return [Pry::Method, nil] The Pry::Method representing the
data/lib/pry/method.rb CHANGED
@@ -564,8 +564,7 @@ class Pry
564
564
  def method_name_from_first_line(first_ln)
565
565
  return nil if first_ln.strip !~ /^def /
566
566
 
567
- tokens = SyntaxHighlighter.tokenize(first_ln)
568
- tokens = tokens.tokens.each_slice(2) if tokens.respond_to?(:tokens)
567
+ tokens = SyntaxHighlighter.tokenize(first_ln).each_slice(2)
569
568
  tokens.each_cons(2) do |t1, t2|
570
569
  if t2.last == :method || t2.last == :ident && t1 == [".", :operator]
571
570
  return t2.first
data/lib/pry/pry_class.rb CHANGED
@@ -161,6 +161,8 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
161
161
 
162
162
  options = options.to_hash
163
163
 
164
+ options[:color] = false if Pry::Env['NO_COLOR']
165
+
164
166
  if in_critical_section?
165
167
  output.puts "ERROR: Pry started inside Pry."
166
168
  output.puts "This can happen if you have a binding.pry inside a #to_s " \
@@ -215,7 +217,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc.
215
217
  # The maximum number of chars before clipping occurs.
216
218
  #
217
219
  # @option options [Boolean] :id (false)
218
- # Boolean to indicate whether or not a hex reprsentation of the object ID
220
+ # Boolean to indicate whether or not a hex representation of the object ID
219
221
  # is attached to the return value when the length of inspect is greater than
220
222
  # value of `:max_length`.
221
223
  #
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'method_source'
4
- require 'ostruct'
5
4
 
6
5
  ##
7
6
  # Pry is a powerful alternative to the standard IRB shell for Ruby. It
@@ -93,7 +92,6 @@ class Pry
93
92
  @input_ring << nil
94
93
  push_initial_binding(target)
95
94
  exec_hook(:when_started, target, options, self)
96
- @prompt_warn = false
97
95
  end
98
96
 
99
97
  # This is the prompt at the top of the prompt stack.
@@ -388,7 +386,7 @@ class Pry
388
386
  # @param [*Object] args The arguments to pass to the hook
389
387
  # @return [Object, Exception] The return value of the hook or the exception raised
390
388
  #
391
- # If executing a hook raises an exception, we log that and then continue sucessfully.
389
+ # If executing a hook raises an exception, we log that and then continue successfully.
392
390
  # To debug such errors, use the global variable $pry_hook_error, which is set as a
393
391
  # result.
394
392
  def exec_hook(name, *args, &block)
@@ -452,45 +450,17 @@ class Pry
452
450
  # @return [String] The prompt.
453
451
  def select_prompt
454
452
  object = current_binding.eval('self')
455
- open_token = @indent.open_delimiters.last || @indent.stack.last
456
-
457
- c = OpenStruct.new(
458
- object: object,
459
- nesting_level: binding_stack.size - 1,
460
- open_token: open_token,
461
- session_line: Pry.history.session_line_count + 1,
462
- history_line: Pry.history.history_line_count + 1,
463
- expr_number: input_ring.count,
464
- pry_instance: self,
465
- binding_stack: binding_stack,
466
- input_ring: input_ring,
467
- eval_string: @eval_string,
468
- cont: !@eval_string.empty?
469
- )
453
+ nesting_level = binding_stack.size - 1
454
+ pry_instance = self
470
455
 
471
456
  Pry.critical_section do
472
457
  # If input buffer is empty, then use normal prompt. Otherwise use the wait
473
458
  # prompt (indicating multi-line expression).
474
459
  if prompt.is_a?(Pry::Prompt)
475
460
  prompt_proc = eval_string.empty? ? prompt.wait_proc : prompt.incomplete_proc
476
- return prompt_proc.call(c.object, c.nesting_level, c.pry_instance)
477
- end
478
-
479
- unless @prompt_warn
480
- @prompt_warn = true
481
- Kernel.warn(
482
- "warning: setting prompt with help of " \
483
- "`Pry.config.prompt = [proc {}, proc {}]` is deprecated. " \
484
- "Use Pry::Prompt API instead"
485
- )
486
- end
487
-
488
- # If input buffer is empty then use normal prompt
489
- if eval_string.empty?
490
- generate_prompt(Array(prompt).first, c)
491
- # Otherwise use the wait prompt (indicating multi-line expression)
461
+ return prompt_proc.call(object, nesting_level, pry_instance)
492
462
  else
493
- generate_prompt(Array(prompt).last, c)
463
+ output.puts "ERROR: Use Pry::Prompt API."
494
464
  end
495
465
  end
496
466
  end
@@ -549,7 +519,7 @@ class Pry
549
519
  # and a mistake in specifying that exception.
550
520
  #
551
521
  # (i.e. raise-up RunThymeError.new should not be the same as
552
- # raise-up NameError, "unititialized constant RunThymeError")
522
+ # raise-up NameError, "uninitialized constant RunThymeError")
553
523
  #
554
524
  def raise_up_common(force, *args)
555
525
  exception = if args == []
@@ -685,14 +655,6 @@ class Pry
685
655
  end
686
656
  end
687
657
 
688
- def generate_prompt(prompt_proc, conf)
689
- if prompt_proc.arity == 1
690
- prompt_proc.call(conf)
691
- else
692
- prompt_proc.call(conf.object, conf.nesting_level, conf.pry_instance)
693
- end
694
- end
695
-
696
658
  # the array that the prompt stack is stored in
697
659
  def prompt_stack
698
660
  @prompt_stack ||= []
data/lib/pry/repl.rb CHANGED
@@ -100,7 +100,7 @@ class Pry
100
100
  # Return nil for EOF, :no_more_input for error, or :control_c for <Ctrl-C>
101
101
  return val unless val.is_a?(String)
102
102
 
103
- if pry.config.auto_indent
103
+ if pry.config.auto_indent && !input_multiline?
104
104
  original_val = "#{indentation}#{val}"
105
105
  indented_val = @indent.indent(val)
106
106
 
@@ -179,7 +179,31 @@ class Pry
179
179
  end
180
180
  end
181
181
 
182
- if readline_available?
182
+ if reline_available?
183
+ Reline.output_modifier_proc = lambda do |text, _|
184
+ if pry.color
185
+ SyntaxHighlighter.highlight(text)
186
+ else
187
+ text
188
+ end
189
+ end
190
+
191
+ if pry.config.auto_indent
192
+ Reline.auto_indent_proc = lambda do |lines, line_index, _byte_ptr, _newline|
193
+ if line_index == 0
194
+ 0
195
+ else
196
+ pry_indentation = Pry::Indent.new
197
+ pry_indentation.indent(lines.join("\n"))
198
+ pry_indentation.last_indent_level.length
199
+ end
200
+ end
201
+ end
202
+ end
203
+
204
+ if input_multiline?
205
+ input_readmultiline(current_prompt, false)
206
+ elsif readline_available?
183
207
  set_readline_output
184
208
  input_readline(current_prompt, false) # false since we'll add it manually
185
209
  elsif coolline_available?
@@ -192,12 +216,29 @@ class Pry
192
216
  end
193
217
  end
194
218
 
219
+ def input_readmultiline(*args)
220
+ Pry::InputLock.for(:all).interruptible_region do
221
+ input.readmultiline(*args) do |multiline_input|
222
+ Pry.commands.find_command(multiline_input) ||
223
+ (complete_expression?(multiline_input) && !Reline::IOGate.in_pasting?)
224
+ end
225
+ end
226
+ end
227
+
195
228
  def input_readline(*args)
196
229
  Pry::InputLock.for(:all).interruptible_region do
197
230
  input.readline(*args)
198
231
  end
199
232
  end
200
233
 
234
+ def input_multiline?
235
+ !!pry.config.multiline && reline_available?
236
+ end
237
+
238
+ def reline_available?
239
+ defined?(Reline) && input == Reline
240
+ end
241
+
201
242
  def readline_available?
202
243
  defined?(Readline) && input == Readline
203
244
  end
@@ -206,6 +247,13 @@ class Pry
206
247
  defined?(Coolline) && input.is_a?(Coolline)
207
248
  end
208
249
 
250
+ def prism_available?
251
+ require 'prism'
252
+
253
+ @prism_available ||= defined?(Prism) &&
254
+ Gem::Version.new(Prism::VERSION) >= Gem::Version.new('0.25.0')
255
+ end
256
+
209
257
  # If `$stdout` is not a tty, it's probably a pipe.
210
258
  # @example
211
259
  # # `piping?` returns `false`
@@ -227,6 +275,21 @@ class Pry
227
275
  @readline_output = (Readline.output = Pry.config.output) if piping?
228
276
  end
229
277
 
278
+ UNEXPECTED_TOKENS = %i[unexpected_token_ignore lambda_open].freeze
279
+
280
+ def complete_expression?(multiline_input)
281
+ if prism_available?
282
+ lex = Prism.lex(multiline_input)
283
+
284
+ errors = lex.errors
285
+ return true if errors.empty?
286
+
287
+ errors.any? { |error| UNEXPECTED_TOKENS.include?(error.type) }
288
+ else
289
+ Pry::Code.complete_expression?(multiline_input)
290
+ end
291
+ end
292
+
230
293
  # Calculates correct overhang for current line. Supports vi Readline
231
294
  # mode and its indicators such as "(ins)" or "(cmd)".
232
295
  #
data/lib/pry/ring.rb CHANGED
@@ -3,7 +3,7 @@
3
3
  class Pry
4
4
  # A ring is a thread-safe fixed-capacity array to which you can only add
5
5
  # elements. Older entries are overwritten as you add new elements, so that the
6
- # ring can never contain more than `max_size` elemens.
6
+ # ring can never contain more than `max_size` elements.
7
7
  #
8
8
  # @example
9
9
  # ring = Pry::Ring.new(3)
data/lib/pry/slop.rb CHANGED
@@ -73,7 +73,7 @@ class Pry
73
73
  # Build a Slop object from a option specification.
74
74
  #
75
75
  # This allows you to design your options via a simple String rather
76
- # than programatically. Do note though that with this method, you're
76
+ # than programmatically. Do note though that with this method, you're
77
77
  # unable to pass any advanced options to the on() method when creating
78
78
  # options.
79
79
  #
@@ -11,7 +11,7 @@ class Pry
11
11
  end
12
12
 
13
13
  def self.tokenize(code, language = :ruby)
14
- CodeRay.scan(code, language)
14
+ CodeRay::Scanners[language].new(code).tokens
15
15
  end
16
16
 
17
17
  def self.keyword_token_color
data/lib/pry/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Pry
4
- VERSION = '0.14.2'.freeze
4
+ VERSION = '0.15.0'.freeze
5
5
  end
@@ -286,7 +286,7 @@ class Pry
286
286
  # highest rank, that is the 'monkey patch' of this module with the
287
287
  # highest number of methods, which contains a source code line that
288
288
  # defines the module. It is considered the 'canonical' definition
289
- # for the module. In the absense of a suitable candidate, the
289
+ # for the module. In the absence of a suitable candidate, the
290
290
  # candidate of rank 0 will be returned, or a CommandError raised if
291
291
  # there are no candidates at all.
292
292
  def primary_candidate
data/lib/pry.rb CHANGED
@@ -34,6 +34,7 @@ require 'pry/env'
34
34
 
35
35
  Pry::Commands = Pry::CommandSet.new unless defined?(Pry::Commands)
36
36
 
37
+ require 'pry/commands/ls/config'
37
38
  require 'pry/commands/ls/jruby_hacks'
38
39
  require 'pry/commands/ls/methods_helper'
39
40
  require 'pry/commands/ls/interrogatable'
@@ -57,6 +58,8 @@ require 'pry/config/memoized_value'
57
58
  require 'pry/config/lazy_value'
58
59
  require 'pry/config'
59
60
 
61
+ require 'pry/input/simple_stdio'
62
+
60
63
  require 'pry/pry_class'
61
64
  require 'pry/pry_instance'
62
65
  require 'pry/inspector'
metadata CHANGED
@@ -1,17 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.2
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mair (banisterfiend)
8
8
  - Conrad Irwin
9
9
  - Ryan Fitzgerald
10
10
  - Kyrylo Silin
11
- autorequire:
12
11
  bindir: bin
13
12
  cert_chain: []
14
- date: 2023-01-09 00:00:00.000000000 Z
13
+ date: 2024-11-15 00:00:00.000000000 Z
15
14
  dependencies:
16
15
  - !ruby/object:Gem::Dependency
17
16
  name: coderay
@@ -102,6 +101,7 @@ files:
102
101
  - lib/pry/commands/jump_to.rb
103
102
  - lib/pry/commands/list_inspectors.rb
104
103
  - lib/pry/commands/ls.rb
104
+ - lib/pry/commands/ls/config.rb
105
105
  - lib/pry/commands/ls/constants.rb
106
106
  - lib/pry/commands/ls/formatter.rb
107
107
  - lib/pry/commands/ls/globals.rb
@@ -160,6 +160,7 @@ files:
160
160
  - lib/pry/history.rb
161
161
  - lib/pry/hooks.rb
162
162
  - lib/pry/indent.rb
163
+ - lib/pry/input/simple_stdio.rb
163
164
  - lib/pry/input_completer.rb
164
165
  - lib/pry/input_lock.rb
165
166
  - lib/pry/inspector.rb
@@ -200,7 +201,6 @@ metadata:
200
201
  changelog_uri: https://github.com/pry/pry/blob/master/CHANGELOG.md
201
202
  source_code_uri: https://github.com/pry/pry
202
203
  bug_tracker_uri: https://github.com/pry/pry/issues
203
- post_install_message:
204
204
  rdoc_options: []
205
205
  require_paths:
206
206
  - lib
@@ -215,8 +215,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
215
215
  - !ruby/object:Gem::Version
216
216
  version: '0'
217
217
  requirements: []
218
- rubygems_version: 3.4.1
219
- signing_key:
218
+ rubygems_version: 3.6.0.dev
220
219
  specification_version: 4
221
220
  summary: A runtime developer console and IRB alternative with powerful introspection
222
221
  capabilities.