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
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
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
Mutably borrows from an owned value. Read more