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
**keymap-rs** is a lightweight and extensible key mapping library for Rust applications. It supports parsing key mappings from configuration files and mapping them to actions based on input events from backends like [`crossterm`](https://crates.io/crates/crossterm), [`termion`](https://docs.rs/termion/latest/termion/), `wasm`, and others.
**keymap-rs** is a lightweight and extensible key mapping library for Rust that simplifies input processing for terminal user interfaces (TUIs), WebAssembly (WASM) applications, and more. It parses keymaps from derive macros or configuration files and maps them to actions from various input backends, including [`crossterm`](https://crates.io/crates/crossterm), [`termion`](https://docs.rs/termion/latest/termion/), and [`wasm`](https://webassembly.org/).
> The table below shows all keys when using both the configuration file **and** the keys defined via `#[key("..")]`. The sets are merged.
122
-
>
123
-
> | Key | Action |
124
-
> | ------------- | ------ |
125
-
> |`"j"`, `"up"`| Jump |
126
-
> |`"left"`| Left |
127
-
> |`"right"`| Right |
128
-
> |`@any`| Quit |
127
+
#### `DerivedConfig<T>`: Merge Derived and File Configs
128
+
129
+
This **merges** the keybindings from the `#[key("...")]` attributes with the ones from the configuration file. Keys from the external file will override any conflicting keys defined in the enum.
One powerful advantage of using the `#[key(".."))]` attribute macro from `keymap_derive` is that invalid key definitions are caught at **compile time**, ensuring early feedback and safety.
144
+
### 3. Compile-Time Validation
138
145
139
-
#### Example: Invalid Key
146
+
The `keymap_derive` macro validates all key strings at **compile time**, so you get immediate feedback on invalid syntax.
147
+
148
+
**Invalid Key Example:**
140
149
141
150
```rust
142
151
#[derive(keymap::KeyMap)]
143
152
enumAction {
153
+
// "enter2" is not a valid key.
144
154
#[key("enter2", "ctrl-b n")]
145
155
Invalid,
146
156
}
147
157
```
148
158
149
-
#### Compile Error
159
+
**Compiler Error:**
160
+
161
+
This code will fail to compile with a clear error message:
150
162
151
163
```
152
164
error: Invalid key "enter2": Parse error at position 5: expect end of input, found: 2
@@ -156,7 +168,37 @@ error: Invalid key "enter2": Parse error at position 5: expect end of input, fou
156
168
| ^^^^^^^^
157
169
```
158
170
159
-
This prevents runtime surprises and provides clear diagnostics during development.
171
+
### 4. Direct Key Parsing
172
+
173
+
You can also parse key strings directly into a `KeyMap` or a backend-specific key event.
For complete, runnable examples, check out the [`/examples`](https://github.com/rezigned/keymap-rs/tree/main/examples) directory, which includes demos for:
197
+
-`crossterm`
198
+
-`termion`
199
+
-`wasm`
200
+
201
+
---
160
202
161
203
## 📜 License
162
204
@@ -166,4 +208,5 @@ This project is licensed under the [MIT License](https://github.com/rezigned/key
166
208
167
209
## 🙌 Contributions
168
210
169
-
Contributions, issues, and feature requests are welcome. Have an idea for a new backend, pattern rule, or integration? Open a PR!
211
+
Contributions, issues, and feature requests are welcome! Feel free to open an issue or submit a pull request.
0 commit comments