Skip to content

Add custom key bindings via config.toml#48

Merged
ptrsauer merged 2 commits intomainfrom
feat/custom-keybindings
Feb 15, 2026
Merged

Add custom key bindings via config.toml#48
ptrsauer merged 2 commits intomainfrom
feat/custom-keybindings

Conversation

@ptrsauer
Copy link
Owner

Summary

  • Adds [key_map] section to config.toml for customizing key bindings
  • Rebindable actions: quit, restart, repeat, practice_missed, practice_slow, new_test
  • Supports single characters ("q"), special keys ("Tab", "Space"), and modifiers ("C-r" for Ctrl+R, "A-q" for Alt+Q)
  • Conflict detection warns on startup if two actions share the same key
  • Results screen dynamically shows configured key labels

Design Decisions

  • Only results screen actions + new_test (Tab) are rebindable — typing mechanics (Space, Backspace) stay hardcoded to avoid destabilizing core test logic
  • Esc and Ctrl+C remain hardcoded as global exit controls
  • Exact modifier matching (pressing Ctrl+Q won't trigger a plain "q" binding)
  • ThemedWidget trait now receives &Config instead of &Theme for clean key_map access in rendering

Test plan

  • 10 new tests for key parsing, matching, TOML deserialization, defaults, and conflict detection
  • All 106 tests pass (97 unit + 9 integration)

Closes #42

🤖 Generated with Claude Code

ptrsauer and others added 2 commits February 15, 2026 21:36
Allows users to customize key bindings for results screen actions
(quit, restart, repeat, practice missed/slow) and the new test key
(Tab) through a [key_map] section in config.toml. Supports single
characters, special keys (Tab, Space, etc.), and Ctrl/Alt modifiers.

- Add KeyMap struct with KeyBinding type and serde deserialization
- Add key parsing for chars, special keys, and C-/A- modifiers
- Add conflict detection with warnings on startup
- Update results screen to show configured key labels dynamically
- Refactor ThemedWidget to receive &Config (access to both theme and key_map)
- Add 10 new tests for parsing, matching, config, and conflicts

Closes #42

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…l errors

- Fix Unicode character parsing (use chars().count() instead of len())
- Include hardcoded Esc and Ctrl+C in conflict detection
- Replace config panic with graceful fallback to defaults
- Add 4 new tests: Unicode parsing, Esc/Ctrl+C conflicts, empty string

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@ptrsauer ptrsauer merged commit 64daca9 into main Feb 15, 2026
6 checks passed
@ptrsauer ptrsauer deleted the feat/custom-keybindings branch February 15, 2026 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom key bindings via config.toml

1 participant