Skip to content

Commit 72c2f2d

Browse files
authored
fix(prompts): don't strip dots in spinner stop (#287)
1 parent dccb07c commit 72c2f2d

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

packages/prompts/src/__snapshots__/index.test.ts.snap

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,20 @@ exports[`prompts (isCI = false) > spinner > stop > renders message 1`] = `
17671767
]
17681768
`;
17691769

1770+
exports[`prompts (isCI = false) > spinner > stop > renders message without removing dots 1`] = `
1771+
[
1772+
"[?25l",
1773+
"│
1774+
",
1775+
"◒ ",
1776+
"",
1777+
"",
1778+
"◇ foo.
1779+
",
1780+
"[?25h",
1781+
]
1782+
`;
1783+
17701784
exports[`prompts (isCI = false) > spinner > stop > renders submit symbol and stops spinner 1`] = `
17711785
[
17721786
"[?25l",
@@ -3758,6 +3772,22 @@ exports[`prompts (isCI = true) > spinner > stop > renders message 1`] = `
37583772
]
37593773
`;
37603774

3775+
exports[`prompts (isCI = true) > spinner > stop > renders message without removing dots 1`] = `
3776+
[
3777+
"[?25l",
3778+
"│
3779+
",
3780+
"◒ ...",
3781+
"
3782+
",
3783+
"",
3784+
"",
3785+
"◇ foo.
3786+
",
3787+
"[?25h",
3788+
]
3789+
`;
3790+
37613791
exports[`prompts (isCI = true) > spinner > stop > renders submit symbol and stops spinner 1`] = `
37623792
[
37633793
"[?25l",

packages/prompts/src/index.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,18 @@ describe.each(['true', 'false'])('prompts (isCI = %s)', (isCI) => {
167167

168168
expect(output.buffer).toMatchSnapshot();
169169
});
170+
171+
test('renders message without removing dots', () => {
172+
const result = prompts.spinner({ output });
173+
174+
result.start();
175+
176+
vi.advanceTimersByTime(80);
177+
178+
result.stop('foo.');
179+
180+
expect(output.buffer).toMatchSnapshot();
181+
});
170182
});
171183

172184
describe('message', () => {

packages/prompts/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -853,7 +853,7 @@ export const spinner = ({
853853
output.write(erase.down(prevLines.length));
854854
};
855855

856-
const parseMessage = (msg: string): string => {
856+
const removeTrailingDots = (msg: string): string => {
857857
return msg.replace(/\.+$/, '');
858858
};
859859

@@ -867,7 +867,7 @@ export const spinner = ({
867867
const start = (msg = ''): void => {
868868
isSpinnerActive = true;
869869
unblock = block({ output });
870-
_message = parseMessage(msg);
870+
_message = removeTrailingDots(msg);
871871
_origin = performance.now();
872872
output.write(`${color.gray(S_BAR)}\n`);
873873
let frameIndex = 0;
@@ -905,7 +905,7 @@ export const spinner = ({
905905
: code === 1
906906
? color.red(S_STEP_CANCEL)
907907
: color.red(S_STEP_ERROR);
908-
_message = parseMessage(msg ?? _message);
908+
_message = msg ?? _message;
909909
if (indicator === 'timer') {
910910
output.write(`${step} ${_message} ${formatTimer(_origin)}\n`);
911911
} else {
@@ -916,7 +916,7 @@ export const spinner = ({
916916
};
917917

918918
const message = (msg = ''): void => {
919-
_message = parseMessage(msg ?? _message);
919+
_message = removeTrailingDots(msg ?? _message);
920920
};
921921

922922
return {

0 commit comments

Comments
 (0)