2014-03-19 09:06:26 -04:00
|
|
|
class Pry::Command::ChangePrompt < Pry::ClassCommand
|
|
|
|
match 'change-prompt'
|
2014-05-05 03:49:45 -04:00
|
|
|
group 'Input and Output'
|
|
|
|
description 'Change the current prompt.'
|
2014-03-19 09:06:26 -04:00
|
|
|
command_options argument_required: true
|
|
|
|
banner <<-BANNER
|
2018-11-03 17:16:32 -04:00
|
|
|
Usage: change-prompt [OPTIONS] [NAME]
|
2014-05-05 03:49:45 -04:00
|
|
|
|
2018-11-03 17:16:32 -04:00
|
|
|
Change the current prompt.
|
2014-03-19 09:06:26 -04:00
|
|
|
BANNER
|
|
|
|
|
2018-11-03 17:16:32 -04:00
|
|
|
def options(opt)
|
|
|
|
opt.on(:l, :list, 'List the available prompts')
|
|
|
|
end
|
|
|
|
|
2014-03-19 09:06:26 -04:00
|
|
|
def process(prompt)
|
2018-11-03 17:16:32 -04:00
|
|
|
if opts.present?(:l)
|
|
|
|
list_prompts
|
|
|
|
else
|
|
|
|
change_prompt(prompt)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def list_prompts
|
|
|
|
prompts = Pry::Prompt.all.map do |name, prompt|
|
2018-11-10 15:20:45 -05:00
|
|
|
"#{bold(name)}#{red(' (selected)') if _pry_.prompt == prompt}\n" +
|
|
|
|
prompt.description
|
2018-11-03 17:16:32 -04:00
|
|
|
end
|
2018-11-05 15:25:10 -05:00
|
|
|
output.puts(prompts.join("\n" * 2))
|
2018-11-03 17:16:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def change_prompt(prompt)
|
2018-11-10 15:20:45 -05:00
|
|
|
if Pry::Prompt[prompt]
|
|
|
|
_pry_.prompt = Pry::Prompt[prompt]
|
2014-03-19 09:06:26 -04:00
|
|
|
else
|
2018-11-13 20:37:07 -05:00
|
|
|
raise Pry::CommandError, "'#{prompt}' isn't a known prompt. " \
|
|
|
|
"Run `change-prompt --list` to see the list of known prompts."
|
2014-03-19 09:06:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Pry::Commands.add_command(self)
|
|
|
|
end
|