Skip to content

Support syntax highlighting customization#1199

Open
shugo wants to merge 1 commit intoruby:masterfrom
shugo:feature/syntax-highlighting-customization
Open

Support syntax highlighting customization#1199
shugo wants to merge 1 commit intoruby:masterfrom
shugo:feature/syntax-highlighting-customization

Conversation

@shugo
Copy link
Copy Markdown
Member

@shugo shugo commented Apr 9, 2026

For example, put the following code in ~/.irbrc:

Reline::Face.config(:syntax_highlighting) do |conf|
  conf.define :pseudo_variable,  foreground: "#4dacfd",  style: :bold
  conf.define :global_variable,  foreground: "#4dacfd",  style: :bold
  conf.define :constant,         foreground: "#ffa657",  style: :bold
  conf.define :comment,          foreground: "#abaeb1",  style: :bold
  conf.define :string_edge,      foreground: "#c1daec",  style: :bold
  conf.define :string_body,      foreground: "#c1daec"
  conf.define :symbol,           foreground: "#c1daec"
  conf.define :number,           foreground: "#4dacfd",  style: :bold
  conf.define :float,            foreground: "#4dacfd",  style: :bold
  conf.define :keyword,          foreground: "#f16636"
  conf.define :label,            foreground: "#4dacfd"
  conf.define :method_name,      foreground: "#a887e6",  style: :bold
  conf.define :message_name,     foreground: "#a887e6"
  conf.define :error,            foreground: "#f16636",  style: :negative
end

For example, put the following code in ~/.irbrc:

```ruby
Reline::Face.config(:syntax_highlighting) do |conf|
  conf.define :pseudo_variable,  foreground: "#4dacfd",  style: :bold
  conf.define :global_variable,  foreground: "#4dacfd",  style: :bold
  conf.define :constant,         foreground: "#ffa657",  style: :bold
  conf.define :comment,          foreground: "#abaeb1",  style: :bold
  conf.define :string_edge,      foreground: "#c1daec",  style: :bold
  conf.define :string_body,      foreground: "#c1daec"
  conf.define :symbol,           foreground: "#c1daec"
  conf.define :number,           foreground: "#4dacfd",  style: :bold
  conf.define :float,            foreground: "#4dacfd",  style: :bold
  conf.define :keyword,          foreground: "#f16636"
  conf.define :label,            foreground: "#4dacfd"
  conf.define :method_name,      foreground: "#a887e6",  style: :bold
  conf.define :message_name,     foreground: "#a887e6"
  conf.define :error,            foreground: "#f16636",  style: :negative
end
```
Comment on lines +340 to +347
# Normalize SGR sequences for existing test cases
def normalize_sgr(seq)
s = seq.sub(/\A\e\[0m/, "")
return s if s.match?(/\e\[(38|48|58);/) # Do not normalize extended colors
s.gsub(/\e\[([0-9;]+)m/) {
$1.split(/;/).map { |i| "\e[#{i}m" }.join
}
end
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead, it may be better to fix test cases.

conf.define :error, foreground: :red, style: :negative
end

IRB::Color.init
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we call this here too? Are we initializing twice?

Copy link
Copy Markdown
Member Author

@shugo shugo Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's called here just in case irb/color is required from applications other than irb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants