Skip to main content

ScrollBuffer

Struct ScrollBuffer 

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

Ring buffer for storing lines with scrollback.

The scroll buffer maintains a fixed number of lines in memory, automatically discarding old lines when capacity is exceeded.

Implementations§

Source§

impl ScrollBuffer

Source

pub fn new(max_lines: usize) -> Self

Create a new scroll buffer with the given capacity.

Source

pub fn len(&self) -> usize

Get the total number of lines in the buffer.

Source

pub fn is_empty(&self) -> bool

Check if the buffer is empty.

Source

pub fn current_line(&self) -> &StyledLine

Get the current line (the line being appended to).

§Panics

Panics if the buffer is empty (which should never happen).

Source

pub fn current_line_mut(&mut self) -> &mut StyledLine

Get a mutable reference to the current line.

§Panics

Panics if the buffer is empty (which should never happen).

Source

pub fn append(&mut self, cells: impl IntoIterator<Item = Cell>)

Append cells to the current line.

Source

pub fn newline(&mut self, wrapped: bool)

Start a new line.

§Arguments
  • wrapped - Whether the new line is due to soft wrapping.
Source

pub fn get(&self, index: usize) -> Option<&StyledLine>

Get a line by index from the top of the buffer.

Source

pub fn visible_lines( &self, viewport_height: usize, ) -> impl Iterator<Item = &StyledLine>

Get visible lines for a given viewport height.

Returns an iterator over lines that should be visible, accounting for scroll offset.

Source

pub fn scroll_up(&mut self, lines: usize)

Scroll up by the given number of lines.

Source

pub const fn scroll_down(&mut self, lines: usize)

Scroll down by the given number of lines.

Source

pub const fn scroll_to_bottom(&mut self)

Scroll to the bottom (latest content).

Source

pub const fn at_bottom(&self) -> bool

Check if we’re scrolled to the bottom.

Source

pub fn clear(&mut self)

Clear all content.

Source

pub fn current_line_len(&self) -> usize

Get the length of the current line in characters.

Trait Implementations§

Source§

impl Debug for ScrollBuffer

Source§

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

Formats the value using the given formatter. 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> 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.