mirror of https://github.com/lukechilds/node.git
Ryan Dahl
14 years ago
6 changed files with 101 additions and 7 deletions
@ -0,0 +1,40 @@ |
|||
## TTY |
|||
|
|||
Use `require('tty')` to access this module. |
|||
|
|||
|
|||
### tty.open(path, args=[]) |
|||
|
|||
Spawns a new process with the executable pointed to by `path` as the session |
|||
leader to a new pseudo terminal. |
|||
|
|||
Returns an array `[slaveFD, childProcess]`. `slaveFD` is the file descriptor |
|||
of the slave end of the pseudo terminal. `childProcess` is a child process |
|||
object. |
|||
|
|||
|
|||
### tty.isatty(fd) |
|||
|
|||
Returns `true` or `false` depending on if the `fd` is associated with a |
|||
terminal. |
|||
|
|||
|
|||
### tty.setRawMode(mode) |
|||
|
|||
`mode` should be `true` or `false`. This sets the properies of the current |
|||
process's stdin fd to act either as a raw device or default. |
|||
|
|||
|
|||
### tty.getColumns() |
|||
|
|||
Returns the number of columns associated with the current process's TTY. |
|||
|
|||
Note that each time this number is changed the process receives a `SIGWINCH` |
|||
signal. So you can keep a cache of it like this: |
|||
|
|||
var columns = tty.getColumns(); |
|||
process.on('SIGWINCH', function() { |
|||
columns = tty.getColumns(); |
|||
}); |
|||
|
|||
|
@ -0,0 +1,28 @@ |
|||
var spawn = require('child_process').spawn; |
|||
var binding = process.binding('stdio'); |
|||
|
|||
|
|||
exports.isatty = binding.isatty; |
|||
exports.setRawMode = binding.setRawMode; |
|||
exports.getColumns = binding.getColumns; |
|||
|
|||
|
|||
exports.open = function(path, args) { |
|||
var fds = binding.openpty(); |
|||
|
|||
var masterFD = fds[1]; |
|||
var slaveFD = fds[0]; |
|||
|
|||
var env = { TERM: 'vt100' }; |
|||
for (var k in process.env) { |
|||
env[k] = process.env[k]; |
|||
} |
|||
|
|||
child = spawn(path, args, env, [masterFD, masterFD, masterFD]); |
|||
|
|||
return [slaveFD, child]; |
|||
}; |
|||
|
|||
|
|||
|
|||
|
Loading…
Reference in new issue