class Pry::Prompt

@api public
@since v0.11.0
prompt.incomplete_proc.call(…)
prompt.wait_proc.call(…) #=>
)
prompt_procs
’Random number or letter prompt.‘,
:random,
prompt = Pry::Prompt.new(
]
proc { “#{(’a’..‘z’).to_a.sample}*” }
proc { ‘#{rand(1)}>“ },
prompt_procs = [
@example Manually instantiating the Prompt class
# In [4]:
# => :foo
# …: end
# …: puts ’foo’
# In [3]: def foo
# Produces:
end
sep == ‘:’ ? ”In [#{pry_instance.input_ring.count}]: “ : ‘ …: ’
) do |_context, _nesting, pry_instance, sep|
‘IPython-like prompt’, [‘:’, ‘…:’]
:ipython,
Pry::Prompt.add(
@example Registering a new Pry prompt
etc) and also provides an API for adding and implementing custom prompts.
libraries. It defines a few default prompts (default prompt, simple prompt,
Prompt represents the Pry prompt, which can be used with Readline-like

def [](name)

Other tags:
    Since: - v0.12.0

Returns:
  • (Hash{Symbol=>Object}) -

Parameters:
  • name (Symbol) -- The name of the prompt you want to access
def [](name)
  @prompts[name.to_s]
end

def [](key)

Deprecated:
  • Use a `Pry::Prompt` instance directly
def [](key)
  key = key.to_s
  if %w[name description].include?(key)
    Pry::Warning.warn(
      "`Pry::Prompt[:#{@name}][:#{key}]` is deprecated. " \
      "Use `#{self.class}##{key}` instead"
    )
    public_send(key)
  elsif key.to_s == 'value'
    Pry::Warning.warn(
      "`#{self.class}[:#{@name}][:value]` is deprecated. Use " \
      "`#{self.class}#prompt_procs` instead or an instance of " \
      "`#{self.class}` directly"
    )
    @prompt_procs
  end
end

def add(name, description = '', separators = %w[> *])

Other tags:
    Since: - v0.12.0

Raises:
  • (ArgumentError) - if `prompt_name` is already occupied
  • (ArgumentError) - if the size of `separators` is not 2

Returns:
  • (nil) -

Other tags:
    Yieldparam: separator - separator string
    Yieldparam: pry_instance - the Pry instance
    Yieldparam: nesting - whether the context is nested
    Yieldparam: context - the context where Pry is currently in

Other tags:
    Yield: -

Parameters:
  • separators (Array) -- The separators to differentiate
  • description (String) --
  • name (Symbol) --
def add(name, description = '', separators = %w[> *])
  name = name.to_s
  unless separators.size == 2
    raise ArgumentError, "separators size must be 2, given #{separators.size}"
  end
  if @prompts.key?(name)
    raise ArgumentError, "the '#{name}' prompt was already added"
  end
  @prompts[name] = new(
    name,
    description,
    separators.map do |sep|
      proc do |context, nesting, pry_instance|
        yield(context, nesting, pry_instance, sep)
      end
    end
  )
  nil
end

def all

Other tags:
    Since: - v0.12.0

Other tags:
    Note: - Use this for read-only operations

Returns:
  • (Hash{Symbol=>Hash}) - the duplicate of the internal prompts hash
def all
  @prompts.dup
end

def incomplete_proc

Returns:
  • (Proc) - the proc which builds the prompt when in the middle of an
def incomplete_proc
  @prompt_procs.last
end

def initialize(name, description, prompt_procs)

Parameters:
  • prompt_procs (Array) --
  • description (String) --
  • name (String) --
def initialize(name, description, prompt_procs)
  @name = name
  @description = description
  @prompt_procs = prompt_procs
end

def wait_proc

Returns:
  • (Proc) - the proc which builds the wait prompt (`>`)
def wait_proc
  @prompt_procs.first
end