How to Update Your Pry Prompt Setting since v0.13.0
- Backend
- 26 Jun, 2020
The pry gem changed itsPry::Prompt API since v0.13.0, and deprecated setting prompt through Pry.config.prompt = [] . If you have customized this way, you should use the new API instead.
If you have set up your pry prompt like this way:
# config/initializers/pry.rb
# Show red environment name in pry prompt for non development environments
unless Rails.env.development?
old_prompt = Pry.config.prompt
env = Pry::Helpers::Text.red(Rails.env.upcase)
Pry.config.prompt = [
proc {|*a| "#{env} #{old_prompt.first.call(*a)}"},
proc {|*a| "#{env} #{old_prompt.second.call(*a)}"},
]
end
You could use the new API like this:
unless Rails.env.development?
default_prompt = Pry::Prompt[:default]
env = Pry::Helpers::Text.red(Rails.env.upcase)
Pry.config.prompt = Pry::Prompt.new(
'custom',
'my custom prompt',
[
proc{ |*args| "#{env} #{default_prompt.wait_proc.call(*args)}" },
proc{ |*args| "#{env} #{default_prompt.incomplete_proc.call(*args)}" },
],
)
end