{"_id":"ttys","_rev":"161733","name":"ttys","description":"Guaranteed read and write streams to the terminal","dist-tags":{"latest":"0.0.3"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"time":{"modified":"2021-06-03T11:41:02.000Z","created":"2012-06-16T04:29:14.975Z","0.0.3":"2012-06-19T21:30:03.343Z","0.0.2":"2012-06-16T04:32:26.557Z","0.0.1":"2012-06-16T04:29:14.975Z"},"users":{},"author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/ttys.git"},"versions":{"0.0.3":{"name":"ttys","description":"Guaranteed read and write streams to the terminal","keywords":["tty","stdin","stdout","/dev/tty"],"version":"0.0.3","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/ttys.git"},"main":"./index.js","scripts":{"test":"node test"},"engines":{"node":">= 0.6.0"},"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"_id":"ttys@0.0.3","dependencies":{},"devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.25","_nodeVersion":"v0.7.11","_defaultsLoaded":true,"dist":{"shasum":"15bacde7831020de5f2f28f01b1732ef03651f4d","size":2176,"noattachment":false,"key":"/ttys/-/ttys-0.0.3.tgz","tarball":"http://registry.cnpm.dingdandao.com/ttys/download/ttys-0.0.3.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1340141403343,"_cnpm_publish_time":1340141403343,"_hasShrinkwrap":false},"0.0.2":{"name":"ttys","description":"Guaranteed read and write streams to the terminal","keywords":["tty","stdin","stdout","/dev/tty"],"version":"0.0.2","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/ttys.git"},"main":"./index.js","scripts":{"test":"node test"},"engines":{"node":">= 0.6.0"},"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"_id":"ttys@0.0.2","dependencies":{},"devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.25","_nodeVersion":"v0.7.11","_defaultsLoaded":true,"dist":{"shasum":"6e801a9f8ed5d373f13bd1406b8f4708be7d06df","size":2001,"noattachment":false,"key":"/ttys/-/ttys-0.0.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/ttys/download/ttys-0.0.2.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1339821146557,"_cnpm_publish_time":1339821146557,"_hasShrinkwrap":false},"0.0.1":{"name":"ttys","description":"Guaranteed read and write streams to the terminal","keywords":["tty","stdin","stdout","/dev/tty"],"version":"0.0.1","author":{"name":"Nathan Rajlich","email":"nathan@tootallnate.net","url":"http://tootallnate.net"},"repository":{"type":"git","url":"git://github.com/TooTallNate/ttys.git"},"main":"./index.js","scripts":{"test":"node test"},"engines":{"node":">= 0.6.0"},"_npmUser":{"name":"tootallnate","email":"nathan@tootallnate.net"},"_id":"ttys@0.0.1","dependencies":{},"devDependencies":{},"optionalDependencies":{},"_engineSupported":true,"_npmVersion":"1.1.25","_nodeVersion":"v0.7.11","_defaultsLoaded":true,"dist":{"shasum":"fdd81d22b24fd73b29b3022a6d23863c05d751de","size":2003,"noattachment":false,"key":"/ttys/-/ttys-0.0.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/ttys/download/ttys-0.0.1.tgz"},"maintainers":[{"name":"tootallnate","email":"nathan@tootallnate.net"}],"directories":{},"publish_time":1339820954975,"_cnpm_publish_time":1339820954975,"_hasShrinkwrap":false}},"readme":"ttys\n====\n### Guaranteed read and write streams to the terminal\n\n\nThis micro module provides `tty.ReadStream` and `tty.WriteStream` instances to the\nuser's terminal, even when the regular `stdin` or `stdout` streams are already\nbeing piped to other commands.\n\nInstallation\n------------\n\nInstall with `npm`:\n\n``` bash\n$ npm install ttys\n```\n\n\nThe setup\n---------\n\nSuppose you want to provide a `curl | node` command to your users.\n\nThe script could be something as simple as printing \"Hello World\" and exiting.\n\n``` js\n// script.js\nconsole.log('Hello World')\n```\n\nPlace that on your websever and have your users invoke the command:\n\n``` bash\n$ curl aweso.me/script.js | node\nHello World\n```\n\nAwesome!!!\n\nThe problem\n-----------\n\nNow suppose that you wanted to alter `script.js` to prompt the user for their\nname, so that you can personalize it a little bit.\n\nThe problem is that `process.stdin` is used up because it gets piped from the curl\ncommand, and ends before node runs the script. If you try to call\n`process.stdin.resume()` and listen for \"data\" and \"end\" events, you will see that\nthe \"end\" event will be fired immediately.\n\n\n\nThe solution\n------------\n\nUsing `ttys`, you can get guaranteed access to a `stdin` readable stream and\n`stdout` writable stream. It's easy!\n\n``` js\nvar ttys = require('ttys')\nvar readline = require('readline')\n\nvar i = readline.createInterface(ttys.stdin, ttys.stdout)\ni.question('What is your name? ', function (name) {\n  console.log('Hello %s', name)\n\n  i.close()\n  ttys.stdin.pause()\n})\n```\n\nNow when your users run the script, then they will be prompted as you would\nexpect:\n\n``` bash\n$ curl aweso.me/script.js | node\nWhat is your name? Nathan\nHello Nathan\n```\n\nThat's it!\n\n\nLicense\n-------\n\n(The MIT License)\n\nCopyright (c) 2012 Nathan Rajlich &lt;nathan@tootallnate.net&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","_attachments":{}}