import chalk from 'chalk' ; import stripAnsi from 'strip-ansi' ; import wrapAnsi from 'wrap-ansi' ; import { terminalWidth } from 'yargs' ; interface CLIOption { singleLine ? : boolean ; } const width = terminalWidth ( ) || 80 ; const messageBlock = ( kind , message , opts ) : string => { const indent = stripAnsi ( kind ) . length + 1 ; const target = opts . singleLine ? message : wrapAnsi ( message , width - indent ) ; return `${ kind } ${ target . split ( '\n' ) . join ( `\n${ ' ' . repeat ( indent ) }` ) }` ; } ; let silent = false ; export function silence ( value ) { silent = value ; } export function info ( message , opts = { } ) { if ( ! silent ) console . warn ( messageBlock ( chalk . bgCyan . black ( '[  INFO ]' ) , message , opts ) ) ; } export function warn ( message , opts = { } ) { if ( ! silent ) console . warn ( messageBlock ( chalk . bgYellow . black ( '[  WARN ]' ) , message , opts ) ) ; } export function error ( message , opts = { } ) { console . error ( messageBlock ( chalk . bgRed . white ( '[ ERROR ]' ) , message , opts ) ) ; }