struct Termisu::Cell

Overview

Cell represents a single character cell in the terminal buffer.

Cell contains:

Grapheme and Continuation Cells

Wide characters (CJK, emoji) occupy 2 columns. The Cell model represents this:

Example:

# Leading cell for "中" (width auto-calculated as 2)
lead = Termisu::Cell.new("中")
lead.grapheme      # => "中"
lead.width         # => 2
lead.continuation? # => false

# Trailing continuation cell
trail = Termisu::Cell.continuation
trail.grapheme      # => ""
trail.width         # => 0
trail.continuation? # => true

Compatibility (Public API)

The #grapheme property provides backward-compatible access:

cell = Termisu::Cell.new("ABC")
cell.grapheme # => "A" (first grapheme of input-String is stored)

continuation = Termisu::Cell.continuation
continuation.grapheme # => "" (empty for continuation cells)

Defined in:

termisu/cell.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(grapheme : String = " ", continuation : Bool = false, fg : Color = Color.white, bg : Color = Color.default, attr : Attribute = Attribute::None) #

Creates a new Cell with the specified grapheme and colors.

Parameters:

  • grapheme: Unicode grapheme cluster to display (if multi-grapheme string is passed, only the first grapheme cluster is stored)
  • continuation: True if this is a trailing cell of a wide grapheme
  • fg: Foreground color (default: white)
  • bg: Background color (default: default terminal color)
  • attr: Text attributes (default: None)

Note: Width is derived from grapheme content to ensure consistency. Continuation cells always have empty grapheme and width 0.

Occupancy invariants enforced:

  • Continuation cells: always empty grapheme, width 0
  • Empty non-continuation: normalized to default space cell (width 1)
  • Leading cells: width derived via grapheme_width (handles VS16, ZWJ, flags)
  • Multi-grapheme strings: only first grapheme is stored; debug log warns of truncation

[View source]

Class Method Detail

def self.continuation #

Continuation cells represent the trailing column occupied by a wide character. They have empty grapheme, width 0, and are never rendered directly.

trail = Termisu::Cell.continuation
trail.continuation? # => true
trail.width         # => 0
trail.grapheme      # => ""

[View source]
def self.default #

default empty cell (space with default colors, width 1, not continuation).


[View source]

Instance Method Detail

def attr : Attribute #

[View source]
def attr=(attr : Attribute) #

[View source]
def bg : Color #

[View source]
def bg=(bg : Color) #

[View source]
def continuation? : Bool #

[View source]
def default_state? : Bool #

Returns true when this cell is the canonical default blank cell.

Used by Buffer hot paths (clear/dirtiness accounting) to avoid expensive full-buffer work when rows are already blank.


[View source]
def fg : Color #

[View source]
def fg=(fg : Color) #

[View source]
def grapheme : String #

[View source]
def grapheme=(grapheme : String) #

[View source]
def width : UInt8 #

[View source]