pub struct Text(/* private fields */);Expand description
Sanitized, display-safe text.
Constructing a Text always goes through Text::sanitize (directly, or
indirectly via Deserialize), which strips control characters and
terminal escape sequences, resolves backspace-overstrike, expands tabs,
collapses whitespace runs, normalizes newlines (preserving paragraph
breaks), and truncates to MAX_TEXT_CHARS. Widgets and other consumers
may assume a Text is safe to place directly into a rendering surface.
Implementations§
Source§impl Text
impl Text
Sourcepub fn sanitize(raw: &str) -> Text
pub fn sanitize(raw: &str) -> Text
The only way to build a Text from raw, untrusted input.
Pipeline (see spec §4.1 and §13.3 for the adversarial cases this must survive):
- Strip ANSI/OSC/other terminal escape sequences.
- Resolve backspace-overstrike (
_\bX,X\bX, and any stray\b). - Strip remaining C0 control characters and DEL.
- Expand tabs to spaces at 8-column stops.
- Normalize line endings to
\n. - Unwrap hard-wrapped paragraphs: a single
\ninside a paragraph joins to a space (so a later re-wrap at the pane’s actual width produces clean lines instead of re-wrapping already-short, pre-broken lines raggedly);\n\nstays a paragraph break; indented/code-like lines and list items (-,*,1.) are never joined to a neighbor, preserving block structure. - Collapse runs of horizontal whitespace to a single space.
- Trim leading/trailing whitespace.
- Truncate to
MAX_TEXT_CHARScharacters, at a char boundary.
Sourcepub fn sanitize_markdown(raw: &str) -> Text
pub fn sanitize_markdown(raw: &str) -> Text
Like Text::sanitize, but for text known to originate as
markdown-flavored prose (carapace-spec’s description/
documentation fields, which use [label](uri) links — including
custom schemes like man:// and cmd:// — plus inline code,
**bold**, and *em*/_em_ markers).
This is a conservative, targeted normalizer, not a general markdown
parser: it recognizes exactly those four constructs and leaves
anything else untouched. In particular it does not touch [value]
usage-string brackets (no following (...)), and it requires
non-word characters immediately outside *em*/_em_ delimiters so
it doesn’t misfire on identifiers like GIT_DIR or globs.
Recognized markup is replaced with its inner text; the surrounding
URI/delimiters are discarded (plain-text fallback, since the detail
pane doesn’t yet render hyperlinks).
Sourcepub fn single_line(&self) -> String
pub fn single_line(&self) -> String
Collapse to a single display line (paragraph breaks and internal newlines become a single space), for contexts like tree rows that have no room for multi-line text. The tree pane is expected to call this at render time rather than store a second copy of the text.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Text
impl<'de> Deserialize<'de> for Text
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialization re-runs Text::sanitize rather than trusting the
stored bytes verbatim. This keeps the invariant airtight even when a
Text is round-tripped through the on-disk cache (spec §11): a
tampered or corrupted cache file cannot smuggle unsanitized bytes
back into the IR. sanitize is idempotent, so this costs nothing
extra for cache entries that were already clean.