Skip to content

Handle the \r character correctly in log viewer

However, there is something we're missing, which I think is known here (at least, it was to me, and I can't remember whether I explained it to @mrincon): we're not yet handling \r yet.

\r is supposed to reset the cursor back to the start of the line. Any text then written, overwrites that line. This is useful for progress bar updates, which the Ruby implementation does handle: like progress: 10%\rprogress: 20%.

A good example of this is using job variable TRANSFER_METER_FREQUENCY: 1s and having a job that downloads an artifact/cache as it will tell you the progress.

For Windows that provides \r\n you're doing a reset cursor and jump to next line. Nothing visually changes in this case (although, technically, you are performing 2 ops instead of 1).

So we eventually need to handle \r, but we don't really need to handle \r\n because that'll just take care of itself when we handle \r correctly.

The following discussion from !145499 (merged) should be addressed:

  • @leipert started a discussion: (+1 comment)

    Question Do we need to handle \r\n as well for windows runners or do runners already normalize line endings?

Edited by Miguel Rincon