diff --git a/lib/pry/commands/change_prompt.rb b/lib/pry/commands/change_prompt.rb index f20b741a..746cbbc3 100644 --- a/lib/pry/commands/change_prompt.rb +++ b/lib/pry/commands/change_prompt.rb @@ -4,17 +4,41 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand description 'Change the current prompt.' command_options argument_required: true banner <<-BANNER - Usage: change-prompt NAME + Usage: change-prompt [OPTIONS] [NAME] - Change the current prompt. See list-prompts for a list of available - prompts. + 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, "'#{prompt}' isn't a known prompt!" + raise(Pry::CommandError, <s] %s(%s)%s%s ", @@ -109,13 +109,13 @@ DESC ) end - add(:simple, "A simple '>>'.", ['>> ', ' | ']) do |_, _, _, sep| + add(:simple, "A simple `>>`.\n", ['>> ', ' | ']) do |_, _, _, sep| sep end add(:nav, < *]) do |context, nesting, _pry_, sep| -A prompt that displays the binding stack as a path and -includes information about _in_ and _out_. +A prompt that displays the binding stack as a path and includes information +about #{Helpers::Text.bold('_in_')} and #{Helpers::Text.bold('_out_')}. DESC tree = _pry_.binding_stack.map { |b| Pry.view_clip(b.eval('self')) } format( @@ -129,8 +129,7 @@ DESC end add(:shell, <s %s:%s %s ",