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: boolWhether this physical row continues a preceding soft-wrapped row.
Implementations§
Source§impl TerminalLine
impl TerminalLine
Sourcepub fn blank(cols: usize, style: TerminalStyle) -> Self
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());Sourcepub fn len(&self) -> usize
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);Sourcepub fn is_empty(&self) -> bool
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());Sourcepub fn cell(&self, col: usize) -> Option<&TerminalCell>
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());Sourcepub fn cell_mut(&mut self, col: usize) -> Option<&mut TerminalCell>
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");Sourcepub fn clear(&mut self, style: TerminalStyle)
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));Sourcepub fn erase_chars(&mut self, col: usize, count: usize, style: TerminalStyle)
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 ");Sourcepub fn delete_chars(&mut self, col: usize, count: usize, style: TerminalStyle)
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 ");Sourcepub fn insert_blank_chars(
&mut self,
col: usize,
count: usize,
style: TerminalStyle,
)
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");Sourcepub fn resize(&mut self, cols: usize, style: TerminalStyle)
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);Sourcepub fn plain_text(&self) -> String
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
impl Clone for TerminalLine
Source§fn clone(&self) -> TerminalLine
fn clone(&self) -> TerminalLine
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more