keybinds-rs
THIS CRATE IS WORK IN PROGRESS YET. The first beta release is planned as 0.1.0. Until then, this library can be buggy and have arbitrary breaking changes.
keybinds-rs is a small Rust crate to parse/generate/dispatch key bindings (keyboard shortcuts).
- Provide the syntax to easily define key bindings in a configuration file like
Ctrl+a
. (document) - Support key sequences like
Ctrl+x Ctrl+s
for complicated key bindings like Vim style. - Provide the core API independent from any platforms and frameworks with minimal dependencies (only one crate). (example)
- Support several platforms and frameworks as optional features.
- Support to parse/generate the key bindings configuration using serde optionally.
- Support structure-aware fuzzing using arbitrary optionally. (example)
Installation
Usage
This code demonstrates the usage by parsing and dispatching key bindings for moving the cursor inside terminal
using the serde
and crossterm
optional features. You can try this code as an example.
See the API documentation for more details.
use ;
use ;
use ;
use Deserialize;
use io;
// Actions dispatched by key bindings
// Configuration of your app
const CONFIG_FILE: &str = r#"
[keyboard]
"Esc" = "Exit"
# Standard bindings
"Up" = "Up"
"Down" = "Down"
"Left" = "Left"
"Right" = "Right"
"PageUp" = "Top"
"PageDown" = "Bottom"
"Home" = "Home"
"End" = "End"
# 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"
# Vim-like bindings
"k" = "Up"
"j" = "Down"
"h" = "Left"
"l" = "Right"
"g g" = "Top"
"G" = "Bottom"
"^" = "Home"
"$" = "End"
"#;
Examples
For more usage, please see the examples. They can be run locally by cargo run
inside this repository.
Some examples require some features enabled. For instance, to run termwiz
example:
License
This crate is licensed under the MIT license.