Expand description
Word-wrapping with URL-aware heuristics.
The TUI renders text that frequently contains URLs — command output,
markdown, agent messages, tool-call results. Standard textwrap
hyphenation treats / and - as split points, which breaks URLs
across lines and makes them unclickable in terminal emulators.
This module provides two wrapping paths:
- Standard (
word_wrap_line,word_wrap_lines): delegates totextwrapwith the caller’s options unchanged. Used when the content is known to be plain prose. - Adaptive (
adaptive_wrap_line,adaptive_wrap_lines): inspects the line for URL-like tokens; if any are found, the wrapping keeps URL tokens intact. Mixed URL/prose lines still wrap ordinary prose at word boundaries, only splitting a non-URL token when that token is itself wider than the available row width.
Callers that might encounter URLs should use the adaptive_*
functions. Callers that definitely will not (code blocks, pure
numeric output) can use the standard path for speed.
URL detection is heuristic — see text_contains_url_like for the
rules. False positives suppress hyphenation for that line; false
negatives let a URL get split. The heuristic is intentionally
conservative: file paths like src/main.rs are not matched.
Structs§
Functions§
- adaptive_
wrap_ line - Wraps a single ratatui
Line, automatically switching to URL-preserving options when the line contains a URL-like token. - adaptive_
wrap_ lines - Wraps multiple input lines with URL-aware heuristics, applying
initial_indentto the first line andsubsequent_indentto the rest. Each line is independently checked for URLs; URL detection on one line does not affect wrapping of the others. - line_
contains_ url_ like - Returns
trueif any whitespace-delimited token inlinelooks like a URL. - line_
has_ mixed_ url_ and_ non_ url_ tokens - Returns
trueiflinecontains both a URL-like token and at least one substantive non-URL token. - text_
contains_ url_ like - Returns
trueif any whitespace-delimited token intextlooks like a URL. - url_
preserving_ wrap_ options - Reconfigures wrapping options so that URL-like tokens are never split.
- word_
wrap_ line - word_
wrap_ lines - Wrap a sequence of lines, applying the initial indent only to the very first output line, and using the subsequent indent for all later wrapped pieces.
- word_
wrap_ lines_ borrowed - wrap_
ranges - Returns byte-ranges into
textfor each wrapped line, including trailing whitespace and a +1 sentinel byte. Used by the textarea cursor-position logic. - wrap_
ranges_ trim - Like
wrap_rangesbut returns ranges without trailing whitespace and without the sentinel extra byte. Suitable for general wrapping where trailing spaces should not be preserved.