Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wicked-sides-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@clack/prompts": patch
---

Add `withGuide` support to spinner prompt
6 changes: 5 additions & 1 deletion packages/prompts/src/spinner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
52 changes: 52 additions & 0 deletions packages/prompts/test/__snapshots__/spinner.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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`] = `
[
"<cursor.hide>",
"◒ foo",
"<cursor.left count=1>",
"<erase.down>",
"◇
",
"<cursor.show>",
]
`;

exports[`spinner (isCI = false) > indicator customization > custom delay 1`] = `
[
"<cursor.hide>",
Expand Down Expand Up @@ -571,6 +583,18 @@ exports[`spinner (isCI = false) > stop > renders submit symbol and stops spinner
]
`;

exports[`spinner (isCI = false) > withGuide: false removes guide 1`] = `
[
"<cursor.hide>",
"◒ foo",
"<cursor.left count=1>",
"<erase.down>",
"◇
",
"<cursor.show>",
]
`;

exports[`spinner (isCI = true) > can be aborted by a signal 1`] = `
[
"<cursor.hide>",
Expand All @@ -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`] = `
[
"<cursor.hide>",
"◒ foo...",
"
",
"<cursor.left count=1>",
"<erase.down>",
"◇
",
"<cursor.show>",
]
`;

exports[`spinner (isCI = true) > indicator customization > custom delay 1`] = `
[
"<cursor.hide>",
Expand Down Expand Up @@ -954,3 +992,17 @@ exports[`spinner (isCI = true) > stop > renders submit symbol and stops spinner
"<cursor.show>",
]
`;

exports[`spinner (isCI = true) > withGuide: false removes guide 1`] = `
[
"<cursor.hide>",
"◒ foo...",
"
",
"<cursor.left count=1>",
"<erase.down>",
"◇
",
"<cursor.show>",
]
`;
29 changes: 28 additions & 1 deletion packages/prompts/test/spinner.test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -26,6 +26,7 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => {
afterEach(() => {
vi.useRealTimers();
vi.restoreAllMocks();
updateSettings({ withGuide: true });
});

test('returns spinner API', () => {
Expand Down Expand Up @@ -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 });
Expand Down
Loading