Rich Ruby is designed to be modular. You can extend it by creating your own box styles, syntax lexers, and themes.
You can create a custom Box by instantiating the class with a set of characters.
MY_BOX = Rich::Box.new(
top_left: "┏", top_right: "┓",
bottom_left: "┗", bottom_right: "┛",
horizontal: "━", vertical: "┃",
cross: "╋"
)
panel = Rich::Panel.new("Custom Border", box: MY_BOX)
puts panel.renderThemes are simply Hashes mapping token types to Rich::Style objects.
MY_THEME = {
keyword: Rich::Style.new(color: "red", bold: true),
string: Rich::Style.new(color: "green"),
comment: Rich::Style.new(color: "dim yellow"),
text: Rich::Style.new(color: "default")
}
syntax = Rich::Syntax.new(code, language: "ruby", theme: MY_THEME)
puts syntax.renderTo add support for a new language, create a class inheriting from Rich::BaseLexer and register it in Rich::Syntax::LEXERS.
class MyLanguageLexer < Rich::BaseLexer
def tokenize(line, theme)
# Return an array of Rich::Segment objects
[Rich::Segment.new(line, style: theme[:text])]
end
end
# Register it
Rich::Syntax::LEXERS["mylang"] = MyLanguageLexer.newThe Rich::Markup parser utilizes the Rich::Style parsing engine. If you want to create a shorthand tag, you can add it to the Style registry if implemented, or simply use combined strings.
Note: Rich Ruby aims to keep the core small. For complex custom components, we recommend composing existing Panel, Table, and Text objects.