Skip to content

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

@RLievaart

Description

@RLievaart

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions