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

Does not handle CR LF with a color change in between appropriately #30

Open
RLievaart opened this issue Jan 11, 2024 · 0 comments
Open

Comments

@RLievaart
Copy link

RLievaart commented Jan 11, 2024

As I found out the very hard way (half of my output not showing and an hour of debugging), some programs throw a color change in their output between a CR and a LF. I.e. [CR][ESC][31m[LF]

AnsiToHtmlConverter.php erases a line followd by [CR][color change][LF] since it thinks the color change is text at the beginning of a new line so it "overwrites" (deletes) the old line. It isn't Terminals like Putty will handle this correctly.

Proposed fix: for me this change in AnsiToHtmlConverter.php (line 50) worked.

$text = preg_replace('#^.*\r((\x9B|\x1B\[)[0-?]*[ -\/]*[@-~])*(?!\n)#ms', '', $text);

Probably the regex can be a bit simpler (I included all ANSI codes in the regex, that's overkill. I took it from https://stackoverflow.com/questions/14693701/how-can-i-remove-the-ansi-escape-sequences-from-a-string-in-python#33925425 ).

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

No branches or pull requests

1 participant