pub struct Buffer { /* private fields */ }Expand description
A buffer holding the terminal state
Implementations§
Source§impl Buffer
impl Buffer
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
Create a new buffer with the given dimensions
§Panics
Panics if:
- Width exceeds
MAX_BUFFER_DIMENSION(16384) - Height exceeds
MAX_BUFFER_DIMENSION(16384) - Total size (width * height) exceeds
MAX_BUFFER_SIZE(10,000,000 cells)
Use Buffer::try_new() for a non-panicking version.
Sourcepub fn try_new(width: u16, height: u16) -> Result<Self, BufferError>
pub fn try_new(width: u16, height: u16) -> Result<Self, BufferError>
Try to create a new buffer with the given dimensions
Returns Ok(buffer) if dimensions are valid, Err(BufferError) otherwise.
§Errors
Returns BufferError if:
- Width exceeds
MAX_BUFFER_DIMENSION(16384) - Height exceeds
MAX_BUFFER_DIMENSION(16384) - Total size (width * height) exceeds
MAX_BUFFER_SIZE(10,000,000 cells)
Sourcepub fn set_colors(&mut self, x: u16, y: u16, fg: Color, bg: Color)
pub fn set_colors(&mut self, x: u16, y: u16, fg: Color, bg: Color)
Set both foreground and background colors at position
Sourcepub fn put_str(&mut self, x: u16, y: u16, s: &str) -> u16
pub fn put_str(&mut self, x: u16, y: u16, s: &str) -> u16
Put a string at position, handling wide characters correctly
Sourcepub fn put_str_styled(
&mut self,
x: u16,
y: u16,
s: &str,
fg: Option<Color>,
bg: Option<Color>,
) -> u16
pub fn put_str_styled( &mut self, x: u16, y: u16, s: &str, fg: Option<Color>, bg: Option<Color>, ) -> u16
Put a styled string at position
Sourcepub fn fill(&mut self, x: u16, y: u16, width: u16, height: u16, cell: Cell)
pub fn fill(&mut self, x: u16, y: u16, width: u16, height: u16, cell: Cell)
Fill a rectangular area with a cell
Optimized using slice operations for better performance.
Sourcepub fn fill_char(&mut self, x: u16, y: u16, width: u16, height: u16, ch: char)
pub fn fill_char(&mut self, x: u16, y: u16, width: u16, height: u16, ch: char)
Fill area with a character
Sourcepub fn resize(&mut self, width: u16, height: u16)
pub fn resize(&mut self, width: u16, height: u16)
Resize the buffer, keeping content where possible
Optimized using slice copy operations for better performance.
Sourcepub fn iter_cells(&self) -> impl Iterator<Item = (u16, u16, &Cell)>
pub fn iter_cells(&self) -> impl Iterator<Item = (u16, u16, &Cell)>
Iterate over cells with positions
Sourcepub fn register_hyperlink(&mut self, url: impl Into<String>) -> u16
pub fn register_hyperlink(&mut self, url: impl Into<String>) -> u16
Register a hyperlink URL and return its ID
Sourcepub fn get_hyperlink(&self, id: u16) -> Option<&str>
pub fn get_hyperlink(&self, id: u16) -> Option<&str>
Get hyperlink URL by ID
Sourcepub fn hyperlinks(&self) -> &[String]
pub fn hyperlinks(&self) -> &[String]
Get all registered hyperlinks
Sourcepub fn clear_hyperlinks(&mut self)
pub fn clear_hyperlinks(&mut self)
Clear hyperlinks (call on buffer clear/resize)
Sourcepub fn put_hyperlink(
&mut self,
x: u16,
y: u16,
text: &str,
url: &str,
fg: Option<Color>,
bg: Option<Color>,
) -> u16
pub fn put_hyperlink( &mut self, x: u16, y: u16, text: &str, url: &str, fg: Option<Color>, bg: Option<Color>, ) -> u16
Put a hyperlinked string at position
Sourcepub fn register_sequence(&mut self, seq: impl Into<String>) -> u16
pub fn register_sequence(&mut self, seq: impl Into<String>) -> u16
Register an escape sequence and return its ID
Used for raw terminal sequences like OSC 66 (text sizing). The sequence will be written directly to the terminal instead of the cell’s symbol.
Sourcepub fn get_sequence(&self, id: u16) -> Option<&str>
pub fn get_sequence(&self, id: u16) -> Option<&str>
Get escape sequence by ID
Sourcepub fn clear_sequences(&mut self)
pub fn clear_sequences(&mut self)
Clear sequences (call on buffer clear/resize)
Sourcepub fn put_sequence(
&mut self,
x: u16,
y: u16,
seq: &str,
width: u16,
height: u16,
)
pub fn put_sequence( &mut self, x: u16, y: u16, seq: &str, width: u16, height: u16, )
Put an escape sequence at position, marking subsequent cells as continuations
§Arguments
x,y- Starting positionseq- The escape sequence to writewidth- Number of cells this sequence spans (for continuation markers)height- Number of rows this sequence spans