agent icon indicating copy to clipboard operation
agent copied to clipboard

Prefixer for ANSI timestamps overzealous on escape-code-new-lines

Open pda opened this issue 1 year ago • 1 comments

As discussed in https://github.com/buildkite/terminal-to-html/issues/96#issuecomment-1204807847 it seems the Prefixer used (exclusively) by ansi-timestamps experiment is overzealous on declaring CSI n K (EL: Erase in Line) ANSI codes as newlines when sometimes they're in the middle of a line.

This:

  • raises questions about out-of-order timestamps caused by backwards cursor movement, and
  • combines with a buildkite/terminal-to-html bug to miscalculate position and corrupt output during overwrite.

As I wrote in that issue:

Fortunately ansi-timestamps is still in experiment status, so I think we have a bit more freedom to change this behaviour.

We might want to stop considering Erase in Line as a newline at all, and/or we might want to instead treat some other escape codes as newlines.

I think this might get tricky because the prefixer / log output doesn't maintain a terminal emulator state like buildkite/terminal-to-html does, so it's probably impossible to know which combinations of movement and erasing result in a “new line” timestamp candidate 😬

pda avatar Aug 04 '22 06:08 pda

It's possible the agent side of this isn't quite a bug. Lox says:

I think what we were aiming for was to add timestamps incrementally for long-running single lines

It's possible the current escape code regexp is a (sub)set of “interesting looking moments to timestamp”, and that if anything it could be expanded, or changed to a “insert a timestamp at least every X seconds” model.

Maybe.

Edit: see also https://github.com/buildkite/terminal-to-html/pull/97#issuecomment-1204833608 🐴👄

pda avatar Aug 04 '22 07:08 pda