class RatatuiRuby::Buffer::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/buffer/cell.rb, line 109 def self.char(char) symbol(char) end
Alias for Rubyists who prefer a shorter name.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 84 def self.default empty end
Returns a default cell (alias for empty).
Example
Buffer::Cell.default # => #<RatatuiRuby::Buffer::Cell char=" ">
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 66 def self.empty new(symbol: " ", fg: nil, bg: nil, modifiers: []) end
Returns an empty cell (space character, no styles).
Example
Buffer::Cell.empty # => #<RatatuiRuby::Buffer::Cell char=" ">
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 119 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/buffer/cell.rb, line 104 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
Buffer::Cell.symbol("X") # => #<RatatuiRuby::Buffer::Cell symbol="X">
Public Instance Methods
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 173 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/buffer/cell.rb, line 128 def bold? modifiers.include?("bold") end
Returns true if the cell has the bold modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 168 def crossed_out? modifiers.include?("crossed_out") end
Returns true if the cell has the crossed_out modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 197 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/buffer/cell.rb, line 133 def dim? modifiers.include?("dim") end
Returns true if the cell has the dim modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 182 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/buffer/cell.rb, line 138 def italic? modifiers.include?("italic") end
Returns true if the cell has the italic modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 153 def rapid_blink? modifiers.include?("rapid_blink") end
Returns true if the cell has the rapid_blink modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 158 def reversed? modifiers.include?("reversed") end
Returns true if the cell has the reversed modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 148 def slow_blink? modifiers.include?("slow_blink") end
Returns true if the cell has the slow_blink modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 191 def to_s symbol end
Returns the cellās character.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 143 def underlined? modifiers.include?("underlined") end
Returns true if the cell has the underlined modifier.