Struct text_terminal::Unit

source ·
pub struct Unit { /* private fields */ }
Expand description

A Unit is a single character block displayed in the terminal.

Some terminal emulators call this structure a cell, but this is different from the concept of a cell because it may contain more than just a single displayable character, in order to support complex Unicode/emoji.

1-to-1 Relationship between Units and Columns

It is guaranteed that one Unit in the scrollback buffer corresponds to exactly one screen column, which makes it easy to calculate the conversions between screen cursor coordinate points and scrollback buffer coordinate points. For example, if the screen is 80 columns wide, a Line with 120 units will display across exactly 1.5 lines, displaying right up to the 40th column of the second row.

Because a complex Unicode character may require more than one column to display, such as a tab or emoji sequence, there are flags in a Unit that indicate whether it is part of a wider display character sequence. There are flags for both the beginning unit and all of the placeholder units that follow it (which exist solely to satisfy the 1-to-1 relationship between screen columns and scrollback buffer units). Thus, it is easy to determine where multi-column Unit sequences start and end.

Wide-display character sequences like tabs and emoji are always stored completely in the starting Unit (as a Character::Multi variant), with the following placeholder Units containing a default empty Character::Single with the null character within it. This conveniently allows the screen cursor to store a single Unit object within it that represents the entirety of that displayable Unit, instead of more complex storage strategy that splits up wide character sequences into multiple Units.

What Units are Not

Displayable control/escape sequences, i.e., those that affect text style, do not exist as individual Units, though their effects on text style are represented by a Unit’s FormatFlags.

Non-displayable control/escape sequences, i.e., bells, backspace, delete, etc, are NOT saved as Units in the terminal’s scrollback buffer, as they cannot be displayed and are simply transient actions.

Methods from Deref<Target = Character>§

source

pub fn displayable_width(&self) -> u16

Returns the number of columns required to display this Character within a Unit, either a single char or a String.

A return value of 0 indicates this Unit requires special handling to determine its displayable width. This includes characters like new lines, carriage returns, tabs, etc.

Trait Implementations§

source§

impl Clone for Unit

source§

fn clone(&self) -> Unit

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 Unit

source§

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

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

impl Default for Unit

source§

fn default() -> Unit

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

impl Deref for Unit

§

type Target = Character

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl RefUnwindSafe for Unit

§

impl Send for Unit

§

impl Sync for Unit

§

impl Unpin for Unit

§

impl UnwindSafe for Unit

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.