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 108 def self.char(char) symbol(char) end
Alias for Rubyists who prefer a shorter name.
Source
# File lib/ratatui_ruby/cell.rb, line 83 def self.default empty end
Source
# File lib/ratatui_ruby/cell.rb, line 65 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 118 def initialize(symbol: nil, char: nil, fg: nil, bg: nil, modifiers: []) @symbol = (symbol || char || " ").freeze @fg = fg&.freeze @bg = bg&.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).
- modifiers
-
Array of Strings.
Source
# File lib/ratatui_ruby/cell.rb, line 103 def self.symbol(symbol) new(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 172 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 127 def bold? modifiers.include?("bold") end
Returns true if the cell has the bold modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 167 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 196 def deconstruct_keys(keys) { symbol:, char: symbol, fg:, bg:, modifiers: } end
Support for pattern matching. Supports both :symbol and :char keys.
Source
# File lib/ratatui_ruby/cell.rb, line 132 def dim? modifiers.include?("dim") end
Returns true if the cell has the dim modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 181 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 137 def italic? modifiers.include?("italic") end
Returns true if the cell has the italic modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 152 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 157 def reversed? modifiers.include?("reversed") end
Returns true if the cell has the reversed modifier.
Source
# File lib/ratatui_ruby/cell.rb, line 147 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 190 def to_s symbol end
Returns the cellās character.
Source
# File lib/ratatui_ruby/cell.rb, line 142 def underlined? modifiers.include?("underlined") end
Returns true if the cell has the underlined modifier.