pry 0.14.2-java → 0.15.1-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c806cb1e0347c6396c3b6e2e3fc7252b085693333b773efe798dfe41526a7b8c
4
- data.tar.gz: 90b46a979aaac6d01ddf589217baca57bc2d7ce8197c8f27bc22f823eeaffcdd
3
+ metadata.gz: 0d7510fb7f25427c63713eb5fa7e06a2e6237c61963fce651fd9f0624c49c0a2
4
+ data.tar.gz: a3956d43c1d5733f4e09362e0e251d3b2182cd4237bd132243d4479dbdf38efd
5
5
  SHA512:
6
- metadata.gz: a877e6636ba7840c0b433c79d72c8652a7d5b8f7c33e3273bdb78f1eb37eef6979e326d5d0fd31d6e978fb34642daf0d73b6c3d9b6dcbf91c5a8c4791182cf7c
7
- data.tar.gz: f4c80ad6f3187823c18e1fff35306fc1e0a0ee4045a06b190f4742c92099b89d7ef5bafcb1c1dd68c8ae09b251a9a9b64bfd33179c2a7778f3122c90d636afa5
6
+ metadata.gz: be8c495d8f79e3e4b5fb894688e39180bb5c9a32e7b088e98b31c5443ab65605d8a65e407ddbaabdbb202322d29d04d1c802d8f838f6079b83ec9422ca693329
7
+ data.tar.gz: ce971fc59838f97522e4653772199e46ae7b3ef9b9bacb86e40e8975a6b07652af1b7b3a76c396de2f574903041c86d9c657f847a9f194892378318717da4def
data/CHANGELOG.md CHANGED
@@ -1,4 +1,48 @@
1
- ### master
1
+ ### [v0.15.1](v0.15.1) (December 24, 2024)
2
+
3
+ #### Bug Fixes
4
+
5
+ * Restore Pry.config.ls compatibility
6
+ ([#2335](https://github.com/pry/pry/pull/2335))
7
+ * Avoid breaking reading inputs if Prism is not available
8
+ ([#2338](https://github.com/pry/pry/pull/2338))
9
+
10
+ ### [v0.15.0][v0.15.0] (November 15, 2024)
11
+
12
+ #### Features
13
+
14
+ * Added support for Reline
15
+ ([#2298](https://github.com/pry/pry/pull/2298))
16
+ * Added support for Ruby 3.3
17
+ ([#2295](https://github.com/pry/pry/pull/2295))
18
+ * Added Pry::Input::SimpleStdio for dumb terminals when Reline is in use
19
+ ([#2304](https://github.com/pry/pry/pull/2304))
20
+ * Remove OpenStruct usage
21
+ ([#2307](https://github.com/pry/pry/pull/2307))
22
+ ([#2309](https://github.com/pry/pry/pull/2309))
23
+ * Disable coloring of output when NO_COLOR is set.
24
+ ([#2323])(https://github.com/pry/pry/pull/2323))
25
+ * Add `pry --no-multiline` flag to keep single line prompt.
26
+ ([#2327](https://github.com/pry/pry/pull/2327))
27
+
28
+ #### Bug Fixes
29
+
30
+ * Fix typos on docs and and comments
31
+ ([#2300](https://github.com/pry/pry/pull/2300))
32
+ ([#2301](https://github.com/pry/pry/pull/2301))
33
+ * Fix 'calling clear method' on user code when defined in pry context.
34
+ ([#2291](https://github.com/pry/pry/pull/2291))
35
+ * Fix arguments WatchExpression#add_expression
36
+ ([#2278](https://github.com/pry/pry/pull/2278))
37
+
38
+ ### Breaking changes
39
+
40
+ * Remove support for deprecated `Pry.config.prompt = [proc {}, proc {}]`
41
+ Use Pry::Prompt API instead
42
+ ([#2308](https://github.com/pry/pry/pull/2308))
43
+ * Remove deprecated `Pry.config.exception_whitelist`.
44
+ Use `Pry.config.unrescued_exceptions` instead.
45
+ ([#2326](https://github.com/pry/pry/pull/2326))
2
46
 
3
47
  ### [v0.14.2][v0.14.2] (January 9, 2023)
4
48
 
@@ -977,7 +1021,7 @@ complete CHANGELOG:
977
1021
  * _pry_ now passed as 3rd parameter to :before_session hook
978
1022
  * ls colors now configurable via Pry.config.ls.local_var_color = :bright_red etc
979
1023
  * 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
1024
+ * 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
1025
 
982
1026
  ### 0.9.3 (2011/7/27)
983
1027
  * 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,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forwardable'
4
+
5
+ class Pry
6
+ class Command
7
+ class Ls < Pry::ClassCommand
8
+ class Config
9
+ extend Forwardable
10
+
11
+ DEFAULT_OPTIONS = {
12
+ heading_color: :bright_blue,
13
+ public_method_color: :default,
14
+ private_method_color: :blue,
15
+ protected_method_color: :blue,
16
+ method_missing_color: :bright_red,
17
+ local_var_color: :yellow,
18
+ pry_var_color: :default, # e.g. _, pry_instance, _file_
19
+ instance_var_color: :blue, # e.g. @foo
20
+ class_var_color: :bright_blue, # e.g. @@foo
21
+ global_var_color: :default, # e.g. $CODERAY_DEBUG, $eventmachine_library
22
+ builtin_global_color: :cyan, # e.g. $stdin, $-w, $PID
23
+ pseudo_global_color: :cyan, # e.g. $~, $1..$9, $LAST_MATCH_INFO
24
+ constant_color: :default, # e.g. VERSION, ARGF
25
+ class_constant_color: :blue, # e.g. Object, Kernel
26
+ exception_constant_color: :magenta, # e.g. Exception, RuntimeError
27
+ unloaded_constant_color: :yellow, # Constant still in .autoload? state
28
+ separator: " ",
29
+ ceiling: [Object, Module, Class]
30
+ }.freeze
31
+
32
+ DEFAULT_OPTIONS.each_key do |key|
33
+ define_method key do
34
+ @config[key]
35
+ end
36
+
37
+ define_method "#{key}=" do |value|
38
+ @config[key] = value
39
+ end
40
+ end
41
+
42
+ def_delegators :@config, :[], :[]=, :each, :each_pair, :values, :keys, :to_a
43
+
44
+ def initialize(config)
45
+ @config = config
46
+ end
47
+
48
+ def self.default
49
+ new(DEFAULT_OPTIONS.dup)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ 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,20 @@ class Pry
206
247
  defined?(Coolline) && input.is_a?(Coolline)
207
248
  end
208
249
 
250
+ def prism_available?
251
+ @prism_available ||= begin
252
+ # rubocop:disable Lint/SuppressedException
253
+ begin
254
+ require 'prism'
255
+ rescue LoadError
256
+ end
257
+ # rubocop:enable Lint/SuppressedException
258
+
259
+ defined?(Prism) &&
260
+ Gem::Version.new(Prism::VERSION) >= Gem::Version.new('0.25.0')
261
+ end
262
+ end
263
+
209
264
  # If `$stdout` is not a tty, it's probably a pipe.
210
265
  # @example
211
266
  # # `piping?` returns `false`
@@ -227,6 +282,21 @@ class Pry
227
282
  @readline_output = (Readline.output = Pry.config.output) if piping?
228
283
  end
229
284
 
285
+ UNEXPECTED_TOKENS = %i[unexpected_token_ignore lambda_open].freeze
286
+
287
+ def complete_expression?(multiline_input)
288
+ if prism_available?
289
+ lex = Prism.lex(multiline_input)
290
+
291
+ errors = lex.errors
292
+ return true if errors.empty?
293
+
294
+ errors.any? { |error| UNEXPECTED_TOKENS.include?(error.type) }
295
+ else
296
+ Pry::Code.complete_expression?(multiline_input)
297
+ end
298
+ end
299
+
230
300
  # Calculates correct overhang for current line. Supports vi Readline
231
301
  # mode and its indicators such as "(ins)" or "(cmd)".
232
302
  #
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.1'.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,7 +1,7 @@
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.1
5
5
  platform: java
6
6
  authors:
7
7
  - John Mair (banisterfiend)
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-01-09 00:00:00.000000000 Z
14
+ date: 2024-12-24 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: coderay
@@ -116,6 +116,7 @@ files:
116
116
  - lib/pry/commands/jump_to.rb
117
117
  - lib/pry/commands/list_inspectors.rb
118
118
  - lib/pry/commands/ls.rb
119
+ - lib/pry/commands/ls/config.rb
119
120
  - lib/pry/commands/ls/constants.rb
120
121
  - lib/pry/commands/ls/formatter.rb
121
122
  - lib/pry/commands/ls/globals.rb
@@ -174,6 +175,7 @@ files:
174
175
  - lib/pry/history.rb
175
176
  - lib/pry/hooks.rb
176
177
  - lib/pry/indent.rb
178
+ - lib/pry/input/simple_stdio.rb
177
179
  - lib/pry/input_completer.rb
178
180
  - lib/pry/input_lock.rb
179
181
  - lib/pry/inspector.rb
@@ -229,7 +231,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
229
231
  - !ruby/object:Gem::Version
230
232
  version: '0'
231
233
  requirements: []
232
- rubygems_version: 3.4.1
234
+ rubygems_version: 3.4.14
233
235
  signing_key:
234
236
  specification_version: 4
235
237
  summary: A runtime developer console and IRB alternative with powerful introspection