Sha256: 4f3f87f7aa216b0c820249e6c955044519a266fe52f5fe58a9bbf67e15f32858

Contents?: true

Size: 1.02 KB

Versions: 13

Compression:

Stored size: 1.02 KB

Contents

class Pry::Command::ChangePrompt < Pry::ClassCommand
  match 'change-prompt'
  group 'Input and Output'
  description 'Change the current prompt.'
  command_options argument_required: true
  banner <<-BANNER
    Usage: change-prompt [OPTIONS] [NAME]

    Change the current prompt.
  BANNER

  def options(opt)
    opt.on(:l, :list, 'List the available prompts')
  end

  def process(prompt)
    if opts.present?(:l)
      list_prompts
    else
      change_prompt(prompt)
    end
  end

  private

  def list_prompts
    prompts = Pry::Prompt.all.map do |name, prompt|
      "#{bold(name)}#{red(' (selected)') if _pry_.prompt == prompt[:value]}\n" +
        prompt[:description]
    end
    output.puts(prompts.join("\n"))
  end

  def change_prompt(prompt)
    if Pry::Prompt.all.key?(prompt)
      _pry_.prompt = Pry::Prompt.all[prompt][:value]
    else
      raise(Pry::CommandError, <<MSG)
'#{prompt}' isn't a known prompt. Run `change-prompt --list` to see
the list of known prompts.
MSG
    end
  end

  Pry::Commands.add_command(self)
end

Version data entries

13 entries across 13 versions & 7 rubygems

Version Path
argon-1.3.1 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
symbolic_enum-1.1.5 vendor/bundle/ruby/2.7.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
chess_engine-0.0.2 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
chess_engine-0.0.1 vendor/bundle/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/pry-0.12.2/lib/pry/commands/change_prompt.rb
pry-0.12.2-java lib/pry/commands/change_prompt.rb
pry-0.12.2 lib/pry/commands/change_prompt.rb
pry-0.12.0 lib/pry/commands/change_prompt.rb
pry-0.12.0-java lib/pry/commands/change_prompt.rb