oclif / core

Node.js Open CLI Framework. Built by Salesforce.

Home Page:https://oclif.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ux.action.spinner overwrites most recent terminal output when updating spinner

mdonnalley opened this issue · comments

Describe the bug

The last line outputted to the terminal is overwritten when the spinner updates.

I've tracked it down to this line of code, https://github.com/oclif/core/blob/2.15.0/src/cli-ux/action/spinner.ts#L78, which uses ansi-escapes to move the cursor up and then erase everything underneath it. The underlying assumption is that it's moving the cursor to the beginning of the existing spinner, but that assumption fails once additional lines have been made to the terminal.

One potential solution is to use ansiEscapes.cursorSavePosition to capture the position of the cursor immediately after rendering the spinner and then use ansiEscapes.cursorRestorePosition to restore that position just before re-rendering it. I tested this and it did work until the spinner completed, at which point it cleared the additional logs. Maybe there's something to go off there.

To Reproduce

console.log('hello world 1') // this stays on the terminal
ux.action.start('starting spinner')
console.log('hello world 2')  // this stays on the terminal
console.log('hello world 3') // this gets overwritten once spinner updates
await ux.wait(2500)
ux.action.status = 'still going'
await ux.wait(2500)
ux.action.stop()
hello world 1
starting spinner...
hello world 2
starting spinner... done

This issue has been linked to a new work item: W-14208351