| 224 | |
| 225 | // Updates the spinner after the given interval. |
| 226 | const updateFrame = () => { |
| 227 | const color = this.#color ?? ""; |
| 228 | const frame = encoder.encode( |
| 229 | noColor |
| 230 | ? this.#spinner[i] + " " + this.message |
| 231 | : color + this.#spinner[i] + COLOR_RESET + " " + this.message, |
| 232 | ); |
| 233 | // call writeSync once to reduce flickering |
| 234 | const writeData = new Uint8Array(LINE_CLEAR.length + frame.length); |
| 235 | writeData.set(LINE_CLEAR); |
| 236 | writeData.set(frame, LINE_CLEAR.length); |
| 237 | this.#output.writeSync(writeData); |
| 238 | i = (i + 1) % this.#spinner.length; |
| 239 | }; |
| 240 | |
| 241 | this.#intervalId = setInterval(updateFrame, this.#interval); |
| 242 | updateFrame(); |