1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//! # Overview
//!
//! [keybinds-rs][crates-io] is a small crate to parse/generate/dispatch key bindings (keyboard shortcuts) written
//! in Safe Rust. You can easily introduce customizable key bindings to your application using this library.
//!
//! - Provide the syntax to easily define key bindings in a configuration file like `Ctrl+a`
//! - Support key sequences like `Ctrl+x Ctrl+s` for complicated key bindings like Vim style
//! - Core API independent from any platforms and frameworks with minimal dependencies (only two crates)
//! - Support several platforms and frameworks as optional features
//! - [crossterm][]
//! - [termwiz][]
//! - [winit][]
//! - [iced][]
//! - Support parsing/generating a key bindings configuration using [serde][] optionally
//! - Support structure-aware fuzzing using [arbitrary][] optionally.
//!
//! # Installation
//!
//! ```sh
//! cargo add keybinds
//! ```
//!
//! # Minimal example
//!
//! ```
//! use keybinds::{Keybinds, KeyInput, Key, Mods};
//!
//! // Actions dispatched by key bindings
//! #[derive(PartialEq, Eq, Debug)]
//! enum Action {
//! SayHello,
//! OpenFile,
//! ExitApp,
//! }
//!
//! // Create a key bindings dispatcher to dispatch actions for upcoming key inputs
//! let mut keybinds = Keybinds::default();
//!
//! // Register key bindings to dispatch the actions
//!
//! // Key sequence "h" → "e" → "l" → "l" → "o"
//! keybinds.bind("h e l l o", Action::SayHello).unwrap();
//! // Key combination "Ctrl + Alt + Enter"
//! keybinds.bind("Ctrl+Alt+Enter", Action::OpenFile).unwrap();
//! // Sequence of key combinations
//! keybinds.bind("Ctrl+x Ctrl+c", Action::ExitApp).unwrap();
//!
//! // Dispatch `SayHello` action
//! assert_eq!(keybinds.dispatch('h'), None);
//! assert_eq!(keybinds.dispatch('e'), None);
//! assert_eq!(keybinds.dispatch('l'), None);
//! assert_eq!(keybinds.dispatch('l'), None);
//! assert_eq!(keybinds.dispatch('o'), Some(&Action::SayHello));
//!
//! // Dispatch `OpenFile` action
//! let action = keybinds.dispatch(KeyInput::new(Key::Enter, Mods::CTRL | Mods::ALT));
//! assert_eq!(action, Some(&Action::OpenFile));
//!
//! // Dispatch `ExitApp` action
//! assert_eq!(keybinds.dispatch(KeyInput::new('x', Mods::CTRL)), None);
//! assert_eq!(keybinds.dispatch(KeyInput::new('c', Mods::CTRL)), Some(&Action::ExitApp));
//! ```
//!
//! # More examples
//!
//! For more usage, please see [the examples][examples]. They can be run locally by `cargo run` inside this repository.
//! Some examples require some features enabled. For instance, to run the `crossterm` example:
//!
//! ```sh
//! cargo run --example crossterm --features=crossterm,serde
//! ```
//!
//! # Features
//!
//! The list of crate features can be found in `[features]` section of [Cargo.toml][metadata]. Please read the comments
//! on each features which explains about it.
//!
//! # Minimal supported Rust version (MSRV)
//!
//! See `rust-version` field of [Cargo.toml][metadata] for the minimal supported Rust version. Note that enabling
//! optional features may require some higher Rust versions due to the optional dependencies introduced by them.
//!
//! [crates-io]: https://crates.io/crates/keybinds
//! [serde]: https://serde.rs/
//! [crossterm]: https://crates.io/crates/crossterm
//! [winit]: https://crates.io/crates/winit
//! [iced]: https://crates.io/crates/iced
//! [termwiz]: https://crates.io/crates/termwiz
//! [arbitrary]: https://crates.io/crates/arbitrary
//! [examples]: https://github.com/rhysd/keybinds-rs/tree/main/examples
//! [metadata]: https://github.com/rhysd/keybinds-rs/blob/main/Cargo.toml
//!
//! [!Caution]: #modifiers
pub use ;
pub use ;
pub use ;