etui/span
Types
A single terminal row composed of styled spans.
pub type Line {
Line(spans: List(Span), alignment: text.Alignment)
}
Constructors
-
Line(spans: List(Span), alignment: text.Alignment)
A styled text fragment: string content + display style + optional hyperlink.
pub type Span {
Span(content: String, style: style.Style, link: String)
}
Constructors
-
Span(content: String, style: style.Style, link: String)Arguments
- link
-
OSC 8 hyperlink URI. Empty string = no link.
Several lines of styled text.
Line is one row and never wraps; Text is a block that does. Until this
existed, wrapping only worked on a plain String, so any text that needed
both mixed styles and reflowing, a log viewer or rendered markdown, could
not have both.
pub type Text {
Text(lines: List(Line))
}
Constructors
-
Text(lines: List(Line))
Values
pub fn line_aligned(
spans: List(Span),
alignment: text.Alignment,
) -> Line
Line from spans with explicit alignment.
pub fn line_plain(content: String) -> Line
Line with a single unstyled string, left-aligned.
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_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_underline_color(sp: Span, color: style.Color) -> Span
Colour the underline of a span independently of its text.
pub fn text_plain(content: String) -> Text
Text from a single unstyled string, split on newlines.
pub fn wrap(t: Text, width: Int) -> Text
Wrap every line to width cells, keeping each span’s style.
span.line_new([span.span_bold("ERROR"), span.span_plain(" disk full")])
|> span.text_new([_])
|> span.wrap(12)
// ERROR disk <- still bold
// full
pub fn wrap_line(l: Line, width: Int) -> List(Line)
Wrap one line into as many as it takes.
Words are the unit, as in text.wrap, and a word wider than the line is
broken across rows rather than left to overflow. A word never loses its
style by being moved to another row, which is the whole point: the styles
travel with the words rather than with the columns they happened to be in.