import chalk = require ( "chalk" ) ; const ProgressBar = require ( "progress" ) ; class ProgressBarController { private bar : any ; constructor ( ) { this . bar = null ; } public init ( title , total ) { if ( this . bar ) { this . terminate ( ) ; } if ( ! process . stdout . isTTY ) { return ; } this . bar = new ProgressBar ( `:bar ${ title } (:percent)` , { total , complete : chalk . hex ( "#0366d6" ) ( "█" ) , incomplete : chalk . level > 0 ? chalk . gray ( "█" ) : "░" , clear : true , width : 20 , } ) ; } public tick ( ) { if ( this . bar ) { this . bar . tick ( 1 ) ; } } public clear ( ) { if ( this . bar ) { this . bar . terminate ( ) ; } } public terminate ( ) { this . clear ( ) ; this . bar = null ; } } export default new ProgressBarController ( ) ;