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.
This commit is contained in:
Robert Gleeson 2014-01-21 09:13:26 +01:00
parent eab4241ff6
commit 325016eb3a
3 changed files with 29 additions and 1 deletions

View File

@ -3,7 +3,6 @@ module Pry::Config::Convenience
:input,
:output,
:commands,
:prompt,
:print,
:exception_handler,
:quiet?,

View File

@ -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

View File

@ -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<Proc>] 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)