pub struct PrintableText(/* private fields */);Expand description
One line of plain text: a row of cells, every character printable.
This is the unit measurement is defined on — it holds no control
characters at all, not even \n. PrintableLines spans rows and
therefore has no width; a PrintableText is exactly one row, so its cells
come to a single number.
Implementations§
Source§impl PrintableText
impl PrintableText
Sourcepub fn new(text: &str) -> &Self
pub fn new(text: &str) -> &Self
Adopts one line of plain text.
§Panics
In debug builds, panics when text holds any control character, \n
included — a line is one row of cells, so a line break inside it is as
much a contract violation as an escape sequence. Release builds do not
check.
pub fn as_str(&self) -> &str
Sourcepub fn width(&self) -> usize
pub fn width(&self) -> usize
Returns the terminal cells this line occupies.
This is the crate’s one definition of display width: CJK ideographs take two cells, an emoji ZWJ sequence takes two, and a combining mark takes none. Because the receiver is a single line and cannot hold escapes or cursor movement, nothing has to be scanned for or skipped.
The cell rules are defined in one place inside the crate, which is where a measure that depended on the terminal — ambiguous East Asian width resolved as one cell or two — would take its input.
Trait Implementations§
Source§impl Debug for PrintableText
impl Debug for PrintableText
Source§impl PartialEq for PrintableText
impl PartialEq for PrintableText
Source§fn eq(&self, other: &PrintableText) -> bool
fn eq(&self, other: &PrintableText) -> bool
self and other values to be equal, and is used by ==.