Skip to main content

ScrollBuffer

Struct ScrollBuffer 

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

Scrollable buffer of rendered Lines with sticky-bottom auto-scroll.

Implementations§

Source§

impl ScrollBuffer

Source

pub fn new(capacity: usize) -> Self

Source

pub fn push(&mut self, line: Line<'static>)

Append a single line to the buffer.

If sticky bottom is active, the view stays pinned to the latest content. If the buffer exceeds the max cache size, the oldest lines are evicted from the front.

Source

pub fn push_with_gutter(&mut self, line: Line<'static>, gutter_width: u16)

Append a line with a gutter width (for NoSelect diff lines).

Source

pub fn push_lines(&mut self, lines: impl IntoIterator<Item = Line<'static>>)

Append multiple lines at once.

Source

pub fn scroll_up(&mut self, n: usize, term_width: usize, viewport_height: usize)

Scroll up by n visual lines. Disengages sticky bottom.

Source

pub fn scroll_down(&mut self, n: usize)

Scroll down by n lines. Re-engages sticky bottom if we reach the bottom.

Source

pub fn clamp_offset(&mut self, term_width: usize, viewport_height: usize)

Re-clamp scroll_offset to valid bounds for the current terminal dimensions. Must be called after any resize so the offset doesn’t exceed total_visual - viewport_height.

Source

pub fn scroll_to_bottom(&mut self)

Jump to the bottom and re-engage sticky mode.

Source

pub fn scroll_to_top(&mut self, term_width: usize, viewport_height: usize)

Jump to the top of the buffer.

Source

pub fn at_top(&self, term_width: usize, viewport_height: usize) -> bool

Returns true when the user has scrolled to the very top of the buffer. Used to trigger loading older messages from the DB.

Source

pub fn all_lines(&self) -> impl Iterator<Item = &Line<'static>>

Return all lines in the buffer.

Used by render_history() which passes everything to Paragraph::wrap().scroll() — ratatui handles the visual line math for word-wrapped content.

Source

pub fn gutter_widths(&self) -> &VecDeque<u16>

Return the per-line gutter widths (parallel with all_lines()).

Used by mouse selection to skip gutter columns during copy.

Source

pub fn total_visual_lines(&self, term_width: usize) -> usize

Compute the total number of visual (wrapped) lines at a given terminal width. Used for scrollbar state and offset clamping.

Source

pub fn paragraph_scroll( &self, viewport_height: usize, term_width: usize, ) -> (u16, u16)

Compute the Paragraph scroll-from-top offset for the current scroll position. Returns (row_offset, 0) for Paragraph::scroll().

scroll_offset is visual lines from the bottom. Paragraph wants visual lines from the top.

Source

pub fn len(&self) -> usize

Total number of lines in the buffer.

Source

pub fn is_empty(&self) -> bool

Whether the buffer is empty.

Source

pub fn offset(&self) -> usize

Current scroll offset (lines from bottom).

Source

pub fn is_sticky(&self) -> bool

Whether sticky bottom is active.

Source

pub fn oldest_message_id(&self) -> Option<i64>

Get the oldest DB message ID rendered in this buffer.

Source

pub fn set_oldest_message_id(&mut self, id: i64)

Set the oldest DB message ID (called after rendering history).

Source

pub fn clear(&mut self)

Clear all lines and reset scroll state.

Source

pub fn last_code_block(&self) -> Option<String>

Extract the last fenced code block from the buffer.

Scans backward for ``` fences and returns the content between them. Used by Ctrl+Y (copy last code block).

Source

pub fn last_response(&self) -> Option<String>

Extract the last assistant response from the buffer.

Scans backward for the response separator (“───”) and returns everything after it. Used by Ctrl+U / Ctrl+Shift+Y (copy last response).

The separator is exactly 3 characters (emitted by ResponseStart). Markdown HRs (60+ dashes) are explicitly excluded.

Source

pub fn prepend_lines(&mut self, lines: impl IntoIterator<Item = Line<'static>>)

Prepend lines at the top of the buffer (for DB-backed virtual scroll).

Used when the user scrolls past the top of the cache and older messages are fetched from the DB and re-rendered.

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoMaybeUndefined<T> for T

Source§

impl<T> IntoOption<T> for T

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more