Skip to content

Commit

Permalink
Merge pull request #2308 from andrehjr/remove-deprecated-prompt-config
Browse files Browse the repository at this point in the history
Remove deprecated Prompt proc configuration.
  • Loading branch information
andrehjr committed Apr 16, 2024
2 parents c64a8ea + 57b077e commit 4403462
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 46 deletions.
46 changes: 4 additions & 42 deletions lib/pry/pry_instance.rb
@@ -1,7 +1,6 @@
# frozen_string_literal: true

require 'method_source'
require 'ostruct'

##
# Pry is a powerful alternative to the standard IRB shell for Ruby. It
Expand Down Expand Up @@ -93,7 +92,6 @@ def initialize(options = {})
@input_ring << nil
push_initial_binding(target)
exec_hook(:when_started, target, options, self)
@prompt_warn = false
end

# This is the prompt at the top of the prompt stack.
Expand Down Expand Up @@ -452,45 +450,17 @@ def should_print?
# @return [String] The prompt.
def select_prompt
object = current_binding.eval('self')
open_token = @indent.open_delimiters.last || @indent.stack.last

c = OpenStruct.new(
object: object,
nesting_level: binding_stack.size - 1,
open_token: open_token,
session_line: Pry.history.session_line_count + 1,
history_line: Pry.history.history_line_count + 1,
expr_number: input_ring.count,
pry_instance: self,
binding_stack: binding_stack,
input_ring: input_ring,
eval_string: @eval_string,
cont: !@eval_string.empty?
)
nesting_level = binding_stack.size - 1
pry_instance = self

Pry.critical_section do
# If input buffer is empty, then use normal prompt. Otherwise use the wait
# prompt (indicating multi-line expression).
if prompt.is_a?(Pry::Prompt)
prompt_proc = eval_string.empty? ? prompt.wait_proc : prompt.incomplete_proc
return prompt_proc.call(c.object, c.nesting_level, c.pry_instance)
end

unless @prompt_warn
@prompt_warn = true
Kernel.warn(
"warning: setting prompt with help of " \
"`Pry.config.prompt = [proc {}, proc {}]` is deprecated. " \
"Use Pry::Prompt API instead"
)
end

# If input buffer is empty then use normal prompt
if eval_string.empty?
generate_prompt(Array(prompt).first, c)
# Otherwise use the wait prompt (indicating multi-line expression)
return prompt_proc.call(object, nesting_level, pry_instance)
else
generate_prompt(Array(prompt).last, c)
output.puts "ERROR: Use Pry::Prompt API."
end
end
end
Expand Down Expand Up @@ -685,14 +655,6 @@ def ensure_correct_encoding!(val)
end
end

def generate_prompt(prompt_proc, conf)
if prompt_proc.arity == 1
prompt_proc.call(conf)
else
prompt_proc.call(conf.object, conf.nesting_level, conf.pry_instance)
end
end

# the array that the prompt stack is stored in
def prompt_stack
@prompt_stack ||= []
Expand Down
8 changes: 4 additions & 4 deletions spec/pry_defaults_spec.rb
Expand Up @@ -28,7 +28,7 @@
end

it 'should pass in the prompt if readline arity is 1' do
Pry.prompt = proc { "A" }
Pry.prompt = Pry::Prompt[:simple]

arity_one_input = Class.new do
attr_accessor :prompt
Expand All @@ -39,11 +39,11 @@ def readline(prompt)
end.new

Pry.start(self, input: arity_one_input, output: StringIO.new)
expect(arity_one_input.prompt).to eq Pry.prompt.call
expect(arity_one_input.prompt).to eq Pry.prompt.wait_proc.call
end

it 'should not pass in the prompt if the arity is 0' do
Pry.prompt = proc { "A" }
Pry.prompt = Pry::Prompt[:simple]

arity_zero_input = Class.new do
def readline
Expand All @@ -56,7 +56,7 @@ def readline
end

it 'should not pass in the prompt if the arity is -1' do
Pry.prompt = proc { "A" }
Pry.prompt = Pry::Prompt[:simple]

arity_multi_input = Class.new do
attr_accessor :prompt
Expand Down

0 comments on commit 4403462

Please sign in to comment.