Skip to main content

Module wrapping

Module wrapping 

Source
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 to textwrap with 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§

RtOptions

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_indent to the first line and subsequent_indent to 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 true if any whitespace-delimited token in line looks like a URL.
line_has_mixed_url_and_non_url_tokens
Returns true if line contains both a URL-like token and at least one substantive non-URL token.
text_contains_url_like
Returns true if any whitespace-delimited token in text looks 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 text for each wrapped line, including trailing whitespace and a +1 sentinel byte. Used by the textarea cursor-position logic.
wrap_ranges_trim
Like wrap_ranges but returns ranges without trailing whitespace and without the sentinel extra byte. Suitable for general wrapping where trailing spaces should not be preserved.