keybinds-rs
keybinds-rs is a small platform&framework-agnostic 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. (example) - Provide the core API independent from any platforms and frameworks with minimal (only two crates) dependencies. (example)
- Support several platforms and frameworks as optional features.
- Support parsing/generating a key bindings configuration using serde optionally.
- Support structure-aware fuzzing using arbitrary optionally. (example)
Installation
Usage
The following code demonstrates the usage by parsing key bindings configuration from TOML input and dispatching actions
to move the cursor inside terminal with the serde
and crossterm
optional features. This code can be run as the
example. See the API documentation for more details.
use ;
use ;
use Keybinds;
use Deserialize;
use io;
// Actions dispatched by key bindings
// Configuration of your application
const CONFIG_FILE_CONTENT: &str = r#"
[keyboard]
# Standard bindings
"Up" = "Up"
"Down" = "Down"
"Left" = "Left"
"Right" = "Right"
"PageUp" = "Top"
"PageDown" = "Bottom"
"Home" = "Home"
"End" = "End"
"Mod+q" = "Exit"
# Emacs-like bindings
"Ctrl+p" = "Up"
"Ctrl+n" = "Down"
"Ctrl+b" = "Left"
"Ctrl+f" = "Right"
"Alt+<" = "Top"
"Alt+>" = "Bottom"
"Ctrl+a" = "Home"
"Ctrl+e" = "End"
"Ctrl+x Ctrl+c" = "Exit"
# Vim-like bindings
"k" = "Up"
"j" = "Down"
"h" = "Left"
"l" = "Right"
"g g" = "Top"
"G" = "Bottom"
"^" = "Home"
"$" = "End"
"Esc" = "Exit"
"#;
Examples
For more usage, please see the working examples. They can be run locally by cargo run
inside this
repository. Some examples require some features enabled. For instance, to run the above crossterm
example:
Features
The list of crate features can be found in [features]
section of Cargo.toml. Please read the comments
on each features which explains about it.
Minimal supported Rust version (MSRV)
See rust-version
field of Cargo.toml 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.
Versioning
See the document.
License
This crate is licensed under the MIT license.