summaryrefslogtreecommitdiff
path: root/lib/pry/prompt.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pry/prompt.rb')
-rw-r--r--lib/pry/prompt.rb54
1 files changed, 40 insertions, 14 deletions
diff --git a/lib/pry/prompt.rb b/lib/pry/prompt.rb
index 1e43841a..cbb91870 100644
--- a/lib/pry/prompt.rb
+++ b/lib/pry/prompt.rb
@@ -19,7 +19,7 @@ class Pry
# # In [4]:
# @since v0.11.0
# @api public
- module Prompt
+ class Prompt
# @return [String]
DEFAULT_NAME = 'pry'.freeze
@@ -35,7 +35,7 @@ class Pry
# Retrieves a prompt.
#
# @example
- # Prompt[:my_prompt][:value]
+ # Prompt[:my_prompt]
#
# @param [Symbol] name The name of the prompt you want to access
# @return [Hash{Symbol=>Object}]
@@ -78,12 +78,13 @@ class Pry
raise ArgumentError, "the '#{name}' prompt was already added"
end
- @prompts[name] = {
- description: description,
- value: separators.map do |sep|
+ @prompts[name] = new(
+ name,
+ description,
+ separators.map do |sep|
proc { |context, nesting, _pry_| yield(context, nesting, _pry_, sep) }
end
- }
+ )
nil
end
@@ -97,10 +98,35 @@ class Pry
end
end
- add 'default',
- "The default Pry prompt. Includes information about the current expression \n" \
- "number, evaluation context, and nesting level, plus a reminder that you're \n" \
- 'using Pry.' do |context, nesting, _pry_, sep|
+ # @return [String]
+ attr_reader :name
+
+ # @return [String]
+ attr_reader :description
+
+ def initialize(name, description, prompt_procs)
+ @name = name
+ @description = description
+ @prompt_procs = prompt_procs
+ end
+
+ # @return [Proc] the proc which builds the wait prompt (`>`)
+ def wait_proc
+ @prompt_procs.first
+ end
+
+ # @return [Proc] the proc which builds the prompt when in the middle of an
+ # expression such as open method, etc. (`*`)
+ def incomplete_proc
+ @prompt_procs.last
+ end
+
+ add(
+ :default,
+ "The default Pry prompt. Includes information about the current expression \n" \
+ "number, evaluation context, and nesting level, plus a reminder that you're \n" \
+ 'using Pry.'
+ ) do |context, nesting, _pry_, sep|
format(
"[%<in_count>s] %<name>s(%<context>s)%<nesting>s%<separator>s ",
in_count: _pry_.input_ring.count,
@@ -112,7 +138,7 @@ class Pry
end
add(
- 'simple',
+ :simple,
"A simple `>>`.",
['>> ', ' | ']
) do |_, _, _, sep|
@@ -120,7 +146,7 @@ class Pry
end
add(
- 'nav',
+ :nav,
"A prompt that displays the binding stack as a path and includes information \n" \
"about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}.",
%w[> *]
@@ -137,7 +163,7 @@ class Pry
end
add(
- 'shell',
+ :shell,
'A prompt that displays `$PWD` as you change it.',
%w[$ *]
) do |context, _nesting, _pry_, sep|
@@ -151,7 +177,7 @@ class Pry
end
add(
- 'none',
+ :none,
'Wave goodbye to the Pry prompt.',
Array.new(2)
) { '' }