summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author0xAB <0xAB@protonmail.com>2017-08-29 07:02:42 +0100
committer0xAB <0xAB@protonmail.com>2017-08-29 07:02:42 +0100
commit44a6fa42b685db011f9f6eff35596f7aabea7580 (patch)
treeaa646de4c01b3ed250f5372a1bee992158584208
parentd1260c1a6b1476628ec229c9efb2789a6a40557b (diff)
downloadpry-44a6fa42b685db011f9f6eff35596f7aabea7580.tar.gz
polish Pry::Prompt
-rw-r--r--CHANGELOG.md8
-rw-r--r--lib/pry/commands/change_prompt.rb6
-rw-r--r--lib/pry/prompt.rb11
-rw-r--r--lib/pry/pry_instance.rb2
4 files changed, 18 insertions, 9 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 06a87687..16ed36b6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,9 +1,11 @@
### HEAD
* Add 'alias-prompt' command.
-* Add `Pry::Prompt.add_prompt()`, `Pry::Prompt.get_prompt()`, `Pry::Prompt.alias_prompt` and
- `Pry::Prompt.remove_prompt()`, for integrating custom prompts with Pry
- ([#1628](https://github.com/pry/pry/pull/1628))
+
+* Add `Pry::Prompt.[]`, `Pry::Prompt.add_prompt()`, `Pry::Prompt.alias_prompt()` and
+ `Pry::Prompt.remove_prompt()`, plus more, for integrating custom prompts with Pry
+ ([#1628](https://github.com/pry/pry/pull/1628)). See Pry::Prompt for complete details.
+
* Add text helpers for background colors ([#1624](https://github.com/pry/pry/pull/1624))
* Fix string literal methods completion. ([#1590](https://github.com/pry/pry/pull/1590))
* Make sure Pry::WrappedModule::Candidate#source_location returns non-nil value when `.name` has
diff --git a/lib/pry/commands/change_prompt.rb b/lib/pry/commands/change_prompt.rb
index 48b6acd2..859825a2 100644
--- a/lib/pry/commands/change_prompt.rb
+++ b/lib/pry/commands/change_prompt.rb
@@ -11,9 +11,9 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand
BANNER
def process(prompt)
- prompts = Pry::Prompt.all(prompt)
+ prompts = Pry::Prompt.all_by_name(prompt)
if prompts.size == 1
- _pry_.prompt = prompts[0].proc_array
+ _pry_.prompt = prompts[0]
elsif prompts.size > 1
multiple_choice(prompts)
else
@@ -30,7 +30,7 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand
output.write "Choice: "
reply = (_pry_.input.respond_to?(:gets) ? _pry_.input.gets : _pry_.input.readline).strip
if reply =~ /^[1-9][0-9]*$/ and reply.to_i <= prompts.size
- _pry_.prompt = prompts[reply.to_i-1].proc_array
+ _pry_.prompt = prompts[reply.to_i-1]
else
multiple_choice(prompts)
end
diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb
index fc68664f..6696b71d 100644
--- a/lib/pry/prompt.rb
+++ b/lib/pry/prompt.rb
@@ -55,7 +55,14 @@ module Pry::Prompt
all_prompts.select(&:alias?)
end
- def find_by_proc_array(proc_array)
+ #
+ # @param [Array<Proc,Proc>] proc_array
+ # An array in the form of [proc{}, proc{}]
+ #
+ # @return [PromptInfo]
+ # Returns the first {PromptInfo} object who holds value eql? to `proc_array`.
+ #
+ def first_matching_proc_array(proc_array)
all_prompts.find do |prompt|
prompt.proc_array == proc_array and not prompt.alias?
end
@@ -101,7 +108,7 @@ module Pry::Prompt
# @return [Array<PromptInfo>]
# An array of {PromptInfo} objects.
#
- def all(name)
+ def all_by_name(name)
name = name.to_s
all_prompts.select{|prompt| prompt.name == name}
end
diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb
index 09e8b8f4..4ffe4c58 100644
--- a/lib/pry/pry_instance.rb
+++ b/lib/pry/pry_instance.rb
@@ -91,7 +91,7 @@ class Pry
# @return [Pry::Prompt::PromptInfo, Array<Proc, Proc>] Current prompt.
def prompt
proc_array = prompt_stack.last
- Pry::Prompt.find_by_proc_array(proc_array) or proc_array
+ Pry::Prompt.first_matching_proc_array(proc_array) or proc_array
end
def prompt=(new_prompt)