I just attached super-simple CLI functionality to my app and I'm curious how I'd take it further by turning into a formatted shell.What I'm thinking is, I'd like to define preformatted spaces in the terminal where node was launched. One line at the bottom would be the command entry field. The rest would be debug output and the like. Rather than have the terminal scroll up with each new question/anwer action, I'd like to update more-or-less the way I would in DOM.What are some keywords to read about for this?Thanks in advance. Here's how I'm handling CLI so far:var Readline = require('readline'); var shell = Readline.createInterface({ input: process.stdin, output: process.stdout }); xpApp.listen(port, () => { console.log(`xpApp listening on port ${port}`); shellLoop(); }); function shellLoop() { shell.question("app > ", (answer) => { switch(answer) { case "reload db": console.log("Resetting test data"); break; case "reload tpl": console.log("Reloading templates"); break; case "reset": console.log("Doing full soft init"); break; case "help": console.log( "reload db: clear database and reload test data\n" + "reload tpl: reload templates\n" + "reset: full reload\n" ); break; } shellLoop(); }) } EDIT: pokes around while waiting ... Is it just TTY and Readline? Anything else?
Submitted November 04, 2018 at 04:42AM by poor-toy-soul-doll
No comments:
Post a Comment