pub struct Line { /* private fields */ }Expand description
A list of spans that sit on one terminal line.
The text of a line is the text of its spans, joined. Its Display
prints that text without styles, which suits tests and plain output.
Build one with Line::from(span), or collect spans into it.
Implementations§
Source§impl Line
impl Line
Sourcepub fn push(&mut self, span: Span)
pub fn push(&mut self, span: Span)
Adds span at the end of the line.
A span in the style of the line’s last span joins it. So two lines with the same text and styles are equal, however their spans were pushed.
The start of span can continue the line’s last grapheme cluster, as
a combining mark or the rest of a ZWJ emoji sequence does. Those
characters join the previous span and take its style, because a
terminal cannot style part of a cluster.
So no cluster crosses a span boundary, and every width counts the cluster once. An empty span adds nothing, so none can sit between a cluster’s parts.
Source§impl Line
impl Line
Sourcepub fn truncate(&self, width: u16) -> Self
pub fn truncate(&self, width: u16) -> Self
The line cut to exactly width cells and ended with ELLIPSIS, or
the line itself when it fits.
The text is cut at a cluster boundary. A wide cluster that straddles
the cut is replaced by a space, so a cut line is never narrower than
width. The padding and the ellipsis take the style of the text they
replace. A width of 0 gives an empty line.
Sourcepub fn fit(&self, width: u16, overflow: Overflow) -> Vec<Self>
pub fn fit(&self, width: u16, overflow: Overflow) -> Vec<Self>
The line fitted to width cells by overflow: wrapped into lines for
Overflow::KeepWords and Overflow::Fold, or cut into one line
for Overflow::Ellipsis.
A wrapped line never ends in a space: the spaces at the end of the line
and at each break are dropped. An ellipsis line that fits keeps the
spaces it ends with, as Line::truncate does. Call
trim_end first; Text does this for
you. A width of 0 counts as 1 when wrapping.
Trait Implementations§
impl Eq for Line
Source§impl Extend<Span> for Line
impl Extend<Span> for Line
Source§fn extend<I: IntoIterator<Item = Span>>(&mut self, spans: I)
fn extend<I: IntoIterator<Item = Span>>(&mut self, spans: I)
Source§fn extend_one(&mut self, item: T)
fn extend_one(&mut self, item: T)
extend_one)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)