import * as Readline from 'readline' ; export interface RestartListenerInit { readline : Readline . ReadLine ; } const readline = Readline . createInterface ( { input : process . stdin , terminal : false } ) ; export class RestartListener { private readline : Readline . ReadLine ; private listener : ( ) => void = ( ) => { } ; private constructor ( init ) { this . readline = init . readline ; } public static async fromProcess ( process ) { return new RestartListener ( { readline } ) ; } private onRs = ( line ) : void => { if ( ! line . endsWith ( 'rs' ) ) { return ; } Readline . moveCursor ( process . stdin , 0 , - 1 ) ; Readline . clearLine ( process . stdin , 0 ) ; this . listener ( ) ; } ; public subscribe ( listener ) { this . listener = listener ; this . readline . on ( 'line' , this . onRs ) ; } public unsubscribe ( ) { this . readline . removeAllListeners ( ) ; } }