add 'list-prompts' and 'change-prompt' commands.

the list-prompts command shows a list of available prompts as well
as the active prompt in the list. prompts are drawn with a name as
well as a short description.

change-prompt can be used to change the prompt by the name found in
the list-prompts command.
This commit is contained in:
Robert Gleeson 2014-03-19 14:06:26 +01:00
parent 8092a7db99
commit e617c7d420
5 changed files with 85 additions and 0 deletions

View File

@ -27,6 +27,10 @@
* Add option to disable input completer through `_pry_.config.completer = nil`
* Add `Pry.main`. returns a special instance of Object referenced by self of `TOPLEVEL_BINDING`: "main".
* Add `Pry::LastException` (#1145)
* Add `list-prompts` command. (#1175)
- lists the available prompts available for use.
* Add `change-prompt` command. (#1175)
- switch the current prompt, by name.
#### Bug fixes, etc.
* Move `Pry::BondCompleter` and bond integration to the [pry-bond](https://github.com/pry/pry-bond) rubygem. (#1166)

View File

@ -174,3 +174,4 @@ require 'pry/editor'
require 'pry/rubygem'
require "pry/indent"
require "pry/last_exception"
require "pry/prompt"

View File

@ -0,0 +1,24 @@
class Pry::Command::ChangePrompt < Pry::ClassCommand
match 'change-prompt'
group 'prompts'
description 'change the current pry prompt'
command_options argument_required: true
banner <<-BANNER
Usage: change-prompt
change the current prompt. see list-prompts for a list of available prompts.
BANNER
def process(prompt)
if prompt_map.key?(prompt)
_pry_.prompt = prompt_map[prompt][:value]
else
raise Pry::CommandError, "'#{prompt}' isn't a known prompt!"
end
end
private
def prompt_map
Pry::Prompt::MAP
end
Pry::Commands.add_command(self)
end

View File

@ -0,0 +1,33 @@
class Pry::Command::ListPrompts < Pry::ClassCommand
match 'list-prompts'
group 'prompts'
description 'list the prompts available for use in pry'
banner <<-BANNER
Usage: list-prompts
list the prompts available for use in pry
BANNER
def process
output.puts heading("Available prompts") + "\n"
prompt_map.each do |name, prompt|
output.write "name: #{text.bold(name)}"
output.puts selected_prompt?(prompt) ? selected_text : ""
output.puts prompt[:description]
output.puts
end
end
private
def prompt_map
Pry::Prompt::MAP
end
def selected_text
text.red " (selected) "
end
def selected_prompt?(prompt)
_pry_.prompt == prompt[:value]
end
Pry::Commands.add_command(self)
end

23
lib/pry/prompt.rb Normal file
View File

@ -0,0 +1,23 @@
class Pry::Prompt
MAP = {
"default" => {
value: Pry::DEFAULT_PROMPT,
description: "the default pry prompt"
},
"simple" => {
value: Pry::SIMPLE_PROMPT,
description: "a simple prompt"
},
"nav" => {
value: Pry::NAV_PROMPT,
description: "a prompt that draws the binding stack as a path and includes information about _in_ and _out_"
},
"none" => {
value: Pry::NO_PROMPT,
description: "wave goodbye to the pry prompt"
}
}
end