Skip to content

Commit 5aae76b

Browse files
committed
feat(spinner): add clean param to stop function
1 parent 69508f4 commit 5aae76b

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

packages/prompts/src/spinner.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export interface SpinnerOptions extends CommonOptions {
2424

2525
export interface SpinnerResult {
2626
start(msg?: string): void;
27-
stop(msg?: string, code?: number): void;
27+
stop(msg?: string, code?: number, clear?: boolean): void;
2828
message(msg?: string): void;
2929
readonly isCancelled: boolean;
3030
}
@@ -163,7 +163,7 @@ export const spinner = ({
163163
}, delay);
164164
};
165165

166-
const stop = (msg = '', code = 0): void => {
166+
const stop = (msg = '', code = 0, clear = false): void => {
167167
if (!isSpinnerActive) return;
168168
isSpinnerActive = false;
169169
clearInterval(loop);
@@ -174,11 +174,13 @@ export const spinner = ({
174174
: code === 1
175175
? color.red(S_STEP_CANCEL)
176176
: color.red(S_STEP_ERROR);
177-
_message = msg ?? _message;
178-
if (indicator === 'timer') {
179-
output.write(`${step} ${_message} ${formatTimer(_origin)}\n`);
180-
} else {
181-
output.write(`${step} ${_message}\n`);
177+
if (!clear) {
178+
_message = msg ?? _message;
179+
if (indicator === 'timer') {
180+
output.write(`${step} ${_message} ${formatTimer(_origin)}\n`);
181+
} else {
182+
output.write(`${step} ${_message}\n`);
183+
}
182184
}
183185
clearHooks();
184186
unblock();

0 commit comments

Comments
 (0)