Skip to main content

Segment

Struct Segment 

Source
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: bool

Whether this segment carries terminal control codes rather than content.

Implementations§

Source§

impl Segment

Source

pub fn new(text: impl Into<String>, style: Option<Style>) -> Self

A plain content segment.

Source

pub fn line() -> Self

A newline segment (Segment.line() upstream).

Source

pub fn control(text: impl Into<String>) -> Self

A control segment (carries no visible width).

Source

pub fn cell_length(&self) -> usize

The number of terminal cells this segment occupies (0 for control).

Source

pub fn simplify(segments: &[Segment]) -> Vec<Segment>

Merge adjacent segments that share the same style and control flag. Port of Segment.simplify.

Source

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.

Source

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.

Source

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).

Source

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.

Source

pub fn adjust_line_length( line: &[Segment], length: usize, style: Option<Style>, ) -> Vec<Segment>

Pad (with a styled space run) or crop a single line to exactly length cells. Port of Segment.adjust_line_length.

Trait Implementations§

Source§

impl Clone for Segment

Source§

fn clone(&self) -> Segment

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Segment

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Segment

Source§

impl PartialEq for Segment

Source§

fn eq(&self, other: &Segment) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Segment

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.