etui/text

Types

pub type Alignment {
  Left
  Center
  Right
}

Constructors

  • Left
  • Center
  • Right

Values

pub fn align(
  s: String,
  width: Int,
  alignment: Alignment,
) -> String

Align left/center/right within width cells. Cell-aware.

pub fn cell_width(s: String) -> Int

Cell width of a string (sum of grapheme widths).

pub fn codepoint_cell_width(cp: Int) -> Int

Cell width of a single Unicode codepoint. Returns 0 for control / combining / zero-width, 2 for wide (CJK / emoji / fullwidth), 1 otherwise.

pub fn grapheme_cell_width(g: String) -> Int

Cell width of a single grapheme cluster. Uses the first codepoint’s East Asian Width / emoji classification. Subsequent codepoints in a grapheme (combining, ZWJ, variation selectors) contribute 0, so the first determines the visible cell count.

pub fn graphemes(s: String) -> List(String)

Split a string into grapheme clusters (UAX #29, via Erlang Unicode).

Each element is one user-perceived character: a base letter, a ZWJ sequence, a flag pair, an emoji with modifiers, etc.

graphemes("café") // ["c", "a", "f", "é"]
graphemes("👨‍👩‍👧‍👦") // ["👨‍👩‍👧‍👦"], one cluster
pub fn pad_left(s: String, width: Int) -> String

Pad left with spaces to reach width cells. Cell-aware.

pub fn pad_right(s: String, width: Int) -> String

Pad right with spaces to reach width cells. Cell-aware.

pub fn strip_ansi(s: String) -> String

Strip ANSI escape sequences. Handles CSI (\e[…<final>) and OSC (\e]…ST/\e]…BEL) sequences.

pub fn truncate(
  s: String,
  max_width: Int,
  ellipsis: String,
) -> String

Truncate to max_width cells. Appends ellipsis only if truncation occurs. The ellipsis itself counts toward the budget.

pub fn wrap(s: String, max_width: Int) -> List(String)

Word-wrap to max_width cells. Handles explicit \n newlines. Returns list of lines, each padded to max_width cells.

Search Document