'how can I change the default syntax coloring in ruby 3.0's IRB

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.)



Solution 1:[1]

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

Solution 2:[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.

Solution 3:[3]

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.

Solution 4:[4]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Koper
Solution 2 Geoffroy
Solution 3
Solution 4 Jamie Buchanan