Skip to main content

SelectState

Struct SelectState 

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

The state for a SelectPrompt.

Rendering a SelectPrompt keeps the focused index within the rendered options. Until the prompt has been rendered at least once, explicit focused-index changes are accepted and clamped on the next render. Once the state is completed or aborted, SelectState::handle_key_event ignores later key events.

Implementations§

Source§

impl SelectState

Source

pub const fn new() -> SelectState

Creates a pending, unfocused select state.

Source

pub fn move_up(&mut self)

Moves focus to the previous option.

Focus stays at index 0 when the first option is already focused.

Source

pub fn move_down(&mut self)

Moves focus to the next option.

Focus stays at the last rendered option. The prompt learns the option count during render, so this is a no-op until the state has been rendered with at least one visible option.

Source

pub const fn with_status(self, status: Status) -> SelectState

Sets the prompt status.

Source

pub const fn with_focus(self, focus: FocusState) -> SelectState

Sets whether the prompt is focused.

Source

pub const fn focused_index(&self) -> usize

Returns the currently focused option index.

Source

pub fn set_focused_index(&mut self, index: usize)

Sets the focused option index.

If the state has already been rendered with options, the index is clamped to the last available option. If the state has not been rendered yet, the value is accepted and clamped during the next render.

Source

pub const fn is_finished(&self) -> bool

Returns whether the select prompt has completed or aborted.

Source

pub const fn status(&self) -> Status

Returns the current prompt status.

Source

pub fn focus(&mut self)

Sets focus to FocusState::Focused.

Source

pub fn blur(&mut self)

Sets focus to FocusState::Unfocused.

Source

pub fn is_focused(&self) -> bool

Returns whether the select prompt is focused.

Source

pub fn complete(&mut self)

Completes the prompt.

Source

pub fn abort(&mut self)

Aborts the prompt.

Source

pub fn handle_key_event(&mut self, key: KeyEvent)

Handles a key event for select prompt navigation and completion.

Pressing Up or Down moves the focused option, Enter completes the prompt when an option is visible, and Escape or Ctrl+C aborts the prompt. Key release events and events routed after completion or abort are ignored.

Trait Implementations§

Source§

impl Clone for SelectState

Source§

fn clone(&self) -> SelectState

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 SelectState

Source§

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

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

impl Default for SelectState

Source§

fn default() -> SelectState

Returns the “default value” for a type. Read more
Source§

impl Eq for SelectState

Source§

impl Hash for SelectState

Source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SelectState

Source§

fn eq(&self, other: &SelectState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for SelectState

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> 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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> 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> 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.