Skip to main content

PreviewSlot

Struct PreviewSlot 

Source
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: PathBuf

The path whose preview is currently being displayed (or loading).

§generation: u64

Monotonically increasing counter. Every selection change bumps this.

§content: PreviewContent

The actual content to render, or a loading placeholder.

§scroll: usize

Index 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: usize

Height 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: u16

Width 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: bool

Whether 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: bool

Whether 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

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PreviewSlot

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for PreviewSlot

Source§

fn default() -> Self

Returns the “default value” for a type. 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &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
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync> ⓘ

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> 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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

Source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
Source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
Source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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