Skip to content
Merged
Changes from 2 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
15 changes: 9 additions & 6 deletions packages/prompts/src/spinner.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { block, getColumns, settings } from '@clack/core';
import { wrapAnsi } from 'fast-wrap-ansi';
import color from 'picocolors';
import colors from 'picocolors';
import type { Colors } from 'picocolors/types.d.ts';
import { cursor, erase } from 'sisteransi';
import {
type CommonOptions,
Expand All @@ -19,6 +20,7 @@ export interface SpinnerOptions extends CommonOptions {
errorMessage?: string;
frames?: string[];
delay?: number;
color?: keyof Omit<Colors, 'isColorSupported'>;
}

export interface SpinnerResult {
Expand All @@ -37,6 +39,7 @@ export const spinner = ({
frames = unicode ? ['◒', '◐', '◓', '◑'] : ['•', 'o', 'O', '0'],
delay = unicode ? 80 : 120,
signal,
color = 'magenta',
}: SpinnerOptions = {}): SpinnerResult => {
const isCI = isCIFn();

Expand Down Expand Up @@ -124,7 +127,7 @@ export const spinner = ({
unblock = block({ output });
_message = removeTrailingDots(msg);
_origin = performance.now();
output.write(`${color.gray(S_BAR)}\n`);
output.write(`${colors.gray(S_BAR)}\n`);
let frameIndex = 0;
let indicatorTimer = 0;
registerHooks();
Expand All @@ -134,7 +137,7 @@ export const spinner = ({
}
clearPrevMessage();
_prevMessage = _message;
const frame = color.magenta(frames[frameIndex]);
const frame = colors[color](frames[frameIndex]);
let outputMessage: string;

if (isCI) {
Expand Down Expand Up @@ -165,10 +168,10 @@ export const spinner = ({
clearPrevMessage();
const step =
code === 0
? color.green(S_STEP_SUBMIT)
? colors.green(S_STEP_SUBMIT)
: code === 1
? color.red(S_STEP_CANCEL)
: color.red(S_STEP_ERROR);
? colors.red(S_STEP_CANCEL)
: colors.red(S_STEP_ERROR);
_message = msg ?? _message;
if (indicator === 'timer') {
output.write(`${step} ${_message} ${formatTimer(_origin)}\n`);
Expand Down
Loading