pub struct Segment {
pub text: String,
pub style: Option<Style>,
pub control: bool,
}Expand description
A span of text with an optional style. Mirrors rich.segment.Segment.
Fields§
§text: String§style: Option<Style>§control: boolWhether this segment carries terminal control codes rather than content.
Implementations§
Source§impl Segment
impl Segment
Sourcepub fn cell_length(&self) -> usize
pub fn cell_length(&self) -> usize
The number of terminal cells this segment occupies (0 for control).
Sourcepub fn simplify(segments: &[Segment]) -> Vec<Segment>
pub fn simplify(segments: &[Segment]) -> Vec<Segment>
Merge adjacent segments that share the same style and control flag.
Port of Segment.simplify.
Sourcepub fn apply_style(segments: &[Segment], style: &Style) -> Vec<Segment>
pub fn apply_style(segments: &[Segment], style: &Style) -> Vec<Segment>
Apply style as a base under each segment’s own style (that segment’s
style wins on top). Control segments are left untouched. Port of
Segment.apply_style (the style-only path).
Line-break segments ("\n") are also left unstyled: upstream’s
line-oriented print pipeline re-emits row separators plain, so styling
them would add stray SGR runs around every newline.
Sourcepub fn split_lines(segments: &[Segment]) -> Vec<Vec<Segment>>
pub fn split_lines(segments: &[Segment]) -> Vec<Vec<Segment>>
Split a flat segment stream into lines, breaking on \n.
Port of Segment.split_lines. Newline characters are consumed (not kept
in the output); a trailing newline yields a final empty line only if
there was content after the last break.
Sourcepub fn set_shape(
lines: Vec<Vec<Segment>>,
width: usize,
height: usize,
) -> Vec<Vec<Segment>>
pub fn set_shape( lines: Vec<Vec<Segment>>, width: usize, height: usize, ) -> Vec<Vec<Segment>>
Shape a set of lines into exactly height rows of width cells: crop
extra rows, pad each row to width, and append blank rows to reach
height. Port of Segment.set_shape (style=None, new_lines=False).
Sourcepub fn fold_lines_words(segments: &[Segment], width: usize) -> Vec<Segment>
pub fn fold_lines_words(segments: &[Segment], width: usize) -> Vec<Segment>
Fold every line to at most width cells, breaking at word boundaries
the way upstream’s word wrapping does.
fold_lines breaks wherever the row happens to fill
up, which splits identifiers and words mid-character-run
(epsilon, z / eta, eta, theta)). Upstream’s word_wrap=True routes
through _wrap.divide_line, which we already port for Text — this
applies the same break offsets to a styled segment run, so styles survive
the split.
A word longer than width is still folded mid-word; there is nowhere
else to break it.
Sourcepub fn fold_lines(segments: &[Segment], width: usize) -> Vec<Segment>
pub fn fold_lines(segments: &[Segment], width: usize) -> Vec<Segment>
Fold every line to at most width cells, carrying the overflow onto
continuation lines instead of discarding it.
crop_lines is the display backstop and throws the
remainder away — correct for a renderable that has already wrapped
itself, and data loss for one that emits a long line verbatim. Styles are
preserved across the split.
This breaks wherever the row happens to fill up, so it splits words. That
is right only for content upstream folds without word wrapping. A
renderable whose upstream counterpart goes through Text.wrap wants
fold_lines_words instead: reaching for this
one is what made --json print over t / he lazy where rich prints
over / the lazy.
Sourcepub fn crop_lines(segments: &[Segment], width: usize) -> Vec<Segment>
pub fn crop_lines(segments: &[Segment], width: usize) -> Vec<Segment>
Crop every line in a segment stream to at most width cells, discarding
the excess and leaving short lines alone.
Port of Segment.split_and_crop_lines with pad=False, which is what
Console.print(crop=True) applies to the finished stream. It is the only
thing standing between an Overflow::Ignore
text and a line that runs off the side of the terminal.
Control segments occupy no cells and are always kept, so cursor moves and hyperlink codes survive a crop.
Trait Implementations§
impl Eq for Segment
impl StructuralPartialEq for Segment
Auto Trait Implementations§
impl Freeze for Segment
impl RefUnwindSafe for Segment
impl Send for Segment
impl Sync for Segment
impl Unpin for Segment
impl UnsafeUnpin for Segment
impl UnwindSafe for Segment
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.