8

I added to my .irbrc:

IRB.conf[:PROMPT].reverse_merge!(:RAILS_ENV => {:PROMPT_I=>"#{current_app} #{rails_env} #{prompt} ", :PROMPT_N=>"#{current_app} #{rails_env} #{prompt} ", :PROMPT_S=>nil, :PROMPT_C=>"?> ", :RETURN=>"=> %s\n"}) 
IRB.conf[:PROMPT_MODE] = :RAILS_ENV

If I do something like:

current_app = "\e[31mfoo_bar_app\e[0m"
rails_env = "\e[32m#{RAILS_ENV}\e[0m"

then the prompt shows up beautifully colorized, but if I copy some text into my copybuffer and paste it, if I do page-up/page-down to go to the beginning/end of the current text entered, my cursor like jumps to the middle of the text for page-up, and for page-down it jumps way out to the right into an area of blank spaces where nothing had been typed, then my cursor position is totally screwed up.

Is there a way I can correct this? I would really like a colorized prompt.

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
patrick
  • 9,290
  • 13
  • 61
  • 112

2 Answers2

3

I'd be willing to bet this is similar to the question I asked in Colorized output breaks linewrapping with readline

Try this:

current_app = "\001\e[31mfoo_bar_app\e[0m\002"
rails_env = "\001\e[32m#{RAILS_ENV}\e[0m\002"

Basically, your prompt is not ignoring non-printing characters which causes weird things to happen.

Community
  • 1
  • 1
Eugene
  • 4,829
  • 1
  • 24
  • 49
  • Only the control codes which set the color should be surrounded by `\001` and `\002`, not the text which is to be printed in color. Otherwise you have a problem in the other direction. – qqx Dec 14 '12 at 07:13
0

Yes, only color code need to be in \001 and \002 like this

\001\e[37m\002[%~] #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} - r#{release}\001\e[0m\002production
kureikain
  • 2,304
  • 2
  • 14
  • 9