Skip to content

Commit 0256238

Browse files
authored
feat: add withGuide support to spinner prompt (#454)
1 parent bc31ee8 commit 0256238

File tree

4 files changed

+90
-2
lines changed

4 files changed

+90
-2
lines changed

.changeset/wicked-sides-share.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@clack/prompts": patch
3+
---
4+
5+
Add `withGuide` support to spinner prompt

packages/prompts/src/spinner.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,16 @@ export const spinner = ({
127127
return min > 0 ? `[${min}m ${secs}s]` : `[${secs}s]`;
128128
};
129129

130+
const hasGuide = (opts.withGuide ?? settings.withGuide) !== false;
131+
130132
const start = (msg = ''): void => {
131133
isSpinnerActive = true;
132134
unblock = block({ output });
133135
_message = removeTrailingDots(msg);
134136
_origin = performance.now();
135-
output.write(`${color.gray(S_BAR)}\n`);
137+
if (hasGuide) {
138+
output.write(`${color.gray(S_BAR)}\n`);
139+
}
136140
let frameIndex = 0;
137141
let indicatorTimer = 0;
138142
registerHooks();

packages/prompts/test/__snapshots__/spinner.test.ts.snap

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ exports[`spinner (isCI = false) > clear > stops and clears the spinner from the
2323
]
2424
`;
2525
26+
exports[`spinner (isCI = false) > global withGuide: false removes guide 1`] = `
27+
[
28+
"<cursor.hide>",
29+
"◒ foo",
30+
"<cursor.left count=1>",
31+
"<erase.down>",
32+
"◇
33+
",
34+
"<cursor.show>",
35+
]
36+
`;
37+
2638
exports[`spinner (isCI = false) > indicator customization > custom delay 1`] = `
2739
[
2840
"<cursor.hide>",
@@ -571,6 +583,18 @@ exports[`spinner (isCI = false) > stop > renders submit symbol and stops spinner
571583
]
572584
`;
573585
586+
exports[`spinner (isCI = false) > withGuide: false removes guide 1`] = `
587+
[
588+
"<cursor.hide>",
589+
"◒ foo",
590+
"<cursor.left count=1>",
591+
"<erase.down>",
592+
"◇
593+
",
594+
"<cursor.show>",
595+
]
596+
`;
597+
574598
exports[`spinner (isCI = true) > can be aborted by a signal 1`] = `
575599
[
576600
"<cursor.hide>",
@@ -596,6 +620,20 @@ exports[`spinner (isCI = true) > clear > stops and clears the spinner from the o
596620
]
597621
`;
598622
623+
exports[`spinner (isCI = true) > global withGuide: false removes guide 1`] = `
624+
[
625+
"<cursor.hide>",
626+
"◒ foo...",
627+
"
628+
",
629+
"<cursor.left count=1>",
630+
"<erase.down>",
631+
"◇
632+
",
633+
"<cursor.show>",
634+
]
635+
`;
636+
599637
exports[`spinner (isCI = true) > indicator customization > custom delay 1`] = `
600638
[
601639
"<cursor.hide>",
@@ -954,3 +992,17 @@ exports[`spinner (isCI = true) > stop > renders submit symbol and stops spinner
954992
"<cursor.show>",
955993
]
956994
`;
995+
996+
exports[`spinner (isCI = true) > withGuide: false removes guide 1`] = `
997+
[
998+
"<cursor.hide>",
999+
"◒ foo...",
1000+
"
1001+
",
1002+
"<cursor.left count=1>",
1003+
"<erase.down>",
1004+
"◇
1005+
",
1006+
"<cursor.show>",
1007+
]
1008+
`;

packages/prompts/test/spinner.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { EventEmitter } from 'node:stream';
2-
import { getColumns } from '@clack/core';
2+
import { getColumns, updateSettings } from '@clack/core';
33
import color from 'picocolors';
44
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, test, vi } from 'vitest';
55
import * as prompts from '../src/index.js';
@@ -26,6 +26,7 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => {
2626
afterEach(() => {
2727
vi.useRealTimers();
2828
vi.restoreAllMocks();
29+
updateSettings({ withGuide: true });
2930
});
3031

3132
test('returns spinner API', () => {
@@ -426,6 +427,32 @@ describe.each(['true', 'false'])('spinner (isCI = %s)', (isCI) => {
426427
expect(output.buffer).toMatchSnapshot();
427428
});
428429

430+
test('withGuide: false removes guide', () => {
431+
const result = prompts.spinner({ output, withGuide: false });
432+
433+
result.start('foo');
434+
435+
vi.advanceTimersByTime(80);
436+
437+
result.stop();
438+
439+
expect(output.buffer).toMatchSnapshot();
440+
});
441+
442+
test('global withGuide: false removes guide', () => {
443+
updateSettings({ withGuide: false });
444+
445+
const result = prompts.spinner({ output });
446+
447+
result.start('foo');
448+
449+
vi.advanceTimersByTime(80);
450+
451+
result.stop();
452+
453+
expect(output.buffer).toMatchSnapshot();
454+
});
455+
429456
describe('clear', () => {
430457
test('stops and clears the spinner from the output', () => {
431458
const result = prompts.spinner({ output });

0 commit comments

Comments
 (0)