replace spinner, use disk cache for fonts

This commit is contained in:
Jacky Zhao
2025-03-13 08:38:16 -07:00
parent f301eca9a7
commit 07ffc8681e
7 changed files with 90 additions and 66 deletions

View File

@@ -1,26 +1,41 @@
import { Spinner } from "cli-spinner"
export class QuartzLogger {
verbose: boolean
spinner: Spinner | undefined
private spinnerInterval: NodeJS.Timeout | undefined
private spinnerText: string = ""
private spinnerIndex: number = 0
private readonly spinnerChars = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"]
constructor(verbose: boolean) {
this.verbose = verbose
}
start(text: string) {
this.spinnerText = text
if (this.verbose) {
console.log(text)
} else {
this.spinner = new Spinner(`%s ${text}`)
this.spinner.setSpinnerString(18)
this.spinner.start()
this.spinnerIndex = 0
this.spinnerInterval = setInterval(() => {
process.stdout.clearLine(0)
process.stdout.cursorTo(0)
process.stdout.write(`${this.spinnerChars[this.spinnerIndex]} ${this.spinnerText}`)
this.spinnerIndex = (this.spinnerIndex + 1) % this.spinnerChars.length
}, 100)
}
}
updateText(text: string) {
this.spinnerText = text
}
end(text?: string) {
if (!this.verbose) {
this.spinner!.stop(true)
if (!this.verbose && this.spinnerInterval) {
clearInterval(this.spinnerInterval)
this.spinnerInterval = undefined
process.stdout.clearLine(0)
process.stdout.cursorTo(0)
}
if (text) {
console.log(text)
}