Skip to content

Commit 240a5d1

Browse files
Patrick Carrollclaude
andcommitted
Update README and CLAUDE.md
README: add --print-layout / -p flag to both command synopses and usage examples. CLAUDE.md: document the trait conventions for domain types (Display = ZMK, qmk_name() for QMK, From<&str> for mixed-format parsing), note that ToZmk/ToQmk were removed and must not be reintroduced, and add the cmp_owned allow exception for KeyExpr's PartialEq impls. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5be555a commit 240a5d1

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

CLAUDE.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ examples/
4444

4545
All code must pass `cargo clippy --all-targets -- -W clippy::pedantic -D warnings` with no errors. This is enforced by CI. Run it locally before committing.
4646

47-
The one deliberate exception is `#[allow(clippy::implicit_hasher)]` on `parse_key_expr_str` — threading separate hasher type parameters through all private helpers adds noise without value for a CLI tool.
47+
Deliberate exceptions:
48+
49+
- `#[allow(clippy::implicit_hasher)]` on `parse_key_expr_str` — threading separate hasher type parameters through all private helpers adds noise without value for a CLI tool.
50+
- `#[allow(clippy::cmp_owned)]` on `KeyExpr`'s `PartialEq<&str>` / `PartialEq<str>` impls — the `Modified` variant (nested modifier expressions like `LG(LS(LBKT))`) must build a formatted string to compare; there is no allocation-free alternative.
4851

4952
## Testing
5053

@@ -77,6 +80,18 @@ all of these are done and verified:
7780
9. Report the pushed commit, pushed tag, GitHub Release workflow status, and
7881
crates.io version.
7982

83+
## Trait conventions for domain types
84+
85+
The typed domain types in `src/codes.rs` (`KeyCode`, `Modifier`, `KeyExpr`, `RgbAction`, `MouseMovement`, `MouseButton`, `MouseScroll`, `ModPrefix`) follow a consistent pattern:
86+
87+
- **`Display`** outputs the **ZMK** spelling. This is the canonical string form; use `.to_string()` or format interpolation `{x}` wherever a ZMK string is needed.
88+
- **`qmk_name()` / `qmk_mod_name()`** methods return the **QMK** spelling as `&str`. Call these directly in QMK renderers; do not add a trait wrapper.
89+
- `Modifier` exposes three QMK spellings: `qmk_mod_name()` (`MOD_LSFT`, used in `MT`/`OSM`), `qmk_fn_name()` (`LSFT`, used in modifier-wrapping functions), and `zmk_name()` via `Display`.
90+
- `KeyExpr` has a `to_qmk() -> String` method for the recursive modifier-expression case (e.g. `LGUI(LSFT(KC_LBRC))`).
91+
- **`From<&str>` / `From<String>`** are implemented for types with an `Unknown` fallback variant. They try ZMK spelling first, then QMK, then fall back to `Unknown(raw)`. Use these when the source format is ambiguous or mixed.
92+
- **`from_qmk(s)` / `from_zmk(s)`** associated functions return `Option<Self>` for strict format-specific parsing (no `Unknown` fallback). Prefer these in parsers where the input format is known.
93+
- There are **no custom `ToZmk` or `ToQmk` traits**. Earlier versions had them; they were removed because `Display` already covers the ZMK case and the QMK case has no stdlib equivalent. Don't reintroduce them.
94+
8095
## Key mapping conventions
8196

8297
QMK and ZMK use different names for the same physical keys. The canonical mapping lives in `src/codes.rs`. Notable differences:

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Options:
4646
--cols <COLS> Override columns per row in ZMK output
4747
--list-keyboards List known keyboards and their column counts, then exit
4848
--no-warn Suppress warnings for unmapped keycodes
49+
-p, --print-layout Parse the keymap and print a layout table, then exit
4950
-h, --help Print help
5051
```
5152

@@ -68,6 +69,9 @@ qmk2zmk keymap.c --cols 10
6869
# List known keyboards
6970
qmk2zmk --list-keyboards
7071

72+
# Print a human-readable layout table without converting
73+
qmk2zmk keymap.c --print-layout
74+
7175
# Explicit format flag
7276
qmk2zmk -f json keymap.json -o my_keymap.keymap
7377
```
@@ -88,6 +92,7 @@ Options:
8892
--cols <COLS> Override columns per row in QMK C output
8993
--list-keyboards List known keyboards and their column counts, then exit
9094
--no-warn Suppress warnings for unmapped keycodes
95+
-p, --print-layout Parse the keymap and print a layout table, then exit
9196
-h, --help Print help
9297
```
9398

@@ -106,6 +111,9 @@ zmk2qmk my_keymap.keymap -f c --keyboard corne
106111

107112
# List known keyboards
108113
zmk2qmk --list-keyboards
114+
115+
# Print a human-readable layout table without converting
116+
zmk2qmk my_keymap.keymap --print-layout
109117
```
110118

111119
## What gets converted

0 commit comments

Comments
 (0)