Class: RatatuiRuby::Style::Style
- Inherits:
-
Object
- Object
- RatatuiRuby::Style::Style
- Defined in:
- lib/ratatui_ruby/style/style.rb
Overview
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
-- SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
Standard colors
Style::Style.new(fg: :red, bg: :white, modifiers: [:bold])
# Hex colors
Style::Style.new(fg: "#ff00ff")
-- SPDX-SnippetEnd ++
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,
--
SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++ :light_yellow, :light_blue, :light_magenta, :light_cyan, :white
SPDX-SnippetEnd ++
- :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.
Class Method Summary collapse
-
.default ⇒ Object
Returns an empty style.
-
.with(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) ⇒ Style
Creates a new Style (convenience alias for #initialize).
Instance Method Summary collapse
-
#initialize(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) ⇒ Style
constructor
Creates a new Style.
Constructor Details
#initialize(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) ⇒ Style
Creates a new Style.
[fg] Color (Symbol/String/Integer). [bg] Color (Symbol/String/Integer). [underline_color] Color for underline (Symbol/String/Integer). [modifiers] Array of Symbols to add. [remove_modifiers] Array of Symbols to remove (Ratatui: sub_modifier).
105 106 107 |
# File 'lib/ratatui_ruby/style/style.rb', line 105 def initialize(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) super end |
Class Method Details
.default ⇒ Object
Returns an empty style.
Use this as a baseline to prevent style inheritance issues or when no styling is required.
112 113 114 |
# File 'lib/ratatui_ruby/style/style.rb', line 112 def self.default new end |
.with(fg: nil, bg: nil, underline_color: nil, modifiers: [], remove_modifiers: []) ⇒ Style
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
--
SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++ 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))
SPDX-SnippetEnd ++
142 143 144 |
# 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 |