11

I'm very happy to be using the most recent ruby 3.0; as well as having access to the updated command-line interpreter which does syntax highlighting and coloring.

However, the colors are a bit hard to see for me. How can I change them? The command line options for IRB allow me to turn off colorization, but I can't figure out where the configuration files are that would allow me to change the defaults (e.g., to make the blue color lighter.)

Simon DeDeo
  • 111
  • 1
  • 3
  • 1
    I was not aware that with Ruby 3, we will have a clourful irb, but I am using in irb the `wirble` gem with works with Ruby 2.x (perhaps with Ruby 3 too) and allows you to configure the colours. – user1934428 Mar 03 '21 at 08:38

4 Answers4

9

I fixed this by changing iTerm2 theme.

Switching to 'Tango Dark' made it readable.

Tango Dark

Here how the new Ruby 3.1 autocomplete feature looks like right now:

Irb autocomplete

Michael Koper
  • 9,586
  • 7
  • 45
  • 59
6

A quick work around until this is configurable is to change the ANSI Cyan colour default in your terminal preferences. In iTerm2 you can go to preferences > Profiles > Colors. I went for a rather fetching 383a59.

fixing irb autocomplete cyan background white text issue

Jamie Buchanan
  • 3,868
  • 4
  • 22
  • 24
5

Some are hardcoded; but most of it is inside a constant, and thus editable (even though it's private). This should let you change all the pesky blues with cyans. The single downside is that keywords are indeed hardcoded to use CYAN, but we can cheat and change the CYAN constant itself to something else (e.g. BLUE - readability for stuff like nil and true is not that important to me, but feel free to change to something else), and hope no other plugin relies on CYAN actually being cyan :D

module IRB::Color
  TOKEN_SEQ_EXPRS.each do |token, (seq, exprs)|
    seq[0] = CYAN if seq[0] == BLUE
  end
  remove_const :CYAN
  CYAN = BLUE
end

You can put it inside $HOME/.irbrc to make it work across all future irb sessions.

Needless to say, this is a hack, and should IRB::Color change in the future, this may well stop working.

Amadan
  • 191,408
  • 23
  • 240
  • 301
  • How to replace red color for strings? – MVP May 25 '23 at 16:25
  • @MVP I guess you could download [`color.rb`](https://github.com/ruby/ruby/blob/master/lib/irb/color.rb) and edit it, redefine `TOKEN_SEQ_EXPRS` as you want, then require it in order to do arbitrary changes. But without that, the only thing you can do is change one constant for another, as described above (in your case `RED`). – Amadan May 26 '23 at 01:14
  • Thanks, yes I have to redefine `TOKEN_SEQ_EXPRS` because I tried to replace the constant `RED` with `MAGENTA` but it doesn't work. Thank you very much. – MVP May 26 '23 at 15:06
2

As far as I can tell reading the source, the colors are hard-coded in the last version or IRB, so there's no configuration (yet!) available for this.

Jaffa
  • 12,442
  • 4
  • 49
  • 101
  • While the color name is hardcoded the far more interesting color value depends on the terminal settings. I'm guessing but maybe OP uses an older Windows version or used to upgrading keeps most settings). Current Windows 10 versions have better default color values. See [ANSI escape code](https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit) on Wikipedia. – cremno Mar 03 '21 at 20:01
  • @cremno the problem if you change the terminal colors is that it changes them everywhere, so it's not very practical if you already like the config you have. I didn't know it was possible on windows though, good to know! – Jaffa Mar 03 '21 at 20:44
  • 1
    True but if this kind of colored text is barely readable in irb it's very likely barely readable in other applications as well. – cremno Mar 04 '21 at 19:05
  • Some are hardcoded; but most of it is inside a constant, and thus editable (even though it's private). – Amadan Apr 06 '22 at 02:18