Skip to content

Feat: add live subject preview for interactive commit (--preview)#1902

Open
ttw225 wants to merge 20 commits intocommitizen-tools:masterfrom
ttw225:feat/preview-and-word-count
Open

Feat: add live subject preview for interactive commit (--preview)#1902
ttw225 wants to merge 20 commits intocommitizen-tools:masterfrom
ttw225:feat/preview-and-word-count

Conversation

@ttw225
Copy link
Contributor

@ttw225 ttw225 commented Mar 18, 2026

#1901
The implementation is based on Questionary's bottom_toolbar

Description

  • Add --preview flag (and config preview) to show a live first-line (subject) preview while typing during cz 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

Was generative AI tooling used to co-author this PR?

  • Yes (please specify the tool below)

Generated-by: [Cursor] following the guidelines

Code Changes

  • Add test cases to all the changes you introduce
  • Run uv run poe all locally to ensure this change passes linter check and tests
  • Manually test the changes:
    • Verify the feature/bug fix works as expected in real-world scenarios
    • Test edge cases and error conditions
    • Ensure backward compatibility is maintained
    • Document any manual testing steps performed
  • Update the documentation for the changes

Documentation Changes

  • Run uv run poe doc locally to ensure the documentation pages renders correctly
  • Check and fix any broken links (internal or external)

Expected Behavior

  • Running cz commit --preview shows 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 shows current/72 and validation triggers when exceeded)

Additional Context

  • New modules: commitizen/interactive_preview.py, commitizen/preview_questions.py
  • CLI/config additions: commitizen/cli.py adds --preview; commitizen/defaults.py adds preview setting (default False)
  • Docs demos: docs/images/cli_interactive/commit_preview.gif, docs/images/cli_interactive/commit_preview_length_limit.gif (+ .tape)

@codecov
Copy link

codecov bot commented Mar 18, 2026

Codecov Report

❌ Patch coverage is 93.07692% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 97.79%. Comparing base (33223b4) to head (f18c7ae).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
commitizen/question.py 0.00% 9 Missing ⚠️
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     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ttw225 ttw225 changed the title Feat/preview and word count Feat: add live subject preview for interactive commit (--preview) Mar 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant