Skip to content
Merged
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
28 changes: 27 additions & 1 deletion src/lib/spinner.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,40 @@
import { createSpinner, type Spinner } from 'nanospinner'

const argv = process.argv.slice(2)

const DOTS_SPINNER = {
interval: 80,
frames: ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏'],
}

const shouldSuppressOutput = () => argv.includes('--json') || argv.includes('--silent')

const noopSpinner: Spinner = {
start: () => noopSpinner,
stop: () => noopSpinner,
success: () => noopSpinner,
error: () => noopSpinner,
warn: () => noopSpinner,
info: () => noopSpinner,
update: () => noopSpinner,
reset: () => noopSpinner,
clear: () => noopSpinner,
spin: () => noopSpinner,
write: () => noopSpinner,
render: () => noopSpinner,
loop: () => noopSpinner,
isSpinning: () => false,
}

/**
* Creates a spinner with the following text
*/
export const startSpinner = ({ text }: { text: string }) => createSpinner(text, DOTS_SPINNER).start()
export const startSpinner = ({ text }: { text: string }): Spinner => {
if (shouldSuppressOutput()) {
return noopSpinner
}
return createSpinner(text, DOTS_SPINNER).start()
}

/**
* Stops the spinner with the following text
Expand Down
Loading