buildkite / terminal-to-html

Converts arbitrary shell output (with ANSI) into beautifully rendered HTML
http://buildkite.github.io/terminal-to-html
MIT License
642 stars 45 forks source link

Overwrite line metadata #109

Closed DrJosh9000 closed 11 months ago

DrJosh9000 commented 11 months ago

What timestamp should a rewritten line have?

I argue we should replace old line metadata with new metadata. This will make timestamps look more sensible in ESC [1A ESC [K-heavy output.

For example, when faced with updating the existing screen (pseudo-rendered):

<?bk t="0"?>Commencing build...
<?bk t="1"?>Enumerating packages...

with a sequence like ESC [1A ESC [K ESC _bk;t=200 BEL Completed! LF, we currently get

<?bk t="0"?>Commencing build...
<?bk t="1"?>Completed!

which is nonsensical from a timestamp perspective (Completed! actually happened at t=200).

The current approach does have a benefit: assuming the timestamps are non-decreasing, it is somewhat possible to derive the "duration" of a line (assuming each line is printed at the very start of a chunk of processing). In the example above, Commencing build... can be inferred to take Δt = 1; if Completed! has t=200, then Commencing build...'s inferred Δt = 200, when 199 of that was actually spent starting with package enumeration. But to do this effectively requires making that assumption.

I also tweaked the style of setLineMetadata, and implemented an optimisation for clear.