class RatatuiRuby::Style::Style
Defines colors and text modifiers.
The terminal is traditionally monochrome, but efficient interfaces use color to convey meaning. Red for errors. Green for success. Bold for headers.
This value object encapsulates those choices. It applies foreground and background colors. It adds effects like italics or blinking.
Use it to theme your application or highlight critical data.
Examples
# Standard colors Style::Style.new(fg: :red, bg: :white, modifiers: [:bold]) # Hex colors Style::Style.new(fg: "#ff00ff")
Supported Colors
Integer
Represents an indexed color from the Xterm 256-color palette (0-255).
-
0ā15: Standard and bright ANSI colors. -
16ā231: 6x6x6 Color Cube. -
232ā255: Grayscale ramp.
Symbol
Represents a named color from the standard ANSI palette. Supported values:
-
:black,:red,:green,:yellow,:blue,:magenta,:cyan,:gray -
:dark_gray,:light_red,:light_green,:light_yellow,:light_blue,:light_magenta,:light_cyan,:white -
:resetā Restores the terminalās default color.
String
Represents a specific RGB color using a Hex code ("#RRGGBB"). Requires a terminal emulator with āTrue Colorā (24-bit color) support.
Attributes
Background color.
Symbol (:black), Hex String ("#000000"), or Integer (0-255).
Foreground color.
Symbol (:red), Hex String ("#ffffff"), or Integer (0-255).
Text effects to add.
Array of symbols: :bold, :dim, :italic, :underlined, :slow_blink, :rapid_blink, :reversed, :hidden, :crossed_out.
Text effects to remove.
Array of symbols. When this style is applied, these modifiers are removed from any inherited/patched styles. Corresponds to Ratatuiās sub_modifier.
Color of the underline.
Symbol (:red), Hex String ("#ff0000"), or Integer (0-255). Distinct from foreground color. Terminals supporting this feature render the underline in this color while text remains in the foreground color.
Public Class Methods
Source
# File lib/ratatui_ruby/style/style.rb, line 112 def self.default new end
Returns an empty style.
Use this as a baseline to prevent style inheritance issues or when no styling is required.
Source
# File lib/ratatui_ruby/style/style.rb, line 105 def initialize(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) super end
Creates a new Style.
- fg
-
Color(Symbol/String/Integer). - bg
-
Color(Symbol/String/Integer). underline_color-
Colorfor underline (Symbol/String/Integer). - modifiers
-
Array of
Symbolsto add. remove_modifiers-
Array of
Symbolsto remove (Ratatui: sub_modifier).
Source
# File lib/ratatui_ruby/style/style.rb, line 142 def self.with(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) new(fg:, bg:, underline_color:, modifiers:, remove_modifiers:) end
Creates a new Style (convenience alias for {#initialize}).
Constructor keyword arguments require typing out the full Style.new form. This gets verbose in tight layout code or one-liners.
Style.with reads more naturally and enables method chaining. It shows intent: āuse this style with these properties.ā
Use it for inline styling where conciseness matters.
Examples
Style.with(fg: :red, bg: :black, modifiers: [:bold]) Style.with(fg: :white, modifiers: [:underlined], underline_color: :red) Style.with(modifiers: [:bold], remove_modifiers: [:italic]) # Add bold, remove italic paragraph = Paragraph.new(text: "Alert!", style: Style.with(fg: :red))
@return [Style]