summaryrefslogtreecommitdiff
path: root/lib/pry/commands
diff options
context:
space:
mode:
authorKyrylo Silin <silin@kyrylo.org>2018-11-03 21:58:16 +0800
committerKyrylo Silin <silin@kyrylo.org>2018-11-03 22:08:52 +0800
commit82d683b146094dec1ac4dc09f56208df2e1dde7e (patch)
tree0927e5b3267667d19ee95b262aed68e489f4a154 /lib/pry/commands
parent98c5e95064524a603dbaef03c94c97a6b665b9c2 (diff)
downloadpry-prompt-api.tar.gz
prompt: add basic API for adding promptsprompt-api
Fixes #1836 (Add an API for adding new prompts)
Diffstat (limited to 'lib/pry/commands')
-rw-r--r--lib/pry/commands/change_prompt.rb8
-rw-r--r--lib/pry/commands/list_prompts.rb7
-rw-r--r--lib/pry/commands/shell_mode.rb10
3 files changed, 8 insertions, 17 deletions
diff --git a/lib/pry/commands/change_prompt.rb b/lib/pry/commands/change_prompt.rb
index 13d36cbb..f20b741a 100644
--- a/lib/pry/commands/change_prompt.rb
+++ b/lib/pry/commands/change_prompt.rb
@@ -11,16 +11,12 @@ class Pry::Command::ChangePrompt < Pry::ClassCommand
BANNER
def process(prompt)
- if prompt_map.key?(prompt)
- _pry_.prompt = prompt_map[prompt][:value]
+ if Pry::Prompt.all.key?(prompt)
+ _pry_.prompt = Pry::Prompt.all[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
diff --git a/lib/pry/commands/list_prompts.rb b/lib/pry/commands/list_prompts.rb
index c257de7f..9fe2cad3 100644
--- a/lib/pry/commands/list_prompts.rb
+++ b/lib/pry/commands/list_prompts.rb
@@ -11,7 +11,7 @@ class Pry::Command::ListPrompts < Pry::ClassCommand
def process
output.puts heading("Available prompts") + "\n"
- prompt_map.each do |name, prompt|
+ Pry::Prompt.all.each do |name, prompt|
output.write "Name: #{bold(name)}"
output.puts selected_prompt?(prompt) ? selected_text : ""
output.puts prompt[:description]
@@ -19,10 +19,7 @@ class Pry::Command::ListPrompts < Pry::ClassCommand
end
end
-private
- def prompt_map
- Pry::Prompt::MAP
- end
+ private
def selected_text
red " (selected) "
diff --git a/lib/pry/commands/shell_mode.rb b/lib/pry/commands/shell_mode.rb
index 0e5fd0bd..429da7ad 100644
--- a/lib/pry/commands/shell_mode.rb
+++ b/lib/pry/commands/shell_mode.rb
@@ -9,13 +9,11 @@ class Pry
BANNER
def process
- case _pry_.prompt
- when Pry::Prompt::SHELL
- _pry_.pop_prompt
- _pry_.custom_completions = _pry_.config.file_completions
+ if state.disabled ^= true
+ state.prev_prompt = _pry_.prompt
+ _pry_.prompt = Pry::Prompt[:shell][:value]
else
- _pry_.push_prompt Pry::Prompt::SHELL
- _pry_.custom_completions = _pry_.config.command_completions
+ _pry_.prompt = state.prev_prompt
end
end
end