etui/buffer

Types

pub opaque type Buffer

A diff operation: move cursor to position, write a run of cells.

pub type BufferOp {
  Patch(position: geometry.Position, cells: List(Cell))
}

Constructors

One cell in the terminal grid: a grapheme + colors + modifiers + optional hyperlink.

pub type Cell {
  Cell(
    content: CellContent,
    fg: style.Color,
    bg: style.Color,
    modifier: style.Modifier,
    link: String,
  )
}

Constructors

pub type CellArray

Content variant for a terminal cell.

pub type CellContent {
  Content(symbol: String, width: Int)
  Continuation
}

Constructors

  • Content(symbol: String, width: Int)

    A normal or wide grapheme. width = 1 or 2.

  • Continuation

    Marker for the second cell of a wide grapheme. Never drawn directly.

Values

pub fn area(buf: Buffer) -> geometry.Rect

The rect this buffer covers.

pub fn buffer_new(area: geometry.Rect) -> Buffer

New buffer with given area. All cells start as empty_cell().

pub fn buffer_new_filled(
  area: geometry.Rect,
  row_text: String,
  fg: style.Color,
  bg: style.Color,
  modifier: style.Modifier,
) -> Buffer

Create a buffer with every row pre-filled with row_text. Uses bulk array construction: one pass instead of buffer_new followed by a set_string for every row.

pub fn cell_bg(cell: Cell) -> style.Color

Background color of a cell.

pub fn cell_fg(cell: Cell) -> style.Color

Foreground color of a cell.

pub fn cell_link(cell: Cell) -> String

Accessor: OSC 8 hyperlink URI of a cell (empty = no link).

pub fn cell_modifier(cell: Cell) -> style.Modifier

Text modifier of a cell.

pub fn cell_symbol(cell: Cell) -> String

Symbol string of a cell. Returns “ “ for Continuation cells.

pub fn clear(buffer: Buffer, rect: geometry.Rect) -> Buffer

Clear all cells in a rect (reset to empty_cell).

pub fn continuation_cell(
  fg: style.Color,
  bg: style.Color,
  modifier: style.Modifier,
) -> Cell

Continuation cell (second column of a wide grapheme).

pub fn diff(prev: Buffer, next: Buffer) -> List(BufferOp)

Compute minimal diff between two buffers as a list of patches.

pub fn diff_to_ansi(prev: Buffer, curr: Buffer) -> String

Diff prev against curr and return the minimal ANSI to bring the terminal from prev’s state to curr’s state. On the first frame (or after resize) pass an empty buffer as prev.

pub fn empty_cell() -> Cell

Empty cell (space, default style, no link).

pub fn get_cell(buffer: Buffer, pos: geometry.Position) -> Cell

Get cell at position. Returns empty_cell() for out-of-bounds.

pub fn height(buf: Buffer) -> Int

Height in rows.

pub fn is_continuation(cell: Cell) -> Bool

True if this cell is the second column of a wide grapheme (never rendered directly).

pub fn patches_to_ansi(ops: List(BufferOp)) -> String

Convert a list of BufferOp patches to an ANSI string. Each patch moves the cursor once, then writes a run of cells. Style is tracked across the entire patch list, cursor moves do not reset terminal style, so we avoid redundant escape sequences. Cheaper than to_ansi when only a small fraction of cells changed.

pub fn set_cell(
  buffer: Buffer,
  pos: geometry.Position,
  cell: Cell,
) -> Buffer

Set cell at position. Out-of-bounds writes are ignored.

pub fn set_string(
  buffer: Buffer,
  pos: geometry.Position,
  str: String,
  fg: style.Color,
  bg: style.Color,
  modifier: style.Modifier,
) -> Buffer

Set cells from a string starting at pos. No hyperlink. Wide graphemes (width=2) take one Cell + one Continuation cell.

pub fn set_string_linked(
  buffer: Buffer,
  pos: geometry.Position,
  str: String,
  fg: style.Color,
  bg: style.Color,
  modifier: style.Modifier,
  link: String,
) -> Buffer

Set cells from a string with an OSC 8 hyperlink URI. Pass "" for no link (same as set_string).

pub fn to_ansi(buf: Buffer) -> String

Full-buffer render to an ANSI string. Emits a MoveCursor for every row, then each cell with style transitions only when the style actually changes between adjacent cells. Use for the first frame or after a terminal resize.

pub fn width(buf: Buffer) -> Int

Width in cells.

Search Document