Skip to main content

Module wrap

Module wrap 

Source
Expand description

Character-exact line wrapping primitives.

These back both a panel’s rendering (turning one raw line into the wrapped rows actually shown) and its selection geometry (mapping between logical positions and on-screen rows) — see crate::wrapcache. Wrapping is character-exact (not word-aware): a line is broken every width display columns, matching how a raw HTTP response body or JSON preview is displayed.

Functions§

wrap_line
Wrap a (possibly multi-span, styled) Line to width columns, breaking exactly on the character boundary and preserving each span’s style across the break. width == 0 returns the line unchanged.
wrap_line_window
Wrap only a bounded window of a single (unstyled) line — skip skip_rows whole wrapped rows, then wrap at most max_rows more, without ever touching or allocating the rest of the line. Unlike wrap_line, whose cost is proportional to the entire line, this keeps cost proportional to (skip_rows + max_rows) * width — critical for panels holding one enormous raw line (e.g. a large base64 blob or minified JSON body pasted with no newlines), where re-wrapping the whole line on every redraw would grind the app to a halt regardless of how few rows are actually on screen.
wrapped_row_count
Number of wrapped rows a line of char_len characters produces at width display columns, matching wrap_line’s own boundary math exactly (one row minimum, even for an empty line). Used to size the total scrollable extent and locate a scroll position without ever wrapping every line.