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 list of active modifiers (e.g., [“bold”, “italic”]).
The character displayed in the cell.
Named to match Ratatui’s Cell::symbol() method.
Public Class Methods
Source
# File lib/ratatui_ruby/cell.rb, line 74 def self.char(char) symbol(char) end
Alias for Rubyists who prefer a shorter name.
Source
# File lib/ratatui_ruby/cell.rb, line 57 def self.default empty end
Source
# File lib/ratatui_ruby/cell.rb, line 47 def self.empty new(symbol: " ", fg: nil, bg: 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 84 def initialize(symbol: nil, char: nil, fg: nil, bg: nil, modifiers: []) @symbol = symbol || char || " " @fg = fg @bg = bg @modifiers = modifiers.freeze freeze end
Creates a new Cell.
- symbol
-
String (single character). Aliased as
char:. - fg
-
Symbol or String (nullable).
- bg
-
Symbol or String (nullable).
- modifiers
-
Array of Strings.
Source
# File lib/ratatui_ruby/cell.rb, line 69 def self.symbol(symbol) new(symbol: symbol, fg: nil, bg: 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 138 def ==(other) other.is_a?(Cell) && char == other.char && fg == other.fg && bg == other.bg && modifiers == other.modifiers end
Checks equality with another Cell.
Source
# File lib/ratatui_ruby/cell.rb, line 93 def bold? modifiers.include?("bold") end
Returns true if the cell has the bold modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 133 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 162 def deconstruct_keys(keys) { symbol: symbol, char: symbol, fg: fg, bg: bg, modifiers: modifiers } end
Support for pattern matching. Supports both :symbol and :char keys.
Source
# File lib/ratatui_ruby/cell.rb, line 98 def dim? modifiers.include?("dim") end
Returns true if the cell has the dim modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 147 def inspect parts = ["symbol=#{symbol.inspect}"] parts << "fg=#{fg.inspect}" if fg parts << "bg=#{bg.inspect}" if bg 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 103 def italic? modifiers.include?("italic") end
Returns true if the cell has the italic modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 118 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 123 def reversed? modifiers.include?("reversed") end
Returns true if the cell has the reversed modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 113 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 156 def to_s symbol end
Returns the cell’s character.
Source
# File lib/ratatui_ruby/cell.rb, line 108 def underlined? modifiers.include?("underlined") end
Returns true if the cell has the underlined modifier.