Skip to main content

Binding

Struct Binding 

Source
pub struct Binding {
    pub context: String,
    pub action: String,
    pub keys: Vec<Key>,
    pub description: String,
    pub sequence: bool,
    pub unavailable: Option<String>,
}
Expand description

One thing a key does: an action, in a context, with a description.

Fields§

§context: String

Which component or container it belongs to: select, split.

§action: String

What it does, for code and configuration: down, focus-next.

§keys: Vec<Key>

The keys that do it, first the one to show.

§description: String

What it does, for people: move down.

§sequence: bool

The keys are pressed one after another (g g), rather than being alternatives: a key sequence an app runs itself, listed in a help or a palette. A keymap does not look these up.

§unavailable: Option<String>

Why it cannot be done now, when it cannot: a help or a palette lists it greyed, with the reason, and a palette does not run it.

Implementations§

Source§

impl Binding

Source

pub fn new( context: impl Into<String>, action: impl Into<String>, keys: impl IntoIterator<Item = Key>, description: impl Into<String>, ) -> Binding

Source

pub fn sequence( context: impl Into<String>, action: impl Into<String>, keys: impl IntoIterator<Item = Key>, description: impl Into<String>, ) -> Binding

A binding of keys pressed one after another (g then g), for a help or a palette to list: shown as g g.

use rich_interact::keymap::{keys, Binding};

let top = Binding::sequence("files", "top", keys("g g"), "go to the top");
assert_eq!(top.keys_label(), "g g");
Source

pub fn unavailable(self, reason: impl Into<String>) -> Binding

Listed but not available now, saying reason (see unavailable).

use rich_interact::keymap::{keys, Binding};

let save = Binding::new("editor", "save", keys("ctrl+s"), "save").unavailable("read-only");
assert_eq!(save.unavailable.as_deref(), Some("read-only"));
Source

pub fn id(&self) -> String

context.action: how configuration names it.

Source

pub fn keys_label(&self) -> String

The keys as people read them: up/ctrl+p, or g g for a sequence.

Source

pub fn hint(&self) -> String

The keys as a hint shows them: ↑/ctrl+p, or g g for a sequence.

Trait Implementations§

Source§

impl Clone for Binding

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 Binding

Source§

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

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

impl Display for Binding

Source§

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

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

impl Eq for Binding

Source§

impl PartialEq for Binding

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Binding

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

Checks if this value is equivalent to the given key. 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> ToCompactString for T
where T: Display,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.