buildkite / terminal-to-html

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

Buildkite timestamps only at start of line, via screenLine.metadata #99

Closed pda closed 2 years ago

pda commented 2 years ago

As discussed in #96 and #97, Buildkite timestamps (<ESC>_bk;t=123456<BEL>) were corrupting virtual terminal X position when moving the cursor backwards through them (“CUB”: <ESC>[<distance>D). This is because they occupied a position on the terminal intermediate representation X,Y grid, and parsing/appending them incremented the internal X-position state. Buildkite timestamps should generally only appear at the start of lines, where this isn't a problem, but certain ANSI sequences cause buildkite/agent to place them mid-line.

This pull request introduces a “line metadata” structure, supporting namespaced key:value data attached to entire lines. For example the Buildkite APC <ESC>_bk;t=1234<BEL> places t1234 under the bk namespace. Subsequent _bk;t APCs on the same line are ignored. The bk namespace is then rendered as <?bk t="1234"?> prior to the line's terminal data, so it's always at the start of the line.

Some refactoring to achieve that:

This PR is currently based on some other more minor refactoring that was extracted from a previous approach that I don't want to merge.

Related: