From 325016eb3a41dec75e2c2ec35de80fb620b51d20 Mon Sep 17 00:00:00 2001 From: Robert Gleeson Date: Tue, 21 Jan 2014 09:13:26 +0100 Subject: [PATCH] fix the failing Pry#prompt specs. this is a strange and odd case. Pry.prompt is a delegate to Pry.config, as it has always been. the same delegate was setup on an instance of Pry, but never used because we define #prompt and #prompt= with our implementation. the thing that would make the most sense (to me) is to not support Pry.prompt anymore and recommend the use of Pry.config.prompt instead. a lot of code relies on Pry.prompt though, so we have to support the delegate to config and implement custom behavior for the pry instance. --- lib/pry/config/convenience.rb | 1 - lib/pry/pry_class.rb | 8 ++++++++ lib/pry/pry_instance.rb | 21 +++++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/pry/config/convenience.rb b/lib/pry/config/convenience.rb index b814c773..9d9273df 100644 --- a/lib/pry/config/convenience.rb +++ b/lib/pry/config/convenience.rb @@ -3,7 +3,6 @@ module Pry::Config::Convenience :input, :output, :commands, - :prompt, :print, :exception_handler, :quiet?, diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index 6d5ebd49..c3cb2ada 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -20,6 +20,14 @@ class Pry extend Pry::Config::Convenience config_shortcut *Pry::Config.shortcuts + + def prompt=(value) + config.prompt = value + end + + def prompt + config.prompt + end end def self.main diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index a03441f6..138cd403 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -69,6 +69,7 @@ class Pry @backtrace = options[:backtrace] || caller @config = Pry::Config.new @config.merge!(options) + push_prompt(config.prompt) @input_array = Pry::HistoryArray.new config.memory_size @output_array = Pry::HistoryArray.new config.memory_size @custom_completions = config.command_completer @@ -78,6 +79,26 @@ class Pry exec_hook(:when_started, options[:target], options, self) end + # The current prompt. + # This is the prompt at the top of the prompt stack. + # + # @example + # self.prompt = Pry::SIMPLE_PROMPT + # self.prompt # => Pry::SIMPLE_PROMPT + # + # @return [Array] Current prompt. + def prompt + prompt_stack.last + end + + def prompt=(new_prompt) + if prompt_stack.empty? + push_prompt new_prompt + else + prompt_stack[-1] = new_prompt + end + end + # Initialize this instance by pushing its initial context into the binding # stack. If no target is given, start at the top level. def push_initial_binding(target=nil)