Skip to main content

Selection

Struct Selection 

Source
pub struct Selection<'t> { /* private fields */ }
Expand description

A snapshot selection range defined by two grid references.

§Preconditions

For every method that interacts with the terminal, the selection’s start and end grid refs must both be valid untracked snapshots for the given terminal’s currently active screen. In practice, they must come from that terminal and screen, and no mutating terminal call may have occurred since the refs were produced or reconstructed from tracked refs. Passing refs from another terminal, another screen, or stale refs violates this precondition.

Implementations§

Source§

impl<'t> Selection<'t>

Source

pub fn new(start: GridRef<'t>, end: GridRef<'t>, rectangle: bool) -> Self

Create a new selection between two endpoints.

Both endpoints are inclusive. The endpoints preserve selection direction and may be reversed; callers must not assume that start is the top-left endpoint or that end is the bottom-right endpoint.

When rectangle is false, the endpoints describe a linear selection. When rectangle is true, the same endpoints are interpreted as opposite corners of a rectangular/block selection.

Source

pub fn start(&self) -> GridRef<'t>

Start of the selection range (inclusive).

This may be before start in terminal order. It is an untracked GridRef snapshot and follows untracked grid-ref lifetime rules.

Source

pub fn end(&self) -> GridRef<'t>

End of the selection range (inclusive).

This may be before start in terminal order. It is an untracked GridRef snapshot and follows untracked grid-ref lifetime rules.

Source

pub fn is_rectangle(&self) -> bool

Whether the endpoints are interpreted as a rectangular/block selection rather than a linear selection.

Source

pub fn adjust( &mut self, terminal: &'t Terminal<'_, '_>, adjustment: Adjustment, ) -> Result<()>

Adjust a selection snapshot using terminal selection semantics.

The logical end endpoint is always moved, regardless of whether the selection is forward or reversed visually. The input selection remains a snapshot: after adjustment, call Terminal::set_selection to install it as the terminal-owned selection if desired.

See #Preconditions for the necessary preconditions.

Source

pub fn contains( &self, terminal: &'t Terminal<'_, '_>, point: Point, ) -> Result<bool>

Test whether a terminal point is inside a selection snapshot.

This uses the same selection semantics as the terminal, including rectangular/block selections and linear selections spanning multiple rows.

See #Preconditions for the necessary preconditions.

Source

pub fn equals( &self, terminal: &'t Terminal<'_, '_>, other: &Self, ) -> Result<bool>

Test whether two selection snapshots are equal.

Equality uses the terminal’s internal selection semantics: both endpoint pins must match and both selections must have the same rectangular/block state. This avoids requiring callers to compare raw GridRef internals.

See #Preconditions for the necessary preconditions.

Source

pub fn order(&self, terminal: &'t Terminal<'_, '_>) -> Result<Order>

Get the current endpoint ordering of a selection snapshot.

See #Preconditions for the necessary preconditions.

Source

pub fn to_ordered( &self, terminal: &'t Terminal<'_, '_>, desired: Order, ) -> Result<Self>

Return a selection snapshot with endpoints ordered as requested.

Use Order::Forward to get top-left to bottom-right bounds, and Order::Reverse to get bottom-right to top-left bounds. Mirrored desired orders are accepted but normalized the same as forward. The output selection is a fresh untracked snapshot and is not installed as the terminal’s current selection.

See #Preconditions for the necessary preconditions.

Trait Implementations§

Source§

impl<'t> Clone for Selection<'t>

Source§

fn clone(&self) -> Selection<'t>

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<'t> Debug for Selection<'t>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'t> !Send for Selection<'t>

§

impl<'t> !Sync for Selection<'t>

§

impl<'t> Freeze for Selection<'t>

§

impl<'t> RefUnwindSafe for Selection<'t>

§

impl<'t> Unpin for Selection<'t>

§

impl<'t> UnsafeUnpin for Selection<'t>

§

impl<'t> UnwindSafe for Selection<'t>

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> 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> 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> 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 = 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.