mirror of
https://github.com/pry/pry.git
synced 2022-11-09 12:35:05 -05:00
modified select_prompt() method so it now takes eval_string and target; makes for cleaner code at callsites, update tests
This commit is contained in:
parent
a0a72ac13c
commit
ad62ecaf8b
2 changed files with 30 additions and 22 deletions
|
@ -304,7 +304,7 @@ class Pry
|
||||||
def retrieve_line(eval_string, target)
|
def retrieve_line(eval_string, target)
|
||||||
@indent.reset if eval_string.empty?
|
@indent.reset if eval_string.empty?
|
||||||
|
|
||||||
current_prompt = select_prompt(eval_string.empty?, target.eval('self'))
|
current_prompt = select_prompt(eval_string, target)
|
||||||
indentation = Pry.config.auto_indent ? @indent.indent_level : ''
|
indentation = Pry.config.auto_indent ? @indent.indent_level : ''
|
||||||
|
|
||||||
val = readline(current_prompt + indentation)
|
val = readline(current_prompt + indentation)
|
||||||
|
@ -485,14 +485,17 @@ class Pry
|
||||||
|
|
||||||
# Returns the appropriate prompt to use.
|
# Returns the appropriate prompt to use.
|
||||||
# This method should not need to be invoked directly.
|
# This method should not need to be invoked directly.
|
||||||
# @param [Boolean] first_line Whether this is the first line of input
|
# @param [String] eval_string The current input buffer.
|
||||||
# (and not multi-line input).
|
# @param [Binding] target The target Binding of the Pry session.
|
||||||
# @param [Object] target_self The receiver of the Pry session.
|
|
||||||
# @return [String] The prompt.
|
# @return [String] The prompt.
|
||||||
def select_prompt(first_line, target_self)
|
def select_prompt(eval_string, target)
|
||||||
|
target_self = target.eval('self')
|
||||||
|
|
||||||
if first_line
|
# If input buffer is empty then use normal prompt
|
||||||
|
if eval_string.empty?
|
||||||
Array(prompt).first.call(target_self, binding_stack.size - 1, self)
|
Array(prompt).first.call(target_self, binding_stack.size - 1, self)
|
||||||
|
|
||||||
|
# Otherwise use the wait prompt (indicating multi-line expression)
|
||||||
else
|
else
|
||||||
Array(prompt).last.call(target_self, binding_stack.size - 1, self)
|
Array(prompt).last.call(target_self, binding_stack.size - 1, self)
|
||||||
end
|
end
|
||||||
|
|
|
@ -491,7 +491,6 @@ describe Pry do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
describe "test Pry defaults" do
|
describe "test Pry defaults" do
|
||||||
|
|
||||||
after do
|
after do
|
||||||
|
@ -1084,23 +1083,29 @@ describe Pry do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "prompts" do
|
describe "prompts" do
|
||||||
|
before do
|
||||||
|
@empty_input_buffer = ""
|
||||||
|
@non_empty_input_buffer = "def hello"
|
||||||
|
@context = Pry.binding_for(0)
|
||||||
|
end
|
||||||
|
|
||||||
it 'should set the prompt default, and the default should be overridable (single prompt)' do
|
it 'should set the prompt default, and the default should be overridable (single prompt)' do
|
||||||
new_prompt = proc { "test prompt> " }
|
new_prompt = proc { "test prompt> " }
|
||||||
Pry.prompt = new_prompt
|
Pry.prompt = new_prompt
|
||||||
|
|
||||||
Pry.new.prompt.should == Pry.prompt
|
Pry.new.prompt.should == Pry.prompt
|
||||||
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
|
||||||
Pry.new.select_prompt(false, 0).should == "test prompt> "
|
Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt> "
|
||||||
|
|
||||||
new_prompt = proc { "A" }
|
new_prompt = proc { "A" }
|
||||||
pry_tester = Pry.new(:prompt => new_prompt)
|
pry_tester = Pry.new(:prompt => new_prompt)
|
||||||
pry_tester.prompt.should == new_prompt
|
pry_tester.prompt.should == new_prompt
|
||||||
pry_tester.select_prompt(true, 0).should == "A"
|
pry_tester.select_prompt(@empty_input_buffer, @context).should == "A"
|
||||||
pry_tester.select_prompt(false, 0).should == "A"
|
pry_tester.select_prompt(@non_empty_input_buffer, @context).should == "A"
|
||||||
|
|
||||||
Pry.new.prompt.should == Pry.prompt
|
Pry.new.prompt.should == Pry.prompt
|
||||||
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
|
||||||
Pry.new.select_prompt(false, 0).should == "test prompt> "
|
Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt> "
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'should set the prompt default, and the default should be overridable (multi prompt)' do
|
it 'should set the prompt default, and the default should be overridable (multi prompt)' do
|
||||||
|
@ -1108,18 +1113,18 @@ describe Pry do
|
||||||
Pry.prompt = new_prompt
|
Pry.prompt = new_prompt
|
||||||
|
|
||||||
Pry.new.prompt.should == Pry.prompt
|
Pry.new.prompt.should == Pry.prompt
|
||||||
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
|
||||||
Pry.new.select_prompt(false, 0).should == "test prompt* "
|
Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt* "
|
||||||
|
|
||||||
new_prompt = [proc { "A" }, proc { "B" }]
|
new_prompt = [proc { "A" }, proc { "B" }]
|
||||||
pry_tester = Pry.new(:prompt => new_prompt)
|
pry_tester = Pry.new(:prompt => new_prompt)
|
||||||
pry_tester.prompt.should == new_prompt
|
pry_tester.prompt.should == new_prompt
|
||||||
pry_tester.select_prompt(true, 0).should == "A"
|
pry_tester.select_prompt(@empty_input_buffer, @context).should == "A"
|
||||||
pry_tester.select_prompt(false, 0).should == "B"
|
pry_tester.select_prompt(@non_empty_input_buffer, @context).should == "B"
|
||||||
|
|
||||||
Pry.new.prompt.should == Pry.prompt
|
Pry.new.prompt.should == Pry.prompt
|
||||||
Pry.new.select_prompt(true, 0).should == "test prompt> "
|
Pry.new.select_prompt(@empty_input_buffer, @context).should == "test prompt> "
|
||||||
Pry.new.select_prompt(false, 0).should == "test prompt* "
|
Pry.new.select_prompt(@non_empty_input_buffer, @context).should == "test prompt* "
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'storing and restoring the prompt' do
|
describe 'storing and restoring the prompt' do
|
||||||
|
@ -1145,11 +1150,11 @@ describe Pry do
|
||||||
it 'should restore overridden prompts when returning from file-mode' do
|
it 'should restore overridden prompts when returning from file-mode' do
|
||||||
pry = Pry.new :input => InputTester.new('shell-mode', 'shell-mode'),
|
pry = Pry.new :input => InputTester.new('shell-mode', 'shell-mode'),
|
||||||
:prompt => [ proc { 'P>' } ] * 2
|
:prompt => [ proc { 'P>' } ] * 2
|
||||||
pry.select_prompt(true, 0).should == "P>"
|
pry.select_prompt(@empty_input_buffer, @context).should == "P>"
|
||||||
pry.re
|
pry.re
|
||||||
pry.select_prompt(true, 0).should =~ /\Apry .* \$ \z/
|
pry.select_prompt(@empty_input_buffer, @context).should =~ /\Apry .* \$ \z/
|
||||||
pry.re
|
pry.re
|
||||||
pry.select_prompt(true, 0).should == "P>"
|
pry.select_prompt(@empty_input_buffer, @context).should == "P>"
|
||||||
end
|
end
|
||||||
|
|
||||||
it '#pop_prompt should return the popped prompt' do
|
it '#pop_prompt should return the popped prompt' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue