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>
impl<'t> Selection<'t>
Sourcepub fn new(start: GridRef<'t>, end: GridRef<'t>, rectangle: bool) -> Self
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.
Sourcepub fn start(&self) -> GridRef<'t>
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.
Sourcepub fn end(&self) -> GridRef<'t>
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.
Sourcepub fn is_rectangle(&self) -> bool
pub fn is_rectangle(&self) -> bool
Whether the endpoints are interpreted as a rectangular/block selection rather than a linear selection.
Sourcepub fn adjust(
&mut self,
terminal: &'t Terminal<'_, '_>,
adjustment: Adjustment,
) -> Result<()>
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.
Sourcepub fn contains(
&self,
terminal: &'t Terminal<'_, '_>,
point: Point,
) -> Result<bool>
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.
Sourcepub fn equals(
&self,
terminal: &'t Terminal<'_, '_>,
other: &Self,
) -> Result<bool>
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.
Sourcepub fn order(&self, terminal: &'t Terminal<'_, '_>) -> Result<Order>
pub fn order(&self, terminal: &'t Terminal<'_, '_>) -> Result<Order>
Get the current endpoint ordering of a selection snapshot.
See #Preconditions for the necessary preconditions.
Sourcepub fn to_ordered(
&self,
terminal: &'t Terminal<'_, '_>,
desired: Order,
) -> Result<Self>
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.