Skip to main content

TrackedGridRef

Struct TrackedGridRef 

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

Owned grid references that move with the terminal.

A tracked grid reference follows its cell across normal screen operations. For example scrolling, scrollback pruning, resize/reflow, and other terminal mutations update the tracked reference automatically.

A tracked reference can still lose its original semantic location. This can happen when the underlying grid is reset, pruned, or otherwise discarded in a way that cannot be mapped to a meaningful new cell. In that state, TrackedGridRef::has_value returns false and TrackedGridRef::snapshot / TrackedGridRef::point return Ok(None). The handle remains valid, and callers may move it to a new point with TrackedGridRef::set.

To read cell data from a tracked reference, first snapshot it with TrackedGridRef::snapshot. The returned GridRef is again an untracked reference and follows the same short lifetime rules as any other untracked grid reference.

A tracked reference belongs to the terminal screen/page-list that was active when it was created or last set. Converting it to a point uses that owning screen/page-list, even if the terminal has since switched between primary and alternate screens. Calling TrackedGridRef::set resolves the new point against the terminal’s currently active screen/page-list and may move the tracked reference between screens.

If the tracked grid reference outlives the terminal it is created from, it remains valid, but all APIs return either false or Ok(None).

Each tracked reference adds bookkeeping to terminal mutations. Use them sparingly for long-lived anchors such as selections, search state, marks, or application-side bookmarks.

Implementations§

Source§

impl TrackedGridRef

Source

pub fn has_value(&self) -> bool

Whether a tracked grid reference currently has a meaningful value.

If the terminal that created the tracked reference has been dropped, this returns false.

Source

pub fn snapshot<'t>( &self, terminal: &'t Terminal<'_, '_>, ) -> Result<Option<GridRef<'t>>>

Snapshot a tracked grid reference into a regular GridRef.

The returned GridRef is an untracked snapshot and has the same lifetime rules as Terminal::grid_ref: it is only valid until the next terminal update. Snapshot immediately before calling GridRef::cell, GridRef::row, GridRef::graphemes, GridRef::hyperlink_uri, or GridRef::style,

If the tracked reference no longer has a meaningful value, this returns Ok(None). This includes references whose owning terminal has been dropped.

Source

pub fn point(&self, space: PointSpace) -> Result<Option<PointCoordinate>>

Convert a tracked grid reference to a point in the requested coordinate space.

This is the tracked equivalent of Terminal::point_from_grid_ref. Unlike snapshotting, this does not expose an intermediate untracked GridRef.

A tracked reference is resolved against the terminal screen/page-list that currently owns the reference. If the terminal has switched between primary and alternate screens since the reference was created or last set, this may be different from the terminal’s currently active screen.

If the tracked reference no longer has a meaningful value, this returns Ok(None). Ok(None is also returned when the reference cannot be represented in the requested coordinate space, including after the terminal that created the tracked reference has been dropped.

Source

pub fn set( &mut self, terminal: &mut Terminal<'_, '_>, point: Point, ) -> Result<&mut Self>

Move an existing tracked grid reference to a new terminal point.

On success, the tracked reference begins tracking the new point and any prior “no value” state is cleared. On Err(Error::OutOfMemory), the original tracked reference is left unchanged.

The terminal must be the same terminal that created the tracked reference. The point is resolved against the terminal screen/page-list that is active at the time this function is called. If the terminal has switched between primary and alternate screens, this may move the tracked reference from one screen/page-list to the other.

Trait Implementations§

Source§

impl Debug for TrackedGridRef

Source§

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

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

impl Drop for TrackedGridRef

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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.