pub struct StyledText<'a> { /* private fields */ }Expand description
Parsed semantic style text that can be measured or selected without converting the whole value to plain text.
The parser keeps style tags out of the visible character stream. Selecting
one or more character ranges preserves the styles that cover each range and
closes every emitted tag, including when a range ends inside nested tags.
ANSI controls recognized by console::strip_ansi_codes are likewise
zero-width and are preserved when their position falls inside a selection.
Implementations§
Source§impl<'a> StyledText<'a>
impl<'a> StyledText<'a>
Sourcepub fn parse(input: &'a str) -> Self
pub fn parse(input: &'a str) -> Self
Parses semantic style tags while retaining the original tagged source.
Balanced tags form zero-width style events. Invalid, unexpected, or
unbalanced tag syntax remains visible literal text, matching
BBParser behavior.
Sourcepub fn visit_visible_chars(&self, visitor: impl FnMut(char))
pub fn visit_visible_chars(&self, visitor: impl FnMut(char))
Visits each visible character in rendered order.
Style tag bytes are never visited. Escaped brackets are visited as the single literal bracket they render as.
Sourcepub fn select(&self, ranges: &[Range<usize>], separator: &str) -> String
pub fn select(&self, ranges: &[Range<usize>], separator: &str) -> String
Renders selected visible-character ranges with balanced semantic tags.
Ranges use character offsets from Self::visit_visible_chars. Each
range is rendered as a self-contained balanced fragment. separator is
inserted outside styling between non-empty ranges.
Sourcepub fn select_range(&self, range: Range<usize>) -> String
pub fn select_range(&self, range: Range<usize>) -> String
Render one visible character range as a balanced styled fragment.
The range uses character offsets from Self::visit_visible_chars.
Trait Implementations§
Source§impl<'a> Clone for StyledText<'a>
impl<'a> Clone for StyledText<'a>
Source§fn clone(&self) -> StyledText<'a>
fn clone(&self) -> StyledText<'a>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more