From c480a70022c7b892c07c8e45d0a7cc45b9bd93f3 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 26 Aug 2024 00:51:40 +0700 Subject: [PATCH 1/4] Fix CI --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a023591..6e98150 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -10,9 +10,9 @@ jobs: fail-fast: false matrix: node-version: + - 22 - 20 - 18 - - 16 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4 From 5117dfb69b13d0026a88a8ba5eedc13b4d8df4ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B1=95=E5=B0=8F=E5=93=A5?= Date: Sat, 2 Nov 2024 00:16:16 +0800 Subject: [PATCH 2/4] Fix handling of symbol being empty string in `stopAndPersist()` (#243) --- index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index a91a0cf..3d5b8b8 100644 --- a/index.js +++ b/index.js @@ -358,7 +358,8 @@ class Ora { const symbolText = options.symbol ?? ' '; const text = options.text ?? this.text; - const fullText = (typeof text === 'string') ? ' ' + text : ''; + const separatorText = symbolText ? ' ' : ''; + const fullText = (typeof text === 'string') ? separatorText + text : ''; const suffixText = options.suffixText ?? this.#suffixText; const fullSuffixText = this.#getFullSuffixText(suffixText, ' '); From 818ca34f1fd03d7652965d60cfb3205c29241757 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Sat, 12 Oct 2024 15:51:16 +0700 Subject: [PATCH 3/4] Fix frame handling --- index.js | 14 +++++++++++--- test.js | 4 +++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 3d5b8b8..940f120 100644 --- a/index.js +++ b/index.js @@ -13,7 +13,8 @@ class Ora { #linesToClear = 0; #isDiscardingStdin = false; #lineCount = 0; - #frameIndex = 0; + #frameIndex = -1; + #lastSpinnerFrameTime = 0; #options; #spinner; #stream; @@ -109,7 +110,7 @@ class Ora { } set spinner(spinner) { - this.#frameIndex = 0; + this.#frameIndex = -1; this.#initialInterval = undefined; if (typeof spinner === 'object') { @@ -222,6 +223,14 @@ class Ora { } frame() { + // Ensure we only update the spinner frame at the wanted interval, + // even if the render method is called more often. + const now = Date.now(); + if (this.#frameIndex === -1 || now - this.#lastSpinnerFrameTime >= this.interval) { + this.#frameIndex = ++this.#frameIndex % this.#spinner.frames.length; + this.#lastSpinnerFrameTime = now; + } + const {frames} = this.#spinner; let frame = frames[this.#frameIndex]; @@ -229,7 +238,6 @@ class Ora { frame = chalk[this.color](frame); } - this.#frameIndex = ++this.#frameIndex % frames.length; const fullPrefixText = (typeof this.#prefixText === 'string' && this.#prefixText !== '') ? this.#prefixText + ' ' : ''; const fullText = typeof this.text === 'string' ? ' ' + this.text : ''; const fullSuffixText = (typeof this.#suffixText === 'string' && this.#suffixText !== '') ? ' ' + this.#suffixText : ''; diff --git a/test.js b/test.js index d768f1d..1efc73a 100644 --- a/test.js +++ b/test.js @@ -267,8 +267,10 @@ test('reset frameIndex when setting new spinner', async t => { }, }); + t.is(spinner._frameIndex, -1); + spinner.render(); - t.is(spinner._frameIndex, 1); + t.is(spinner._frameIndex, 0); spinner.spinner = {frames: ['baz']}; spinner.render(); From 86aca37a324dcb010da5c04660e5c81a4d8f1f9d Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Fri, 1 Nov 2024 23:18:48 +0700 Subject: [PATCH 4/4] 8.1.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 89746f7..2bd67a4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ora", - "version": "8.1.0", + "version": "8.1.1", "description": "Elegant terminal spinner", "license": "MIT", "repository": "sindresorhus/ora",