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: bool

Implementations

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");

return the key formatted into a string

format.to_string(key) is equivalent to format.format(key).to_string().

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.