lib/init.js
function menu( items, nextStep ) {
    const rl = RL.createInterface( {
        input: process.stdin,
        output: process.stdout
    } );
    console.log();
    items.forEach( function ( item, idx ) {
        var out = idx < 10 ? ' ' : '';
        out += ( "" + ( 1 + idx ) + ") " ).yellow;
        out += item;
        console.log( out );
    } );
    console.log();
    rl.question( "Your choice: ", ( ans ) => {
        rl.close();
        var choice = parseInt( ans );
        if ( isNaN( ans ) || ans < 1 || ans > items.length ) {
            menu( items, nextStep );
        } else {
            console.log();
            nextStep( choice );
        }
    } );
}
function menu( items, nextStep ) {
    const rl = RL.createInterface( {
        input: process.stdin,
        output: process.stdout
    } );
    console.log();
    items.forEach( function ( item, idx ) {
        var out = idx < 10 ? ' ' : '';
        out += ( "" + ( 1 + idx ) + ") " ).yellow;
        out += item;
        console.log( out );
    } );
    console.log();
    rl.question( "Your choice: ", ( ans ) => {
        rl.close();
        var choice = parseInt( ans );
        if ( isNaN( ans ) || ans < 1 || ans > items.length ) {
            menu( items, nextStep );
        } else {
            console.log();
            nextStep( choice );
        }
    } );
}
function menu ( items , nextStep ) { const rl = RL . createInterface ( { input : process . stdin , output : process . stdout } ) ; console . log ( ) ; items . forEach ( function ( item , idx ) { var out = idx < 10 ? ' ' : '' ; out += ( "" + ( 1 + idx ) + ") " ) . yellow ; out += item ; console . log ( out ) ; } ) ; console . log ( ) ; rl . question ( "Your choice: " , ( ans ) => { rl . close ( ) ; var choice = parseInt ( ans ) ; if ( isNaN ( ans ) || ans < 1 || ans > items . length ) { menu ( items , nextStep ) ; } else { console . log ( ) ; nextStep ( choice ) ; } } ) ; }
Display a list of items and ask the user to select one.
Each item is  numbered and the menu is displayed  again if the user
enter a non-existing value.
The function `nextStep` is called with the choice as a number.
Display a list of items and ask the user to select one . Each item is numbered and the menu is displayed again if the user enter a non - existing value . The function nextStep is called with the choice as a number .