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

fix(ansi): cut/truncate/truncateleft improperly handling new lines #367

Merged
merged 18 commits into from
Feb 11, 2025

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Feb 10, 2025

I'm not sure this is the best way to handle this, but, without this
patch, truncates would still use new lines from outside its cut target.

This fixes it.

closes #351

I'm not sure this is the best way to handle this, but, without this
patch, truncates would still use new lines from outside its cut target.

This fixes it.
@caarlos0 caarlos0 self-assigned this Feb 10, 2025
@caarlos0 caarlos0 added the bug Something isn't working label Feb 10, 2025
@aymanbagabas
Copy link
Member

This is related to #351

@aymanbagabas
Copy link
Member

Could you add the tests from #351 here?

Copy link
Member

@aymanbagabas aymanbagabas left a comment

Choose a reason for hiding this comment

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

TruncateLeft still ignores newlines even if they're within the range

@caarlos0
Copy link
Member Author

TruncateLeft still ignores newlines even if they're within the range

seems to be working fine to me, even added another test for it.

PS: the problem was that it wasn't ignoring out of the cut new lines - so it was including all of them.

@@ -142,6 +143,14 @@ func truncate(m Method, s string, length int, tail string) string {
// collects printable ASCII
curWidth++
fallthrough
case parser.ExecuteAction:
Copy link
Member

Choose a reason for hiding this comment

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

so in case of a new line, it will be ignored?

Copy link
Member

Choose a reason for hiding this comment

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

nevermind saw your comment

Copy link
Member

@raphamorim raphamorim left a comment

Choose a reason for hiding this comment

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

👍

@caarlos0 caarlos0 merged commit cd7b2ce into main Feb 11, 2025
8 checks passed
@caarlos0 caarlos0 deleted the fix-multiline branch February 11, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
3 participants