Skip to content

Improve support for ANSI escape sequences and document the behavior - #184

Merged
astanin merged 2 commits into
astanin:masterfrom
shaunduncan:ansi-fix
Oct 6, 2022
Merged

astanin merged 2 commits into
astanin:masterfrom
shaunduncan:ansi-fix

Conversation

@shaunduncan

Copy link
Copy Markdown

I kept having issues when piping the output of a command whose output was colorized with ANSI escape sequences. The length calculations for strings that contained non-printable ANSI were incorrect and resulted in columns being misaligned. I modified the regex for this to handle CSI escaped codes and OSC escaped hyperlinks (for terminals that support it).

I've also some documentation to explain the technical details as well as explain the output behavior when ANSI sequences are present.

I think this should also resolve #164 and #150

@kdeldycke

Copy link
Copy Markdown
Contributor

That's great indeed! Would love to have this merged upstream!

@kdeldycke

Copy link
Copy Markdown
Contributor

I implemented a while ago a regex to strip ANSI sequences like you did here. Just a note if you want to compare implementations: https://github.com/mahmoud/boltons/blob/6c7fa3e05659fac6515f661153c89d4ad02df168/boltons/strutils.py#L374-L428

kdeldycke added a commit to kdeldycke/meta-package-manager that referenced this pull request Jul 8, 2022
@astanin

astanin commented Oct 6, 2022

Copy link
Copy Markdown
Owner

Thank you. This seems to be a much cleaner implementation.

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.

ANSI escape detection doesn't work in byte strings

3 participants