Struct crokey::KeyEventFormat
source · [−]pub struct KeyEventFormat {
pub control: String,
pub alt: String,
pub shift: String,
pub enter: String,
pub uppercase_shift: bool,
}Expand description
A formatter to produce key combinations descriptions.
use {
crokey::*,
crossterm::event::{
KeyCode,
KeyEvent,
KeyModifiers,
},
};
let format = KeyEventFormat::default();
assert_eq!(format.to_string(key!(shift-a)), "Shift-a");
assert_eq!(format.to_string(key!(ctrl-c)), "Ctrl-c");
// A more compact format
let format = KeyEventFormat::default()
.with_implicit_shift()
.with_control("^");
assert_eq!(format.to_string(key!(shift-a)), "A");
assert_eq!(format.to_string(key!(ctrl-c)), "^c");
// A long format with lowercased modifiers
let format = KeyEventFormat::default()
.with_lowercase_modifiers();
assert_eq!(format.to_string(key!(ctrl-enter)), "ctrl-Enter");
assert_eq!(format.to_string(key!(home)), "Home");
assert_eq!(
format.to_string(
KeyEvent::new(
KeyCode::F(6),
KeyModifiers::ALT,
)
),
"alt-F6",
);
Fields
control: Stringalt: Stringshift: Stringenter: Stringuppercase_shift: boolImplementations
sourceimpl KeyEventFormat
impl KeyEventFormat
pub fn with_lowercase_modifiers(self) -> Self
pub fn with_control<S: Into<String>>(self, s: S) -> Self
pub fn with_alt<S: Into<String>>(self, s: S) -> Self
pub fn with_shift<S: Into<String>>(self, s: S) -> Self
pub fn with_implicit_shift(self) -> Self
sourcepub fn format(&self, key: KeyEvent) -> FormattedKeyEvent<'_>
pub fn format(&self, key: KeyEvent) -> FormattedKeyEvent<'_>
return a wrapper of the key implementing Display
use crokey::*;
let format = KeyEventFormat::default();
let k = format.format(key!(f6));
let s = format!("k={}", k);
assert_eq!(s, "k=F6");Trait Implementations
sourceimpl Clone for KeyEventFormat
impl Clone for KeyEventFormat
sourcefn clone(&self) -> KeyEventFormat
fn clone(&self) -> KeyEventFormat
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl Debug for KeyEventFormat
impl Debug for KeyEventFormat
Auto Trait Implementations
impl RefUnwindSafe for KeyEventFormat
impl Send for KeyEventFormat
impl Sync for KeyEventFormat
impl Unpin for KeyEventFormat
impl UnwindSafe for KeyEventFormat
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
🔬 This is a nightly-only experimental API. (
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more