You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: support Key Group Capturing for dynamic variant data (#35)
- Added `KeyMapConfig::bind()` for mapping matched key groups to enum payloads.
- Implemented `get_bound_*` lookup methods to return owned, captured variants.
- Modified macro to identify key group indices for all macros (@any, @Digit, etc.).
- Automated `Serialize` and `Deserialize` generation to prevent map-key collisions.
- Refreshed project documentation and examples with the new terminology.
Copy file name to clipboardExpand all lines: README.md
+14Lines changed: 14 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,6 +27,7 @@
27
27
* ✅ **Declarative Key Mappings**: Define keymaps via simple configuration files (e.g., TOML, YAML) or directly in your code using derive macros.
28
28
* ⌨️ **Key Patterns**: Supports single keys (`a`), combinations (`ctrl-b`), and multi-key sequences (`ctrl-b n`).
29
29
* 🧠 **Key Groups**: Use built-in pattern matching for common key groups (`@upper`, `@lower`, `@alpha`, `@alnum`, and `@any`).
30
+
* 📸 **Key Group Capturing**: Capture specific keypress data (like the actual `char` from `@any` or `@digit`) directly into your action enum variants at runtime.
30
31
* 🧬 **Compile-Time Safety**: The `keymap_derive` macro validates key syntax at compile time, preventing runtime errors.
31
32
* 🌐 **Backend-Agnostic**: Works with multiple backends, including `crossterm`, `termion`, and `wasm`.
32
33
* 🪶 **Lightweight & Extensible**: Designed to be minimal and easy to extend with new backends or features.
@@ -97,6 +98,11 @@ pub enum Action {
97
98
/// Jump.
98
99
#[key("space")]
99
100
Jump,
101
+
102
+
/// Key Group Capturing action (e.g. tracking which character was pressed).
103
+
/// `char` will be captured from any matched key group macro (like `@any` or `@digit`) at runtime.
104
+
#[key("@any")]
105
+
Shoot(char),
100
106
}
101
107
```
102
108
@@ -109,6 +115,7 @@ The `KeyMap` derive macro generates an associated `keymap_config()` method, whic
109
115
letconfig=Action::keymap_config();
110
116
111
117
// `key` is a key code from the input backend, e.g., `crossterm::event::KeyCode`
118
+
// You can lookup the default pre-instantiated action reference:
112
119
matchconfig.get(&key) {
113
120
Some(action) =>matchaction {
114
121
Action::Quit=>break,
@@ -117,8 +124,15 @@ match config.get(&key) {
117
124
}
118
125
_=> {}
119
126
}
127
+
128
+
// Or use Key Group Capturing to extract the actual `char` from `@any` or `@digit`!
> **Note**: `keymap_derive` automatically generates custom `Serialize` and `Deserialize` implementations for the derived `enum`, making your variants with captured data serialize as simple tags (e.g. `"Shoot"`) out of the box so that Map deserialization continues to work flawlessly.
135
+
122
136
### 2. Using External Configuration
123
137
124
138
`keymap-rs` also supports loading keymaps from external files (e.g., `config.toml`). This is useful for user-configurable keybindings.
0 commit comments