pub struct PreviewSlot {
pub for_path: PathBuf,
pub generation: u64,
pub content: PreviewContent,
pub scroll: usize,
pub viewport_height: usize,
pub viewport_width: u16,
pub truncated: bool,
pub drew_image: bool,
}Expand description
The preview pane’s current content and the generation it belongs to.
generation is incremented on every selection change so that
late-arriving worker results for a since-abandoned selection can be
discarded in workers::merge (Phase 4). The field is defined here in
Phase 1 so the state shape is stable — the guard is exercised in Phase 4/5.
Fields§
§for_path: PathBufThe path whose preview is currently being displayed (or loading).
generation: u64Monotonically increasing counter. Every selection change bumps this.
content: PreviewContentThe actual content to render, or a loading placeholder.
scroll: usizeIndex of the first content line drawn in the pane.
Counted in logical lines (one entry of the content’s line vector), not
wrapped terminal rows, because the render path slices the line vector
rather than offsetting a Paragraph. The limits it is clamped to do
count wrapped rows — see Self::viewport_width.
viewport_height: usizeHeight in rows of the pane’s interior, recorded by the render pass.
Only the renderer knows the pane size, so it writes this on every frame and the scroll actions clamp against it. It is zero until the first render, which makes every scroll request a no-op — harmless, because no key can be pressed before the first frame is drawn.
viewport_width: u16Width in columns of the pane’s interior, recorded by the render pass.
A line wider than this wraps onto further rows, so the scroll limit and the page step measure rows with it rather than assuming one row per line. Zero until the first render, which counts every line as one row.
truncated: boolWhether the loaded content stops short of the end of the file.
Set from WorkerMsg::Preview when the highlight worker hit
[preview] max_lines. The renderer marks such a preview so the pane
never silently claims to show a whole file.
drew_image: boolWhether the last frame drew an inline image.
Written by the renderer, for the renderer. An inline image is placed by the terminal itself rather than by ratatui, so no cell diff can erase it; the frame that stops showing one has to clear the screen, and this is how it knows. Everything else relies on the ordinary diff.
Implementations§
Source§impl PreviewSlot
impl PreviewSlot
Sourcepub fn begin(&mut self, path: &Path) -> u64
pub fn begin(&mut self, path: &Path) -> u64
Prepares the slot for a preview of path and returns the new generation.
Bumps generation so that in-flight worker results for the previous
request are dropped by crate::workers::merge, and resets the scroll
position only when path differs from the current for_path. A
re-preview of the same path (a filesystem-watch tick, R, or toggling
hidden files) therefore keeps the reader where they were.
Sourcepub fn max_scroll(&self) -> usize
pub fn max_scroll(&self) -> usize
Returns the largest useful scroll offset: the offset at which the last content line ends on the pane’s last row.
Wrapped lines count for every row they take, so a file with long lines can still be scrolled until its end is on screen.
Returns 0 for content that does not scroll (an image, a placeholder)
and for content that fits the pane.
Sourcepub fn lines_visible_from(&self, start: usize) -> usize
pub fn lines_visible_from(&self, start: usize) -> usize
Number of logical lines drawn whole when the pane starts at line start.
At least 1 while start is inside the content and the pane has a row:
a single line taller than the pane still counts as the one being shown,
so a page step always advances. 0 past the end or for content that
does not scroll.
Sourcepub fn clamp_scroll(&mut self)
pub fn clamp_scroll(&mut self)
Clamps scroll into range, leaving it alone for content that does not
scroll.
Called by the render pass once it has recorded viewport_height: it is
the only place that sees a terminal resize, and it must not zero a
position that a Loading frame is about to replace with real content.
Trait Implementations§
Source§impl Clone for PreviewSlot
impl Clone for PreviewSlot
Source§impl Debug for PreviewSlot
impl Debug for PreviewSlot
Auto Trait Implementations§
impl !RefUnwindSafe for PreviewSlot
impl !UnwindSafe for PreviewSlot
impl Freeze for PreviewSlot
impl Send for PreviewSlot
impl Sync for PreviewSlot
impl Unpin for PreviewSlot
impl UnsafeUnpin for PreviewSlot
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for 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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<R, P> ReadPrimitive<R> for P
impl<R, P> ReadPrimitive<R> for P
Source§fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
fn read_from_little_endian(read: &mut R) -> Result<Self, Error>
ReadEndian::read_from_little_endian().