https://github.com/keybase/node-spotty
Get the TTY device (e.g., /dev/pts/3) of the current node process
https://github.com/keybase/node-spotty
Last synced: 4 months ago
JSON representation
Get the TTY device (e.g., /dev/pts/3) of the current node process
- Host: GitHub
- URL: https://github.com/keybase/node-spotty
- Owner: keybase
- License: bsd-3-clause
- Created: 2015-02-05T23:33:57.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2015-02-06T01:55:34.000Z (about 10 years ago)
- Last Synced: 2024-12-28T22:06:09.987Z (4 months ago)
- Language: CoffeeScript
- Size: 164 KB
- Stars: 4
- Watchers: 13
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# node-spoTTY
Get the TTY device (e.g., `/dev/pts/3`) of the current node process
## Usage
```javascript
// A clone of the `tty` command
var tty = require('spotty');
tty(function(err, res) {
if (err) {
console.error("Error found: " + err.toString())
} else {
console.log(res)
}
})
```## Approach
It's an ugly hack, but it should work. The idea is to call `fstat` on
file descriptor 0, and then to call `stat` on all `tty`-like files in dev.
Stop when we find one that matches `fstat(0)`.## Limitations
Doesn't work on Windows. Should work on OSX and Linux, but needs some
testing. Won't work if fd=0 isn't standard input connected to a TTY.## Author
Max Krohn for Keybase, Inc.