From 57b077e030f8433bcb42ee94a24910ae0587db08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Luis=20Leal=20Cardoso=20Junior?= Date: Sun, 14 Apr 2024 21:25:48 -0300 Subject: [PATCH] Remove deprecated Prompt proc configuration. Deprecated on v0.13.0 --- lib/pry/pry_instance.rb | 46 ++++----------------------------------- spec/pry_defaults_spec.rb | 8 +++---- 2 files changed, 8 insertions(+), 46 deletions(-) diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 68da39b51..ce44dc138 100644 --- a/lib/pry/pry_instance.rb +++ b/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 @@ -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. @@ -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 @@ -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 ||= [] diff --git a/spec/pry_defaults_spec.rb b/spec/pry_defaults_spec.rb index fa0b8c1a1..0b13e1c97 100644 --- a/spec/pry_defaults_spec.rb +++ b/spec/pry_defaults_spec.rb @@ -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 @@ -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 @@ -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