import ora from 'ora' ; import { colors } from './colors' ; import { isTTY } from './is-tty' ; export class Spinner { private readonly spinner : ora . Ora ; public enabled = true ; protected startTime : Date ; constructor ( text ? ) { this . spinner = ora ( { text : text , hideCursor : false , discardStdin : false , isEnabled : isTTY ( ) } ) ; } get text ( ) { return this . spinner . text ; } set text ( text ) { this . spinner . text = text ; } get isSpinning ( ) : boolean { return this . spinner . isSpinning ; } succeed ( text ? ) { if ( this . enabled ) { this . spinner . succeed ( text ) ; } } info ( text ? ) { if ( this . enabled ) { this . spinner . info ( text ) ; } } warn ( text ? ) { if ( this . enabled ) { this . spinner . warn ( text ) ; } } fail ( text ? ) { this . spinner . fail ( text && colors . redBright ( text ) ) ; } stop ( ) { this . spinner . stop ( ) ; } start ( text ? ) { if ( this . enabled ) { this . startTime = new Date ( ) ; this . spinner . start ( text ) ; } } }