etui/span

Types

A single terminal row composed of styled spans.

pub type Line {
  Line(spans: List(Span), alignment: text.Alignment)
}

Constructors

A styled text fragment: string content + display style + optional hyperlink.

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

Constructors

Values

pub fn line_aligned(
  spans: List(Span),
  alignment: text.Alignment,
) -> Line

Line from spans with explicit alignment.

pub fn line_new(spans: List(Span)) -> Line

Line from a list of spans, left-aligned.

pub fn line_plain(content: String) -> Line

Line with a single unstyled string, left-aligned.

pub fn line_width(l: Line) -> Int

Total cell width of a line (sum of span widths).

pub fn render_line(
  buf: buffer.Buffer,
  pos: geometry.Position,
  l: Line,
  max_width: Int,
) -> buffer.Buffer

Render a line into the buffer at pos, clipped to max_width cells. Each span is drawn with its own fg/bg/modifier. Spans beyond max_width are silently dropped; a span that straddles the boundary is truncated. The line’s alignment field shifts the start position within the available width.

pub fn span_bg(sp: Span, color: style.Color) -> Span

Set background color on a span.

pub fn span_bold(content: String) -> Span

Bold span (default colors + bold modifier).

pub fn span_dim(content: String) -> Span

Dim span (default colors + dim modifier).

pub fn span_fg(sp: Span, color: style.Color) -> Span

Set foreground color on a span.

pub fn span_italic(content: String) -> Span

Italic span (default colors + italic modifier).

pub fn span_link(content: String, uri: String) -> Span

Span with an OSC 8 clickable hyperlink. Terminals that support OSC 8 (iTerm2, Kitty, VTE, Windows Terminal) will render the text as a clickable link. Others display it as plain text.

span.span_link("docs.gleam.run", "https://docs.gleam.run")
pub fn span_modifier(sp: Span, modifier: style.Modifier) -> Span

Add a modifier to a span.

pub fn span_plain(content: String) -> Span

Span with default terminal colors and no modifier.

pub fn span_styled(content: String, s: style.Style) -> Span

Span with explicit style applied.

pub fn span_underline(content: String) -> Span

Underline span (default colors + underline modifier).

pub fn span_width(sp: Span) -> Int

Total cell width of a span.

pub fn with_link(sp: Span, uri: String) -> Span

Add an OSC 8 hyperlink URI to an existing span.

Search Document