diff --git a/lib/env_irb_prompt.rb b/lib/env_irb_prompt.rb index d6facbedfda..9d31d869bd2 100644 --- a/lib/env_irb_prompt.rb +++ b/lib/env_irb_prompt.rb @@ -7,9 +7,9 @@ def configure!(irb_conf = IRB.conf) irb_conf[:SAVE_HISTORY] = on_deployed_box? ? nil : 1000 irb_conf[:PROMPT][:ENV_PROMPT] = { - PROMPT_I: "%N(#{bold(env)}):%03n:%i> ", - PROMPT_S: "%N(\e[1m#{bold(env)}\e[22m):%03n:%i%l ", - PROMPT_C: "%N(\e[1m#{bold(env)}\e[22m):%03n:%i* ", + PROMPT_I: "%N(#{bold(color(env))}):%03n:%i> ", + PROMPT_S: "%N(\e[1m#{bold(color(env))}\e[22m):%03n:%i%l ", + PROMPT_C: "%N(\e[1m#{bold(color(env))}\e[22m):%03n:%i* ", RETURN: "%s\n", } irb_conf[:PROMPT_MODE] = :ENV_PROMPT @@ -29,6 +29,40 @@ def env end end + # @api private + def color(str) + case env + when 'local' + color_blue(str) + when 'prod' + color_red(str) + when 'staging' + color_yellowy_orange(str) + else + color_green(str) + end + end + + # @api private + def color_red(str) + "\e[31m#{str}\e[0m" + end + + # @api private + def color_yellowy_orange(str) + "\e[33m#{str}\e[0m" + end + + # @api private + def color_blue(str) + "\e[34m#{str}\e[0m" + end + + # @api private + def color_green(str) + "\e[32m#{str}\e[0m" + end + # @api private def bold(str) "\e[1m#{str}\e[22m" diff --git a/spec/lib/env_irb_prompt_spec.rb b/spec/lib/env_irb_prompt_spec.rb index d753f930691..08ce2aa8a97 100644 --- a/spec/lib/env_irb_prompt_spec.rb +++ b/spec/lib/env_irb_prompt_spec.rb @@ -32,7 +32,8 @@ it 'sets the prompt with the environment name' do configure - expect(irb_conf[:PROMPT][:ENV_PROMPT][:PROMPT_I]).to include(prompt.bold('dev')) + expect(irb_conf[:PROMPT][:ENV_PROMPT][:PROMPT_I]). + to include(prompt.bold(prompt.color_green('dev'))) end end @@ -51,7 +52,8 @@ it 'sets the prompt with local' do configure - expect(irb_conf[:PROMPT][:ENV_PROMPT][:PROMPT_I]).to include(prompt.bold('local')) + expect(irb_conf[:PROMPT][:ENV_PROMPT][:PROMPT_I]). + to include(prompt.bold(prompt.color_blue('local'))) end end end