Skip to content

Support colored help output - #1328

Open
Zhou-London wants to merge 13 commits into
CLIUtils:mainfrom
Zhou-London:feature/color-formatter
Open

Support colored help output#1328
Zhou-London wants to merge 13 commits into
CLIUtils:mainfrom
Zhou-London:feature/color-formatter

Conversation

@Zhou-London

Copy link
Copy Markdown

This PR adds support for the colored help output regarding the dicuss in issue: #1285
Functions are added into the Default Formatter. When color_enabled_ is true, ANSI codes are injected into the stream to display various colors.

Certain formatting logic has been modified in the colored branch (color_enabled_ == true):

  • Count visual_length instead of the actual length, for that the latter one include the ANSI codes, which are not displayed.
  • Colorize the header/option/etc. before putting them to the stream.
  • The color palette is defined as macros in Macros.h

Usage:

app.get_formatter()->enable_color();

An example and a new test has been added. Readme has been updated as well. All tests are passed on my x86 Linux (Arch)
machine.

ffb22712e2108d43bfcdb8943d82cf5b

@codecov

codecov Bot commented Apr 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.17730% with 35 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.33%. Comparing base (e4ee3af) to head (ca9afcc).
⚠️ Report is 195 commits behind head on main.

Files with missing lines Patch % Lines
include/CLI/impl/Formatter_inl.hpp 81.10% 24 Missing ⚠️
include/CLI/impl/StringTools_inl.hpp 0.00% 11 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##              main    #1328      +/-   ##
===========================================
- Coverage   100.00%   99.33%   -0.67%     
===========================================
  Files           17       19       +2     
  Lines         4546     5243     +697     
  Branches         0     1121    +1121     
===========================================
+ Hits          4546     5208     +662     
- Misses           0       35      +35     

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Sckab

Sckab commented Jun 21, 2026

Copy link
Copy Markdown

please don't quit this PR, it's so good and helpful

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.

2 participants