Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add extension point for stylizing console output #687

Merged
merged 15 commits into from
Mar 10, 2025
Merged

Conversation

cottsay
Copy link
Member

@cottsay cottsay commented Mar 4, 2025

This change provides two noteworthy APIs:

  • A set of "buckets" which call out specific categories of console output, like errors, warnings, package names, measurements, etc. This Style class can be imported in other colcon packages to annotate their console output.
  • An extension point for performing specific text augmentation for console output in these buckets.

Some example use cases:

  1. Colorizing (ANSI color escapes, etc)
  2. Formatting (markdown, RST, simple character tables, etc)
  3. Hyperlinks (HTTP, OSC 8, markdown, RST, etc)
  4. Collapsible blocks (Jenkins, GitHub Actions, etc)

This PR contains a sort of "smoke test" implementation for ANSI color codes. I intend to remove that implementation prior to merging this PR. It is only there to demonstrate behavior, and I'm not interested in debating what colors are appropriate or what the "default" behavior should be. We can consider adding lightweight stylizers directly to colcon_core at a later date - this PR is about getting the framework in-place.

To see a demo of what the styles look like without performing actual operations, run python3 -m colcon_core.output_style.

For now, the interface only allows you to select a single output style extension. It may be desirable in the future to differentiate between "primary" extensions of which only a single one should be used, and "secondary" extensions which overlay the primary one.

@cottsay cottsay added the enhancement New feature or request label Mar 4, 2025
@cottsay cottsay self-assigned this Mar 4, 2025
Copy link

codecov bot commented Mar 5, 2025

Codecov Report

Attention: Patch coverage is 96.22642% with 4 lines in your changes missing coverage. Please review.

Project coverage is 87.50%. Comparing base (c8f5479) to head (df1e247).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
colcon_core/output_style/__init__.py 94.87% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #687      +/-   ##
==========================================
+ Coverage   87.29%   87.50%   +0.21%     
==========================================
  Files          68       70       +2     
  Lines        3951     4050      +99     
  Branches      760      783      +23     
==========================================
+ Hits         3449     3544      +95     
  Misses        396      396              
- Partials      106      110       +4     

☔ 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.

@nuclearsandwich
Copy link
Contributor

  • A set of "buckets" which call out specific categories of console output, like errors, warnings, package names, measurements, etc.

At first I thought that this implementation would only support style buckets defined in a central API. But I actually think that the way output style extensions work the style extension can decide which styles to implement. However, the call sites where styles are actually used must also only use styles exist in the provided output style, so we're realistically going to wind up with a centrally agreed upon list of styling options.

This differs from an after-the-fact decorator like Vim's syntax highlighting patterns or a markup, then style approach which allows for the style formatter to drop styles it doesn't know what to do with.

Do you anticipate any strife with having a limited set of well supported style options or is that an explicit goal of the feature?

cottsay added 2 commits March 7, 2025 12:27
This should behave similarly to a defaultdict, but with attributes.
@cottsay
Copy link
Member Author

cottsay commented Mar 7, 2025

...the call sites where styles are actually used must also only use styles exist in the provided output style, so we're realistically going to wind up with a centrally agreed upon list of styling options.

This is a good point. I set up a default getter in 65a7364 that should allow call sites to use styles that aren't explicitly defined by the selected provider.

Copy link
Contributor

@nuclearsandwich nuclearsandwich left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approval here is focused on the proposed OutputStyle extension API since the AnsiEscape example is included only for testing.

@cottsay cottsay merged commit 7a3bf42 into master Mar 10, 2025
36 checks passed
@cottsay cottsay deleted the cottsay/output-style branch March 10, 2025 21:35
@cottsay cottsay added this to the 0.18.5 milestone Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Development

Successfully merging this pull request may close these issues.

2 participants