pub struct Buffer {
pub area: Rect,
pub content: Vec<Cell>,
}Expand description
A buffer representing the terminal screen.
The buffer is a rectangular grid of Cells that can be efficiently
diffed to minimize terminal updates.
§Example
use tuxtui_core::buffer::Buffer;
use tuxtui_core::geometry::Rect;
use tuxtui_core::style::{Color, Style};
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 5));
buffer.set_string(0, 0, "Hello", Style::default().fg(Color::Green));Fields§
§area: RectThe area covered by this buffer
content: Vec<Cell>The cells in this buffer (row-major order)
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn empty(area: Rect) -> Self
pub fn empty(area: Rect) -> Self
Create an empty buffer with the given area.
All cells are initialized to spaces with default style.
Sourcepub const fn index_of(&self, x: u16, y: u16) -> Option<usize>
pub const fn index_of(&self, x: u16, y: u16) -> Option<usize>
Get the index into the content vector for the given coordinates.
Returns None if the coordinates are out of bounds.
Sourcepub fn get(&self, x: u16, y: u16) -> Option<&Cell>
pub fn get(&self, x: u16, y: u16) -> Option<&Cell>
Get a reference to the cell at the given coordinates.
Sourcepub fn get_mut(&mut self, x: u16, y: u16) -> Option<&mut Cell>
pub fn get_mut(&mut self, x: u16, y: u16) -> Option<&mut Cell>
Get a mutable reference to the cell at the given coordinates.
Sourcepub fn set(
&mut self,
x: u16,
y: u16,
symbol: impl Into<String>,
style: Style,
) -> bool
pub fn set( &mut self, x: u16, y: u16, symbol: impl Into<String>, style: Style, ) -> bool
Set the symbol and style of a cell at the given coordinates.
Returns true if the cell was updated, false if out of bounds.
§Example
use tuxtui_core::buffer::Buffer;
use tuxtui_core::geometry::Rect;
use tuxtui_core::style::Style;
let mut buffer = Buffer::empty(Rect::new(0, 0, 10, 10));
buffer.set(5, 5, "X", Style::default());Sourcepub fn set_string(&mut self, x: u16, y: u16, string: &str, style: Style) -> u16
pub fn set_string(&mut self, x: u16, y: u16, string: &str, style: Style) -> u16
Set a string at the given position with a style.
Returns the x-coordinate after the last written character.
§Example
use tuxtui_core::buffer::Buffer;
use tuxtui_core::geometry::Rect;
use tuxtui_core::style::{Color, Style};
let mut buffer = Buffer::empty(Rect::new(0, 0, 20, 5));
let style = Style::default().fg(Color::Blue);
let end_x = buffer.set_string(0, 0, "Hello, world!", style);Sourcepub fn set_styled_string(
&mut self,
x: u16,
y: u16,
string: &str,
style: Style,
) -> u16
pub fn set_styled_string( &mut self, x: u16, y: u16, string: &str, style: Style, ) -> u16
Set a styled string with mixed styles (via spans).
This is used internally by text rendering.
Sourcepub fn clear_region(&mut self, region: Rect)
pub fn clear_region(&mut self, region: Rect)
Clear a specific rectangular region.
Sourcepub fn set_style(&mut self, _style: Style)
pub fn set_style(&mut self, _style: Style)
Set the style for subsequent operations (no-op for buffer).
Sourcepub fn resize(&mut self, area: Rect)
pub fn resize(&mut self, area: Rect)
Resize the buffer to a new area.
Content is preserved where it overlaps; new areas are filled with default cells.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Buffer
impl<'de> Deserialize<'de> for Buffer
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Buffer
impl StructuralPartialEq for Buffer
Auto Trait Implementations§
impl Freeze for Buffer
impl RefUnwindSafe for Buffer
impl Send for Buffer
impl Sync for Buffer
impl Unpin for Buffer
impl UnwindSafe for Buffer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.