import prompts from 'prompts' ; type InteractionOptions = { pause : boolean ; canEscape ? : boolean ; } ; type InteractionCallback = ( options : InteractionOptions ) => void ; const listeners = [ ] ; param callback export function addInteractionListener ( callback ) { listeners . push ( callback ) ; } export function removeInteractionListener ( callback ) { const listenerIndex = listeners . findIndex ( _callback => _callback === callback ) ; if ( listenerIndex === - 1 ) { throw new Error ( 'Logger.removeInteractionListener(): cannot remove an unregistered event listener.' ) ; } listeners . splice ( listenerIndex , 1 ) ; } export function pauseInteractions ( options = { } ) { for ( const listener of listeners ) { listener ( { pause : true , ... options } ) ; } } export function resumeInteractions ( options = { } ) { for ( const listener of listeners ) { listener ( { pause : false , ... options } ) ; } } export async function confirmAsync ( options ) { pauseInteractions ( ) ; const { value } = await prompts ( { type : 'confirm' , name : 'value' , ... options } ) ; resumeInteractions ( ) ; return value ; }