Skip to content

v0.3.0: styled text spans

Latest

Choose a tag to compare

@ralyodio ralyodio released this 08 Sep 14:29
0605c5a

A line can carry more than one colour.

ui.text([
  { text: "ERROR ", fg: theme.danger, bold: true },
  { text: "connection refused" },
]);

Added

  • Span, SpanLine and RichText, plus Surface.spans() for drawing them.
  • Span-aware measuring, truncation, padding and word wrap: spanWidth, truncateSpans, fitSpans, wrapSpans, wrapRich, toSpanLines, spanStyle, spanText, isRich.
  • drawText and ui.text / ui.label / ui.heading accept RichText wherever they took a string.

Compatibility

A bare string is the one-span case, so no existing call site changes and no committed frame moves. Both fixture generators regenerate byte for byte, and the six native ports stay in parity — they simply do not offer spans yet.

The span layout is held to the exact output of the string functions it mirrors: truncateSpans, fitSpans and wrapSpans produce the same columns as truncate, fit and wrap across a corpus of CJK, emoji, ZWJ sequences, combining marks and overlong tokens at eight widths.

232 tests pass under Bun and Node.