pub struct ScrollBuffer { /* private fields */ }Expand description
Scrollable buffer of rendered Lines with sticky-bottom auto-scroll.
Implementations§
Source§impl ScrollBuffer
impl ScrollBuffer
pub fn new(capacity: usize) -> Self
Sourcepub fn push(&mut self, line: Line<'static>)
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.
Sourcepub fn push_with_gutter(&mut self, line: Line<'static>, gutter_width: u16)
pub fn push_with_gutter(&mut self, line: Line<'static>, gutter_width: u16)
Append a line with a gutter width (for NoSelect diff lines).
Sourcepub fn push_lines(&mut self, lines: impl IntoIterator<Item = Line<'static>>)
pub fn push_lines(&mut self, lines: impl IntoIterator<Item = Line<'static>>)
Append multiple lines at once.
Sourcepub fn scroll_up(&mut self, n: usize, term_width: usize, viewport_height: usize)
pub fn scroll_up(&mut self, n: usize, term_width: usize, viewport_height: usize)
Scroll up by n visual lines. Disengages sticky bottom.
Sourcepub fn scroll_down(&mut self, n: usize)
pub fn scroll_down(&mut self, n: usize)
Scroll down by n lines. Re-engages sticky bottom if we reach
the bottom.
Sourcepub fn clamp_offset(&mut self, term_width: usize, viewport_height: usize)
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.
Sourcepub fn scroll_to_bottom(&mut self)
pub fn scroll_to_bottom(&mut self)
Jump to the bottom and re-engage sticky mode.
Sourcepub fn scroll_to_top(&mut self, term_width: usize, viewport_height: usize)
pub fn scroll_to_top(&mut self, term_width: usize, viewport_height: usize)
Jump to the top of the buffer.
Sourcepub fn at_top(&self, term_width: usize, viewport_height: usize) -> bool
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.
Sourcepub fn all_lines(&self) -> impl Iterator<Item = &Line<'static>>
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.
Sourcepub fn gutter_widths(&self) -> &VecDeque<u16>
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.
Sourcepub fn total_visual_lines(&self, term_width: usize) -> usize
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.
Sourcepub fn paragraph_scroll(
&self,
viewport_height: usize,
term_width: usize,
) -> (u16, u16)
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.
Sourcepub fn oldest_message_id(&self) -> Option<i64>
pub fn oldest_message_id(&self) -> Option<i64>
Get the oldest DB message ID rendered in this buffer.
Sourcepub fn set_oldest_message_id(&mut self, id: i64)
pub fn set_oldest_message_id(&mut self, id: i64)
Set the oldest DB message ID (called after rendering history).
Sourcepub fn last_code_block(&self) -> Option<String>
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).
Sourcepub fn last_response(&self) -> Option<String>
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.
Sourcepub fn prepend_lines(&mut self, lines: impl IntoIterator<Item = Line<'static>>)
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§
impl Freeze for ScrollBuffer
impl RefUnwindSafe for ScrollBuffer
impl Send for ScrollBuffer
impl Sync for ScrollBuffer
impl Unpin for ScrollBuffer
impl UnsafeUnpin for ScrollBuffer
impl UnwindSafe for ScrollBuffer
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> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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