DoubleBuffer

Struct DoubleBuffer 

Source
pub struct DoubleBuffer {
    pub buf: Vec<u8>,
    /* private fields */
}
Expand description

Double-buffered terminal output with differential rendering.

Maintains two buffers to compute minimal updates between frames, reducing flicker and bandwidth.

§Examples

use extui::{DoubleBuffer, Terminal, TerminalFlags};

let mut term = Terminal::open(TerminalFlags::RAW_MODE)?;
let (w, h) = term.size()?;
let mut buf = DoubleBuffer::new(w, h);

// Draw to buf, then render
buf.render(&mut term);

Fields§

§buf: Vec<u8>

The output byte buffer containing VT escape sequences.

Implementations§

Source§

impl DoubleBuffer

Source

pub fn rect(&self) -> Rect

Returns the full buffer area as a Rect.

Source

pub fn epoch(&self) -> u64

Returns the buffer epoch, incremented on each resize or reset.

Source

pub fn width(&self) -> u16

Returns the buffer width in cells.

Source

pub fn height(&self) -> u16

Returns the buffer height in cells.

Source

pub fn set_style(&mut self, area: Rect, style: Style)

Applies a style to all cells within the given area.

Source

pub fn set_string( &mut self, x: u16, y: u16, string: &str, style: Style, ) -> (u16, u16)

Writes a styled string at the given position.

Returns the cursor position after writing.

Source

pub fn set_stringn( &mut self, x: u16, y: u16, string: &str, max_width: usize, style: Style, ) -> (u16, u16)

Writes a styled string with a maximum width.

Returns the cursor position after writing.

Source

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

Creates a new double buffer with the given dimensions.

Source

pub fn reset(&mut self)

Clears both buffers and increments the epoch.

Source

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

Resizes the buffer if dimensions have changed.

Source

pub fn last_write_size(&self) -> usize

Returns the size of the last rendered output in bytes.

Source

pub fn write_buffer(&self) -> &[u8]

Returns the rendered output buffer.

Source

pub fn scroll(&mut self, amount: i16)

Queues a scroll operation for the next render.

Positive values scroll up, negative values scroll down.

Source

pub fn render_internal(&mut self)

Renders the current buffer to the internal byte buffer.

Use write_buffer to access the output.

Source

pub fn render(&mut self, term: &mut Terminal)

Renders and writes the output to the terminal.

Source

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

Returns a mutable reference to the current buffer.

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> 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, 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.