Skip to main content

TextBuffer

Struct TextBuffer 

Source
pub struct TextBuffer { /* private fields */ }
Expand description

A Buffer paired with a text-width policy.

Construct one with new, choose the width policy with with_width_mode / with_eaw_wide, paint with the TextSurface/SurfaceMut methods, then serialize with the Encode trait.

Implementations§

Source§

impl TextBuffer

Source

pub fn new(width: u16, height: u16) -> Self

Create a width by height text buffer of blank cells.

The width policy defaults to WidthMode::Wc with East-Asian Ambiguous characters measured as one cell.

Source

pub fn with_width_mode(self, mode: WidthMode) -> Self

Set the grapheme-cluster width policy and return the updated buffer.

Source

pub fn with_eaw_wide(self, eaw_wide: bool) -> Self

Set the East-Asian Ambiguous policy and return the updated buffer.

When true, code points whose East-Asian-Width property is Ambiguous are measured as two cells instead of one.

Source

pub fn set_width_mode(&mut self, mode: WidthMode)

Set the grapheme-cluster width policy in place.

Source

pub fn set_eaw_wide(&mut self, eaw_wide: bool)

Set the East-Asian Ambiguous policy in place.

Source

pub fn width(&self) -> u16

The width in cells.

Source

pub fn height(&self) -> u16

The height in cells.

Source

pub fn resize(&mut self, width: u16, height: u16)

Resize the buffer, preserving overlapping cells.

Source

pub fn buffer(&self) -> &Buffer

Borrow the underlying Buffer.

Source

pub fn buffer_mut(&mut self) -> &mut Buffer

Mutably borrow the underlying Buffer.

Source

pub fn into_buffer(self) -> Buffer

Consume the text buffer and return the underlying Buffer.

Trait Implementations§

Source§

impl Bounded for TextBuffer

Source§

fn bounds(&self) -> Rect

Return the valid region in this value’s own coordinate space. Read more
Source§

fn width(&self) -> u16

Return the width of Self::bounds in terminal cell columns. Read more
Source§

fn height(&self) -> u16

Return the height of Self::bounds in terminal cell rows. Read more
Source§

fn contains(&self, pos: Position) -> bool

Test whether a position lies inside Self::bounds. Read more
Source§

impl Clone for TextBuffer

Source§

fn clone(&self) -> TextBuffer

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for TextBuffer

Source§

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

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

impl Surface for TextBuffer

Source§

fn cell(&self, pos: Position) -> Option<&Cell>

Read the cell at a position. Read more
Source§

fn draw<T: SurfaceMut + ?Sized>(&self, target: &mut T, at: Position)

Copy self’s cells into target, mapping the top-left of self.bounds() to at in target coordinates. Read more
Source§

impl SurfaceMut for TextBuffer

Source§

fn set_cell(&mut self, pos: Position, cell: &Cell)

Place cell at pos. Implementations are responsible for wide-cell semantics (continuation markers, blanking covered cells) and any dirty tracking they care to do. Taking &Cell lets implementations skip the clone when the destination already matches. Read more
Source§

fn cell_mut(&mut self, pos: Position) -> Option<&mut Cell>

Mutable handle to the cell at pos. Returns None for out-of-bounds positions. Read more
Source§

fn fill(&mut self, cell: &Cell)

Fill the entire surface bounds with cell. Read more
Source§

fn fill_rect(&mut self, rect: Rect, cell: &Cell)

Fill the intersection of rect and Bounded::bounds with cell. Read more
Source§

fn clear(&mut self)

Clear the entire surface bounds to Cell::BLANK. Read more
Source§

fn clear_rect(&mut self, rect: Rect)

Clear a rectangle to Cell::BLANK. Read more
Source§

fn insert_lines(&mut self, y: u16, n: u16, bounds_bottom: u16, fill: &Cell)

Insert n blank rows at y, pushing existing rows down within [y, bounds_bottom). Rows pushed past bounds_bottom are lost. Freed top rows are filled with fill. Read more
Source§

fn delete_lines(&mut self, y: u16, n: u16, bounds_bottom: u16, fill: &Cell)

Delete n rows at y, pulling existing rows up within [y, bounds_bottom). The bottom n rows of the window are filled with fill. Read more
Source§

fn insert_cells( &mut self, pos: Position, n: u16, bounds_right: u16, fill: &Cell, )

Insert n blank cells at pos, pushing cells in [pos.x, bounds_right) right within row pos.y. Cells pushed past bounds_right are lost. The freed slots [pos.x, pos.x + n) are filled with fill. Read more
Source§

fn delete_cells( &mut self, pos: Position, n: u16, bounds_right: u16, fill: &Cell, )

Delete n cells at pos, pulling cells in [pos.x + n, bounds_right) left within row pos.y. The freed slots [bounds_right - n, bounds_right) are filled with fill. Read more
Source§

impl TextSurface for TextBuffer

Source§

fn width_mode(&self) -> WidthMode

Return the width-measurement mode used when shaping strings. Read more
Source§

fn eaw_wide(&self) -> bool

Return the East-Asian Ambiguous width policy for this surface. Read more
Source§

fn set_str( &mut self, pos: impl Into<Position>, s: &str, style: impl Into<Style>, ) -> Position

Paint s at pos, clipped to the surface bounds. Read more
Source§

fn set_str_wrap( &mut self, pos: impl Into<Position>, s: &str, wrap: WrapMode, style: impl Into<Style>, ) -> Position

Paint s at pos with an explicit right-edge behavior. Read more
Source§

fn set_str_rect( &mut self, rect: impl Into<Rect>, s: &str, style: impl Into<Style>, ) -> Position

Paint s inside rect, clipped to the surface bounds. Read more
Source§

fn set_str_rect_wrap( &mut self, rect: impl Into<Rect>, s: &str, wrap: WrapMode, style: impl Into<Style>, ) -> Position

Paint s inside rect with an explicit right-edge behavior. Read more
Source§

fn set_str_truncate( &mut self, pos: impl Into<Position>, s: &str, tail: &str, tail_style: impl Into<Style>, ) -> Position

Paint s at pos, truncating with a tail indicator on overflow. Read more
Source§

fn set_str_rect_truncate( &mut self, rect: impl Into<Rect>, s: &str, tail: &str, tail_style: impl Into<Style>, ) -> Position

Paint s inside rect, truncating with a tail indicator on overflow. Read more
Source§

fn str_width(&self, s: &str) -> u16

Measure the display width of s in terminal columns. Read more
Source§

fn grapheme_width(&self, g: &str) -> u8

Measure one extended grapheme cluster in cells under this surface’s width mode and East-Asian Ambiguous policy. Read more
Source§

fn grapheme_cells<'a>(&self, s: &'a str) -> impl Iterator<Item = (&'a str, u8)>

Iterate s as (cluster, width) pairs under this surface’s width mode and East-Asian Ambiguous policy. Read more

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<S> Encode for S
where S: Surface + ?Sized,

Source§

fn encode<W: Write>(&self, w: &mut W) -> Result<()>

Write the surface to w as escape sequences and text. Read more
Source§

fn encode_with<W: Write>(&self, w: &mut W, profile: Profile) -> Result<()>

Write the surface to w, downsampling colors to profile. Read more
Source§

fn display(&self) -> SurfaceDisplay<'_, Self>

Borrow the surface as a Display adapter. Read more
Source§

fn display_with(&self, profile: Profile) -> SurfaceDisplay<'_, Self>

Borrow the surface as a Display adapter that downsamples colors to profile. 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.
§

impl<T> ErasedDestructor for T
where T: 'static,