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

Handle ANSI escape sequences during text wrapping #2833

Closed
jeremy-rifkin opened this issue Mar 8, 2024 · 0 comments · Fixed by #2849
Closed

Handle ANSI escape sequences during text wrapping #2833

jeremy-rifkin opened this issue Mar 8, 2024 · 0 comments · Fixed by #2849

Comments

@jeremy-rifkin
Copy link
Contributor

Description

I'd like to provide diagnostic messages from a Catch::Matchers::MatcherBase::describe function that are colored with ANSI sequences, however Catch2's line wrapping interferes with this.

Would a PR to update the line wrapping logic be welcomed?

Additional context

I have an assertion library that I'd like to provide a catch2 integration for. Without color codes, with my current attempt to make it work in Catch2, it looks like this:

image

However with color codes the lines are messed up and escape sequences are split in the middle:

image

horenmar pushed a commit that referenced this issue May 4, 2024
This PR adds functionality to skip around ANSI escape sequences in catch_textflow so they do not contribute to line length and line wrapping code does not split escape sequences in the middle. I've implemented this by creating a AnsiSkippingString abstraction that has a bidirectional iterator that can skip around escape sequences while iterating. Additionally I refactored Column::const_iterator to be iterator-based rather than index-based so this abstraction is a simple drop-in for std::string.

Currently only color sequences are handled, other escape sequences are left unaffected.

Motivation: Text with ANSI color sequences gets messed up when being output by Catch2 #2833.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants