Text
Show styled, wrapped, and truncated text, and keep escape sequences from text you did not write away from the terminal.
bloom.Text(s) is how a plain string goes into a layout. It keeps the string's ANSI styles and hyperlinks, wraps and
fills with a Lip Gloss style, or stays on one line and is cut short with "…". It also keeps escape sequences in text
you didn't write from reaching the terminal.
Show text
bloom.Text(s) shows a string, which may already contain ANSI styles. On its own it's drawn as is, and clipped
to the space it's given. Give it a Lip Gloss style with Style and it's rendered at the size of its node instead,
so long lines wrap and a background fills the whole node. See TextNode.Style:
bloom.Text(body) // clipped
bloom.Text(body).Style(lipgloss.NewStyle().Padding(0, 1)) // wraps inside 1 column of padding
bloom.Text(title).Style(lipgloss.NewStyle().Background(highlight)) // background fills the nodeA width or height set on the style itself is kept, so Style(s.Width(20)) is 20 columns wide wherever it's
placed.
Keep text on one line
Truncate shows a single line, turning newlines into spaces and cutting the text short with "…" when it doesn't
fit. Padding and borders count against the width. It's what you want for status bars, titles, and list items:
bloom.Text(path).Style(statusStyle).Truncate()a long line…With tooltips on, text that was cut shows the rest of it as a tooltip. Add NoTooltip() to turn
that off, or call m.ui.Frame().Truncated(id) to see whether a node was cut.
For text that should scroll rather than be cut short, such as a long title in a focused list item, see
Marquee.
Plain strings and components
Anything with a View() string method can go in a layout, including your own components and
Bubbles. Text is for plain strings.
Text from outside your program
A string can hold escape sequences that go to the terminal as they are instead of being drawn, such as an image
drawn with the Kitty graphics protocol or sixel. Text and Viewport drop them, along with any other sequence
that isn't a style or a hyperlink, so a log, a file, or a message you didn't write can't send commands to the
terminal. When you made all of the text yourself and it holds an image (an APC, DCS, SOS, or PM command), mark it
trusted to keep those:
bloom.Text(picture).Trusted()
bloom.Viewport(buf).Trusted()A component's view is drawn as it is, commands included, since that's how a component shows an image. If a
component shows text from outside your program, clean the text first with
canvas.Sanitize, or show it in a Text or
Viewport instead.
Related
TextNodeAPI reference- Selecting and copying text, Mouse events, and Tooltips,
which work on
Texttoo - Borders, to draw a box around text
- Lip Gloss, for the styles themselves
Last updated on
Responsive layouts
Adapt a layout to the terminal's size by collapsing panels by priority, using percentages, building layouts for the space a component is given, and showing a note when the window is too small.
Boxes and borders
Draw Lip Gloss borders around nodes, put titles, tabs, and buttons on them, join lines to them, and animate them.