class RatatuiRuby::Cell
Represents a single cell in the terminal buffer.
A terminal grid is made of cells. Each cell contains a character (symbol) and styling (colors, modifiers). When testing, you often need to verify that a specific cell renders correctly.
This object encapsulates that state. It provides predicate methods for modifiers, making assertions readable.
Use it to inspect the visual state of your application in tests.
Examples
cell = RatatuiRuby.get_cell_at(0, 0) cell.char # => "H" cell.fg # => :red cell.bold? # => true
Attributes
The background color of the cell (e.g., :black, nil).
The character displayed in the cell.
Named to match Ratatuiās Cell::symbol() method.
The foreground color of the cell (e.g., :red, :blue, ā#ff0000ā).
The character displayed in the cell.
Named to match Ratatuiās Cell::symbol() method.
The underline color of the cell.
Distinct from foreground color. Some terminals support colored underlines.
Public Class Methods
Source
# File lib/ratatui_ruby/cell.rb, line 112 def self.char(char) symbol(char) end
Alias for Rubyists who prefer a shorter name.
Source
# File lib/ratatui_ruby/cell.rb, line 87 def self.default empty end
Source
# File lib/ratatui_ruby/cell.rb, line 69 def self.empty new(symbol: " ", fg: nil, bg: nil, underline_color: nil, modifiers: []) end
Returns an empty cell (space character, no styles).
Example
Cell.empty # => #<RatatuiRuby::Cell char=" ">
Source
# File lib/ratatui_ruby/cell.rb, line 123 def initialize(symbol: nil, char: nil, fg: nil, bg: nil, underline_color: nil, modifiers: []) @symbol = (symbol || char || " ").freeze @fg = fg&.freeze @bg = bg&.freeze @underline_color = underline_color&.freeze @modifiers = modifiers.map(&:freeze).freeze freeze end
Creates a new Cell.
- symbol
-
String (single character). Aliased as
char:. - fg
-
Symbol or String (nullable).
- bg
-
Symbol or String (nullable).
underline_color-
Symbol or String (nullable).
- modifiers
-
Array of Strings.
Source
# File lib/ratatui_ruby/cell.rb, line 107 def self.symbol(symbol) new(symbol:, fg: nil, bg: nil, underline_color: nil, modifiers: []) end
Returns a cell with a specific character and no styles.
- symbol
-
String (single character).
Example
Cell.symbol("X") # => #<RatatuiRuby::Cell symbol="X">
Public Instance Methods
Source
# File lib/ratatui_ruby/cell.rb, line 178 def ==(other) other.is_a?(Cell) && char == other.char && fg == other.fg && bg == other.bg && underline_color == other.underline_color && modifiers == other.modifiers end
Checks equality with another Cell.
Source
# File lib/ratatui_ruby/cell.rb, line 133 def bold? modifiers.include?("bold") end
Returns true if the cell has the bold modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 173 def crossed_out? modifiers.include?("crossed_out") end
Returns true if the cell has the crossed_out modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 204 def deconstruct_keys(keys) { symbol:, char: symbol, fg:, bg:, underline_color:, modifiers: } end
Support for pattern matching. Supports both :symbol and :char keys.
Source
# File lib/ratatui_ruby/cell.rb, line 138 def dim? modifiers.include?("dim") end
Returns true if the cell has the dim modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 188 def inspect parts = ["symbol=#{symbol.inspect}"] parts << "fg=#{fg.inspect}" if fg parts << "bg=#{bg.inspect}" if bg parts << "underline_color=#{underline_color.inspect}" if underline_color parts << "modifiers=#{modifiers.inspect}" unless modifiers.empty? "#<#{self.class} #{parts.join(' ')}>" end
Returns a string representation of the cell.
Source
# File lib/ratatui_ruby/cell.rb, line 143 def italic? modifiers.include?("italic") end
Returns true if the cell has the italic modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 158 def rapid_blink? modifiers.include?("rapid_blink") end
Returns true if the cell has the rapid_blink modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 163 def reversed? modifiers.include?("reversed") end
Returns true if the cell has the reversed modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 153 def slow_blink? modifiers.include?("slow_blink") end
Returns true if the cell has the slow_blink modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 198 def to_s symbol end
Returns the cellās character.
Source
# File lib/ratatui_ruby/cell.rb, line 148 def underlined? modifiers.include?("underlined") end
Returns true if the cell has the underlined modifier.