From d9159e0ac9bfc22e584c78bc8aa04ecd82c14eea Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 13 Mar 2025 17:27:46 +0000
Subject: [PATCH] feat: make og images an emitter to properly await image generation (#1826)

---
 quartz/util/log.ts |   31 ++++++++++++++++++++++++-------
 1 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/quartz/util/log.ts b/quartz/util/log.ts
index 773945c..95015ac 100644
--- a/quartz/util/log.ts
+++ b/quartz/util/log.ts
@@ -1,26 +1,43 @@
-import { Spinner } from "cli-spinner"
+import readline from "readline"
 
 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(() => {
+        readline.clearLine(process.stdout, 0)
+        readline.cursorTo(process.stdout, 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
+      readline.clearLine(process.stdout, 0)
+      readline.cursorTo(process.stdout, 0)
     }
+
     if (text) {
       console.log(text)
     }

--
Gitblit v1.10.0