Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 37 additions & 3 deletions lib/env_irb_prompt.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
6 changes: 4 additions & 2 deletions spec/lib/env_irb_prompt_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down