use readline instead

This commit is contained in:
Jacky Zhao 2025-03-13 08:46:55 -07:00
parent 07ffc8681e
commit de727b4686

View File

@ -1,3 +1,5 @@
import readline from "readline"
export class QuartzLogger { export class QuartzLogger {
verbose: boolean verbose: boolean
private spinnerInterval: NodeJS.Timeout | undefined private spinnerInterval: NodeJS.Timeout | undefined
@ -16,8 +18,8 @@ export class QuartzLogger {
} else { } else {
this.spinnerIndex = 0 this.spinnerIndex = 0
this.spinnerInterval = setInterval(() => { this.spinnerInterval = setInterval(() => {
process.stdout.clearLine(0) readline.clearLine(process.stdout, 0)
process.stdout.cursorTo(0) readline.cursorTo(process.stdout, 0)
process.stdout.write(`${this.spinnerChars[this.spinnerIndex]} ${this.spinnerText}`) process.stdout.write(`${this.spinnerChars[this.spinnerIndex]} ${this.spinnerText}`)
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerChars.length this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerChars.length
}, 100) }, 100)
@ -32,8 +34,8 @@ export class QuartzLogger {
if (!this.verbose && this.spinnerInterval) { if (!this.verbose && this.spinnerInterval) {
clearInterval(this.spinnerInterval) clearInterval(this.spinnerInterval)
this.spinnerInterval = undefined this.spinnerInterval = undefined
process.stdout.clearLine(0) readline.clearLine(process.stdout, 0)
process.stdout.cursorTo(0) readline.cursorTo(process.stdout, 0)
} }
if (text) { if (text) {