Giter Club home page Giter Club logo

Comments (5)

lox avatar lox commented on July 22, 2024

Test case: raw_ansi_output.log

from terminal-to-html.

pda avatar pda commented on July 22, 2024

Ooh interesting ๐Ÿ‘๐Ÿผ

from terminal-to-html.

pda avatar pda commented on July 22, 2024

I have a simplified reproduction based on that ๐Ÿ‘Œ๐Ÿผ

You're on the money, the output is using CSI n D / CUB / Cursor Back by n characters to overwrite the progress bar, and each _bk;ts=โ€ฆ timestamp throughout the line is consuming one of those CUBs.

I'll try to turn that into a test case and fix.

from terminal-to-html.

pda avatar pda commented on July 22, 2024

I wonder if this is also a bug in the agent's timestamping.

The timestamps in your raw_ansi_output.log appear in patterns roughly like this:

Hello <ESC>[0K <ESC>_bk;ts=โ€ฆ <ESC>[5D <ESC>[1B <ESC>[1A

Which means:

  • Hello โ€” ๐Ÿ‘‹๐Ÿผ some text already on the line
  • <ESC>[0K โ€”ย EL: Erase in Line (n=0: clear from cursor to the end of the line)
  • <ESC>_bk;ts=โ€ฆ โ€”ย Buildkite start of line timestamp
  • <ESC>[5D โ€”ย CUB: Cursor Back (5 cells)
  • <ESC>[1B โ€”ย CUD: Cursor Down 1 line
  • <ESC>[1A โ€” CUU: Cursor Up 1 line

โ€ฆ That's not where we should be putting a timestamp. The <ESC>[0K is basically saying โ€œI've overwritten part of this line, now ensure everything after the cursor is blanked, in case the old line was longerโ€. So we're not at the start of a line.

It would be nice if it didn't cause rendering bugs, but that's a separate issue โ€” even if resolved, it would leave out of order timestamps etc.

from terminal-to-html.

pda avatar pda commented on July 22, 2024

In the agent a log Prefixer is used to prefix lines with ANSI timestamp, and here's it's detection of escape codes that indicate a new line:

// This regex matches "Erase in Line" escape characters:
// [K Clear from cursor to the end of the line
// [1K Clear from cursor to beginning of the line
// [2K Clear entire line
var lineBreakEscapeCharRegex = regexp.MustCompile(`^\[[012]?K`)

We can see [K Clear from cursor to the end of the line is included intentionally, and also the equivalent [0K is handled by the regexp character class.

Here's the Wikipedia description of [nK:

Clears part of the screen. If n is 0 (or missing), clear from cursor to end of screen. If n is 1, clear from cursor to beginning of the screen. If n is 2, clear entire screen (and moves cursor to upper left on DOS ANSI.SYS). If n is 3, clear entire screen and delete all lines saved in the scrollback buffer (this feature was added for xterm and is supported by other terminal applications).

I imagine we want timestamps in the subset of cases where one of those clears the entire line; including perhaps [0K when the cursor is at the start of the line but not when it's mid-line. But maybe just not at all.

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

from terminal-to-html.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.