TermUI.Renderer.Cell (TermUI v0.2.0)
View SourceRepresents a single cell in the terminal screen buffer.
A cell contains a character (grapheme cluster), foreground and background colors, and style attributes. Cells are immutable - updates create new cells, enabling efficient diffing by reference comparison.
Color Types
Colors can be specified as:
:default- Terminal default color- Atom - Named color (
:red,:green,:blue, etc.) - Integer 0-255 - 256-color palette index
{r, g, b}tuple - True color RGB values (0-255 each)
Attributes
Supported style attributes:
:bold- Bold/bright text:dim- Dimmed text:italic- Italic text:underline- Underlined text:blink- Blinking text:reverse- Reversed colors:hidden- Hidden text:strikethrough- Strikethrough text
Summary
Functions
Adds an attribute to the cell.
Returns an empty cell with default styling.
Checks if a cell is empty (space with default styling).
Compares two cells for equality.
Checks if the cell has a specific attribute.
Returns list of valid color names.
Creates a new cell with the given character and optional styling.
Returns a cell with updated background color.
Returns a cell with updated character.
Returns a cell with updated foreground color.
Removes an attribute from the cell.
Returns list of valid attributes.
Returns true if this cell is a wide (double-width) character.
Creates a placeholder cell for the second column of a wide character.
Returns true if this cell is a wide character placeholder.
Returns the display width of a cell (1 or 2).
Types
@type attribute() ::
:bold
| :dim
| :italic
| :underline
| :blink
| :reverse
| :hidden
| :strikethrough
@type color() :: :default | atom() | 0..255 | {0..255, 0..255, 0..255}
Functions
Adds an attribute to the cell.
@spec empty() :: t()
Returns an empty cell with default styling.
An empty cell contains a space character with default colors and no attributes.
Examples
iex> Cell.empty()
%Cell{char: " ", fg: :default, bg: :default, attrs: MapSet.new()}
Checks if a cell is empty (space with default styling).
Examples
iex> Cell.empty?(Cell.empty())
true
iex> Cell.empty?(Cell.new("A"))
false
Compares two cells for equality.
Returns true if both cells have the same character, colors, and attributes.
Used by the diff algorithm to identify changed cells.
Examples
iex> Cell.equal?(Cell.empty(), Cell.empty())
true
iex> Cell.equal?(Cell.new("A"), Cell.new("B"))
false
Checks if the cell has a specific attribute.
@spec named_colors() :: [atom()]
Returns list of valid color names.
Creates a new cell with the given character and optional styling.
Examples
iex> Cell.new("A")
%Cell{char: "A", fg: :default, bg: :default, attrs: MapSet.new()}
iex> Cell.new("X", fg: :red, attrs: [:bold])
%Cell{char: "X", fg: :red, bg: :default, attrs: MapSet.new([:bold])}
Returns a cell with updated background color.
Returns a cell with updated character.
Examples
iex> cell = Cell.new("A", fg: :red)
iex> Cell.put_char(cell, "B")
%Cell{char: "B", fg: :red, bg: :default, attrs: MapSet.new()}
Returns a cell with updated foreground color.
Removes an attribute from the cell.
@spec valid_attributes() :: [attribute()]
Returns list of valid attributes.
Returns true if this cell is a wide (double-width) character.
Creates a placeholder cell for the second column of a wide character.
This cell inherits the styling from the primary cell but renders as empty.
Returns true if this cell is a wide character placeholder.
@spec width(t()) :: non_neg_integer()
Returns the display width of a cell (1 or 2).