Skip to main content

Module text

Module text 

Source
Expand description

Word wrapping that answers a height and a drawing from the same measurement.

The half ratatui’s Paragraph leaves out. A flow layout asks for rows at a width and then draws into the rect it was given, and if the two disagree by one row a node draws over the one under it. Words into cells.

A terminal wraps on words and counts rows, and both halves have to agree or a node draws over the one under it. So the wrap is written once here and both [height] and [draw] read it, rather than each having its own idea of how many rows a paragraph takes.

Arrived here from quasi-tui in 0.16.0, which is where it was written and where it stopped being quasi’s: nothing below is about a described screen. Flow layout is the shape every terminal consumer in the tree ends up with — ask for a height at a width, then draw into the rect you were given — and it needs a wrap that answers both questions the same way. ratatui’s own Paragraph wraps but will not tell you how many rows it took, which is the half a flow layout cannot do without.

Width is counted in chars. That is wrong for a terminal in the general case – a CJK glyph occupies two cells and a combining mark none – and it is deliberately not fixed here: the fix is a unicode-width dependency, and taking one before anything in the tree has non-ASCII content to draw is paying for a problem nobody has yet. Filed rather than hidden.

Functions§

draw
Draw wrapped text at the top of area, and answer the rows it used.
draw_line
Draw a line of spans at the top of area, wrapping onto further rows.
draw_spans
Draw wrapped spans at the top of area, and answer the rows they used.
height
The rows text takes at width.
line_height
The rows a line of spans takes at width.
spans_height
The rows spans take at width, wrapped as a block.
wrap
Break text into lines no wider than width.
wrap_spans
Break spans into lines no wider than width, keeping each word under the style it arrived with.