Skip to content

Instantly share code, notes, and snippets.

@svsh227
Created April 16, 2020 08:12
Show Gist options
  • Save svsh227/fe15b336543f4f01444fcd74360add57 to your computer and use it in GitHub Desktop.
Save svsh227/fe15b336543f4f01444fcd74360add57 to your computer and use it in GitHub Desktop.
Create init script to start the CLI application:
cli.init = function () {
/* Send the start message to the console in dark blue. */
console.log(‘\x1b[33m % s\x1b[0m’, ‘CLI is running’);
/* Start the interface */
var _interface = readline.createInterface({
input: process.stdin,
output: process.stdout,
prompt: ‘>’
})
/* Create an initial prompt */
_interface.prompt(); // Will wait for input /* Handle each line of input separately. */
_interface.on(‘line’, function (str) { /* Send to input processor. */
cli.processInput(str); /* re-initialize the prompt afterwards. */
_interface.prompt();
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment