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.
The underline color of the cell.
Distinct from foreground color. Some terminals support colored underlines.
Public Class Methods
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 114 def self.char(char) symbol(char) end
Alias for Rubyists who prefer a shorter name.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 89 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 71 def self.empty new(symbol: " ", fg: nil, bg: nil, underline_color: 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 126 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 { |m| m.respond_to?(:to_sym) ? m.to_sym : m.to_s.to_sym }.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,
Symbols, or any object responding to to_sym or to_s. Normalized toSymbolsfor consistent output.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 109 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
Buffer::Cell.symbol("X") # => #<RatatuiRuby::Buffer::Cell symbol="X">
Public Instance Methods
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 181 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/buffer/cell.rb, line 136 def bold? modifiers.include?(:bold) end
Returns true if the cell has the bold modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 176 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 207 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/buffer/cell.rb, line 141 def dim? modifiers.include?(:dim) end
Returns true if the cell has the dim modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 191 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/buffer/cell.rb, line 146 def italic? modifiers.include?(:italic) end
Returns true if the cell has the italic modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 161 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 166 def reversed? modifiers.include?(:reversed) end
Returns true if the cell has the reversed modifier.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 156 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 201 def to_s symbol end
Returns the cellās character.
Source
# File lib/ratatui_ruby/buffer/cell.rb, line 151 def underlined? modifiers.include?(:underlined) end
Returns true if the cell has the underlined modifier.