pub struct Line { /* private fields */ }Expand description
A single line of styled terminal output, composed of Spans.
Each Span carries its own Style, so a single Line can mix colors, bold, italic, etc. ANSI escape codes are emitted only when to_ansi_string is called, keeping the data model free of formatting concerns.
§Construction
use tui::{Line, Style, Color};
// Plain text
let line = Line::new("hello");
// Single color
let line = Line::styled("error", Color::Red);
// Full style
let line = Line::with_style("warning", Style::fg(Color::Yellow).bold());
// Incremental building
let mut line = Line::default();
line.push_text("Name: ");
line.push_styled("Alice", Color::Cyan);§Key methods
push_span(span)— Append aSpan. Merges with the last span if styles match.push_text(text)/push_styled(text, color)/push_with_style(text, style)— Convenience wrappers overpush_span.prepend(text)— Insert unstyled text at the front, inheriting background color or fill style from the line.append_line(other)— Append all spans from anotherLine.display_width()— Width in terminal columns (accounts for Unicode).soft_wrap(width)— Break into multipleLines fitting withinwidthcolumns. Fill metadata is propagated to each wrapped row.to_ansi_string()— Emit the line as an ANSI-escaped string.extend_bg_to_width(target)— Pad with spaces to filltargetcolumns. Ifwith_fillwas called, that color is consumed for the padding; otherwise the existing span background is reused.
§Row fill (deferred padding)
A row can be marked with a fill background that tells later layout stages “extend this row to its containing width with trailing spaces in this color.” Materialization is deferred until either Frame::hstack (per slot width) or VisualFrame::from_frame (per terminal width) needs it. This avoids the trailing-space wrap artifact: a fill-marked row that gets soft-wrapped at a smaller width does not produce phantom rows from the would-be padding spaces.
with_fill(color)— Builder: mark this row as filling its containing width withcolor.set_fill(Option<Color>)— Set or clear the row’s fill background; passNoneto drop existing fill.fill()— Inspect the current fill background asOption<Color>.
Line implements Display for plain-text output (no ANSI codes).
Implementations§
Source§impl Line
impl Line
pub fn new(s: impl Into<String>) -> Self
pub fn styled(text: impl Into<String>, color: Color) -> Self
pub fn with_style(text: impl Into<String>, style: Style) -> Self
pub fn spans(&self) -> &[Span]
pub fn is_empty(&self) -> bool
Sourcepub fn with_fill(self, color: Color) -> Self
pub fn with_fill(self, color: Color) -> Self
Builder: mark this row as filling its containing width with color.
Sourcepub fn set_fill(&mut self, fill: Option<Color>)
pub fn set_fill(&mut self, fill: Option<Color>)
Set or clear this row’s fill background. Pass Some(color) to mark
the row for fill, or None to drop any existing fill metadata.
Sourcepub fn infer_fill_color(&self) -> Option<Color>
pub fn infer_fill_color(&self) -> Option<Color>
The background color this row’s trailing space would be filled with.
Prefers explicit fill metadata, otherwise the first background color
found among the row’s spans, otherwise None. Used by composition
layers (e.g., Frame::fit with with_fill) to decide what background
to extend.
pub fn prepend(self, text: impl Into<String>) -> Self
pub fn push_text(&mut self, text: impl Into<String>)
pub fn push_styled(&mut self, text: impl Into<String>, color: Color)
pub fn push_with_style(&mut self, text: impl Into<String>, style: Style)
pub fn push_span(&mut self, span: Span)
pub fn append_line(&mut self, other: &Line)
pub fn extend_bg_to_width(&mut self, target_width: usize)
pub fn to_ansi_string(&self) -> String
Sourcepub fn display_width(&self) -> usize
pub fn display_width(&self) -> usize
Display width in terminal columns (accounts for unicode widths).
Sourcepub fn soft_wrap(&self, width: u16) -> Vec<Line>
pub fn soft_wrap(&self, width: u16) -> Vec<Line>
Soft-wrap this line to fit within width columns.
pub fn plain_text(&self) -> String
Trait Implementations§
impl Eq for Line
impl StructuralPartialEq for Line
Auto Trait Implementations§
impl Freeze for Line
impl RefUnwindSafe for Line
impl Send for Line
impl Sync for Line
impl Unpin for Line
impl UnsafeUnpin for Line
impl UnwindSafe for Line
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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more