Created
February 4, 2014 03:32
-
-
Save cmonyuk/8797751 to your computer and use it in GitHub Desktop.
synchronous(???) console.log code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var Stream = require("stream").Stream; | |
| var path = require("path"); | |
| var nopt = require("nopt"); | |
| var readJson = require("read-package-json"); | |
| var prompt = require("prompt"); | |
| //var ansi = require("ansi"); | |
| //var cursor = ansi(process.stdout); | |
| var charm = require("charm")(); | |
| charm.pipe(process.stdout); | |
| // interactive interface | |
| function Iface() { | |
| // list of known commands | |
| this.commandList = { | |
| "version" : { | |
| "commandName" : version, | |
| "commandOpts" : null, | |
| "commandShort": null | |
| }, | |
| "quit" : { | |
| "commandName" : quit, | |
| "commandOpts" : null, | |
| "commandShort": null | |
| } | |
| }; | |
| // prompt for command | |
| prompt.message = ""; | |
| prompt.delimiter = ""; | |
| prompt.start(); | |
| readCommand(); | |
| } | |
| // Print version | |
| function version(cb) { | |
| readJson('package.json', console.error, false, function(er, data) { | |
| if (er) { | |
| console.log("package.json not found"); | |
| } else { | |
| // process.stdout.write(data.name + " version " + data.version); | |
| // charm.write(data.name + " version " + data.version); | |
| // charm.write("v"); | |
| console.log(/*data.name + " */"version " + data.version); | |
| } | |
| }); | |
| cb(); | |
| } | |
| function quit() { | |
| process.exit(); | |
| } | |
| function help(cb) { | |
| console.log("helping you help yourself"); | |
| cb(); | |
| } | |
| function readCommand() { | |
| console.log("t"); | |
| prompt.get([{properties : {command : {description : ">".green}}}], | |
| function(err, result) { | |
| if (err) { | |
| console.log("input error!"); | |
| return; | |
| } else { | |
| if (this.commandList[result.command]) { | |
| this.commandList[result.command].commandName(readCommand); | |
| } else { | |
| if (result.command) { | |
| console.log("unknown command " + result.command); | |
| help(readCommand); | |
| } else { | |
| readCommand(); | |
| } | |
| } | |
| } | |
| }); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| t | |
| > version | |
| t | |
| > version 0.0.1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment