Skip to main content

Line

Struct Line 

Source
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 a Span. Merges with the last span if styles match.
  • push_text(text) / push_styled(text, color) / push_with_style(text, style) — Convenience wrappers over push_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 another Line.
  • display_width() — Width in terminal columns (accounts for Unicode).
  • soft_wrap(width) — Break into multiple Lines fitting within width columns. 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 fill target columns. If with_fill was 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 with color.
  • set_fill(Option<Color>) — Set or clear the row’s fill background; pass None to drop existing fill.
  • fill() — Inspect the current fill background as Option<Color>.

Line implements Display for plain-text output (no ANSI codes).

Implementations§

Source§

impl Line

Source

pub fn new(s: impl Into<String>) -> Self

Source

pub fn styled(text: impl Into<String>, color: Color) -> Self

Source

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

Source

pub fn spans(&self) -> &[Span]

Source

pub fn is_empty(&self) -> bool

Source

pub fn fill(&self) -> Option<Color>

Returns this row’s fill background, if any.

Source

pub fn with_fill(self, color: Color) -> Self

Builder: mark this row as filling its containing width with color.

Source

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.

Source

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.

Source

pub fn prepend(self, text: impl Into<String>) -> Self

Source

pub fn push_text(&mut self, text: impl Into<String>)

Source

pub fn push_styled(&mut self, text: impl Into<String>, color: Color)

Source

pub fn push_with_style(&mut self, text: impl Into<String>, style: Style)

Source

pub fn push_span(&mut self, span: Span)

Source

pub fn append_line(&mut self, other: &Line)

Source

pub fn extend_bg_to_width(&mut self, target_width: usize)

Source

pub fn to_ansi_string(&self) -> String

Source

pub fn display_width(&self) -> usize

Display width in terminal columns (accounts for unicode widths).

Source

pub fn soft_wrap(&self, width: u16) -> Vec<Line>

Soft-wrap this line to fit within width columns.

Source

pub fn plain_text(&self) -> String

Trait Implementations§

Source§

impl Clone for Line

Source§

fn clone(&self) -> Line

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Line

Source§

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

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

impl Default for Line

Source§

fn default() -> Line

Returns the “default value” for a type. Read more
Source§

impl Display for Line

Source§

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

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

impl PartialEq for Line

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for Line

Source§

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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more