commitizen
commitizen copied to clipboard
Feat: add live subject preview for interactive commit (--preview)
#1901
The implementation is based on Questionary's bottom_toolbar
Description
- Add
--previewflag (and configpreview) to show a live first-line (subject) preview while typing duringcz commit. - Display a bottom toolbar with subject preview + character counter; wrap by terminal display width (handles CJK width).
- Add a subject length validator that respects
message_length_limit(0 disables limit).
Checklist
- [X] I have read the contributing guidelines
Was generative AI tooling used to co-author this PR?
- [X] Yes (please specify the tool below)
Generated-by: [Cursor] following the guidelines
Code Changes
- [X] Add test cases to all the changes you introduce
- [X] Run
uv run poe alllocally to ensure this change passes linter check and tests - [X] Manually test the changes:
- [X] Verify the feature/bug fix works as expected in real-world scenarios
- [X] Test edge cases and error conditions
- [X] Ensure backward compatibility is maintained
- [x] Document any manual testing steps performed
- [x] Update the documentation for the changes
Documentation Changes
- [X] Run
uv run poe doclocally to ensure the documentation pages renders correctly - [X] Check and fix any broken links (internal or external)
Expected Behavior
- Running
cz commit --previewshows a live subject preview and a character counter while answering interactive questions. - Existing behavior remains unchanged when preview is disabled (default).
Steps to Test This Pull Request
Manual:
cz commit --preview(observe live subject preview + counter)cz commit --preview -l 72(confirm counter showscurrent/72and validation triggers when exceeded)
Additional Context
- New modules:
commitizen/interactive_preview.py,commitizen/preview_questions.py - CLI/config additions:
commitizen/cli.pyadds--preview;commitizen/defaults.pyaddspreviewsetting (defaultFalse) - Docs demos:
docs/images/cli_interactive/commit_preview.gif,docs/images/cli_interactive/commit_preview_length_limit.gif(+.tape)
Codecov Report
:x: Patch coverage is 93.07692% with 9 lines in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 97.79%. Comparing base (33223b4) to head (f18c7ae).
:warning: Report is 3 commits behind head on master.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| commitizen/question.py | 0.00% | 9 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## master #1902 +/- ##
==========================================
- Coverage 97.99% 97.79% -0.20%
==========================================
Files 60 62 +2
Lines 2689 2811 +122
==========================================
+ Hits 2635 2749 +114
- Misses 54 62 +8
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.