Struct TerminalLine

Source
pub struct TerminalLine {
    pub cells: Vec<TerminalCell>,
    pub wrapped_from_previous: bool,
}
Expand description

One terminal row with explicit soft-wrap provenance.

Normal constructors keep cells.len() equal to the owning screen width. Public fields and deserialization can bypass that invariant and wide-cell pairing; editing helpers repair only invalid wide markers at row edges.

§Examples

use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
let line = TerminalLine::blank(3, TerminalStyle::default());
assert_eq!((line.len(), line.wrapped_from_previous), (3, false));

Fields§

§cells: Vec<TerminalCell>

Ordered grid cells; normally one per screen column.

§wrapped_from_previous: bool

Whether this physical row continues a preceding soft-wrapped row.

Implementations§

Source§

impl TerminalLine

Source

pub fn blank(cols: usize, style: TerminalStyle) -> Self

Creates cols narrow spaces with identical style and no wrap marker.

Zero columns creates an empty line.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
assert!(TerminalLine::blank(0, TerminalStyle::default()).is_empty());
Source

pub fn len(&self) -> usize

Returns the number of retained cells/columns.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
assert_eq!(TerminalLine::blank(80, TerminalStyle::default()).len(), 80);
Source

pub fn is_empty(&self) -> bool

Returns whether the row retains zero cells.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
assert!(!TerminalLine::blank(1, TerminalStyle::default()).is_empty());
Source

pub fn cell(&self, col: usize) -> Option<&TerminalCell>

Borrows a zero-based cell, or returns None when out of range.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
let line = TerminalLine::blank(2, TerminalStyle::default());
assert!(line.cell(1).is_some() && line.cell(2).is_none());
Source

pub fn cell_mut(&mut self, col: usize) -> Option<&mut TerminalCell>

Mutably borrows a zero-based cell, or returns None when out of range.

Direct mutation can break wide-cell invariants.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
let mut line = TerminalLine::blank(1, TerminalStyle::default());
line.cell_mut(0).unwrap().text = "A".into();
assert_eq!(line.plain_text(), "A");
Source

pub fn clear(&mut self, style: TerminalStyle)

Replaces every retained cell with a styled narrow space and clears the soft-wrap marker without changing line length.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
let mut line = TerminalLine::blank(2, TerminalStyle::default());
line.wrapped_from_previous = true; line.cell_mut(0).unwrap().text = "x".into();
line.clear(TerminalStyle::default());
assert_eq!((line.plain_text(), line.wrapped_from_previous), ("  ".into(), false));
Source

pub fn erase_chars(&mut self, col: usize, count: usize, style: TerminalStyle)

Replaces up to count cells from col with styled narrow spaces.

Zero count, an empty line, or an out-of-range column is a no-op. The operation does not normalize a partially erased wide pair.

§Panics

In debug builds, col + count panics on usize overflow after col has passed bounds validation; optimized builds wrap and may erase no cells. Ordinary terminal-sized counts do not approach this limit.

§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalLine, TerminalStyle};
let style = TerminalStyle::default();
let mut line = TerminalLine { cells: vec![TerminalCell::narrow("a", style), TerminalCell::narrow("b", style)], wrapped_from_previous: false };
line.erase_chars(1, 9, style);
assert_eq!(line.plain_text(), "a ");
Source

pub fn delete_chars(&mut self, col: usize, count: usize, style: TerminalStyle)

Deletes up to count cells at col, shifts the suffix left, and pads the right edge with styled blanks.

Line length is preserved. Zero count and out-of-range columns are no-ops; invalid leading/trailing wide markers at row edges are blanked.

§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalLine, TerminalStyle};
let style = TerminalStyle::default();
let mut line = TerminalLine { cells: "abc".chars().map(|c| TerminalCell::narrow(c.to_string(), style)).collect(), wrapped_from_previous: false };
line.delete_chars(1, 1, style);
assert_eq!(line.plain_text(), "ac ");
Source

pub fn insert_blank_chars( &mut self, col: usize, count: usize, style: TerminalStyle, )

Inserts up to count styled blanks at col, shifts cells right, and discards the same number from the right edge.

Line length is preserved. Zero count and out-of-range columns are no-ops; invalid leading/trailing wide markers at row edges are blanked.

§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalLine, TerminalStyle};
let style = TerminalStyle::default();
let mut line = TerminalLine { cells: "abc".chars().map(|c| TerminalCell::narrow(c.to_string(), style)).collect(), wrapped_from_previous: false };
line.insert_blank_chars(1, 1, style);
assert_eq!(line.plain_text(), "a b");
Source

pub fn resize(&mut self, cols: usize, style: TerminalStyle)

Resizes the row to exactly cols, padding with styled blanks or truncating at the right edge.

Zero is accepted. A leading trailing-half or final leading-half wide marker is blanked after resizing.

§Examples
use ailloli_ui_terminal_core::{TerminalLine, TerminalStyle};
let mut line = TerminalLine::blank(2, TerminalStyle::default());
line.resize(4, TerminalStyle::default());
assert_eq!(line.len(), 4);
Source

pub fn plain_text(&self) -> String

Concatenates cell text while omitting CellWidth::WideTrailing cells.

Spaces and other blank padding are retained; malformed cell text is returned verbatim.

§Examples
use ailloli_ui_terminal_core::{TerminalCell, TerminalLine, TerminalStyle};
let style = TerminalStyle::default();
let line = TerminalLine { cells: vec![TerminalCell::wide_leading("界", style), TerminalCell::wide_trailing(style)], wrapped_from_previous: false };
assert_eq!(line.plain_text(), "界");

Trait Implementations§

Source§

impl Clone for TerminalLine

Source§

fn clone(&self) -> TerminalLine

Returns a copy 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 TerminalLine

Source§

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

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

impl<'de> Deserialize<'de> for TerminalLine

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for TerminalLine

Source§

fn eq(&self, other: &TerminalLine) -> 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 Serialize for TerminalLine

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for TerminalLine

Source§

impl StructuralPartialEq for TerminalLine

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,