diff --git a/.changeset/wicked-sides-share.md b/.changeset/wicked-sides-share.md new file mode 100644 index 00000000..54cd102e --- /dev/null +++ b/.changeset/wicked-sides-share.md @@ -0,0 +1,5 @@ +--- +"@clack/prompts": patch +--- + +Add `withGuide` support to spinner prompt diff --git a/packages/prompts/src/spinner.ts b/packages/prompts/src/spinner.ts index 8b3f6d01..5e002074 100644 --- a/packages/prompts/src/spinner.ts +++ b/packages/prompts/src/spinner.ts @@ -127,12 +127,16 @@ export const spinner = ({ return min > 0 ? `[${min}m ${secs}s]` : `[${secs}s]`; }; + const hasGuide = (opts.withGuide ?? settings.withGuide) !== false; + const start = (msg = ''): void => { isSpinnerActive = true; unblock = block({ output }); _message = removeTrailingDots(msg); _origin = performance.now(); - output.write(`${color.gray(S_BAR)}\n`); + if (hasGuide) { + output.write(`${color.gray(S_BAR)}\n`); + } let frameIndex = 0; let indicatorTimer = 0; registerHooks(); diff --git a/packages/prompts/test/__snapshots__/spinner.test.ts.snap b/packages/prompts/test/__snapshots__/spinner.test.ts.snap index 5132fe61..31412ea1 100644 --- a/packages/prompts/test/__snapshots__/spinner.test.ts.snap +++ b/packages/prompts/test/__snapshots__/spinner.test.ts.snap @@ -23,6 +23,18 @@ exports[`spinner (isCI = false) > clear > stops and clears the spinner from the ] `; +exports[`spinner (isCI = false) > global withGuide: false removes guide 1`] = ` +[ + "", + "◒ foo", + "", + "", + "◇ +", + "", +] +`; + exports[`spinner (isCI = false) > indicator customization > custom delay 1`] = ` [ "", @@ -571,6 +583,18 @@ exports[`spinner (isCI = false) > stop > renders submit symbol and stops spinner ] `; +exports[`spinner (isCI = false) > withGuide: false removes guide 1`] = ` +[ + "", + "◒ foo", + "", + "", + "◇ +", + "", +] +`; + exports[`spinner (isCI = true) > can be aborted by a signal 1`] = ` [ "", @@ -596,6 +620,20 @@ exports[`spinner (isCI = true) > clear > stops and clears the spinner from the o ] `; +exports[`spinner (isCI = true) > global withGuide: false removes guide 1`] = ` +[ + "", + "◒ foo...", + " +", + "", + "", + "◇ +", + "", +] +`; + exports[`spinner (isCI = true) > indicator customization > custom delay 1`] = ` [ "", @@ -954,3 +992,17 @@ exports[`spinner (isCI = true) > stop > renders submit symbol and stops spinner "", ] `; + +exports[`spinner (isCI = true) > withGuide: false removes guide 1`] = ` +[ + "", + "◒ foo...", + " +", + "", + "", + "◇ +", + "", +] +`; diff --git a/packages/prompts/test/spinner.test.ts b/packages/prompts/test/spinner.test.ts index f6ff68b1..f8ad3ea3 100644 --- a/packages/prompts/test/spinner.test.ts +++ b/packages/prompts/test/spinner.test.ts @@ -1,5 +1,5 @@ import { EventEmitter } from 'node:stream'; -import { getColumns } from '@clack/core'; +import { getColumns, updateSettings } from '@clack/core'; import color from 'picocolors'; import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest'; import * as prompts from '../src/index.js'; @@ -26,6 +26,7 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => { afterEach(() => { vi.useRealTimers(); vi.restoreAllMocks(); + updateSettings({ withGuide: true }); }); test('returns spinner API', () => { @@ -426,6 +427,32 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => { expect(output.buffer).toMatchSnapshot(); }); + test('withGuide: false removes guide', () => { + const result = prompts.spinner({ output, withGuide: false }); + + result.start('foo'); + + vi.advanceTimersByTime(80); + + result.stop(); + + expect(output.buffer).toMatchSnapshot(); + }); + + test('global withGuide: false removes guide', () => { + updateSettings({ withGuide: false }); + + const result = prompts.spinner({ output }); + + result.start('foo'); + + vi.advanceTimersByTime(80); + + result.stop(); + + expect(output.buffer).toMatchSnapshot(); + }); + describe('clear', () => { test('stops and clears the spinner from the output', () => { const result = prompts.spinner({ output });