mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
2.2 KiB
77 lines
2.2 KiB
13 years ago
|
# TTY
|
||
14 years ago
|
|
||
10 years ago
|
Stability: 2 - Stable
|
||
13 years ago
|
|
||
13 years ago
|
The `tty` module houses the `tty.ReadStream` and `tty.WriteStream` classes. In
|
||
|
most cases, you will not need to use this module directly.
|
||
|
|
||
10 years ago
|
When Node.js detects that it is being run inside a TTY context, then `process.stdin`
|
||
13 years ago
|
will be a `tty.ReadStream` instance and `process.stdout` will be
|
||
10 years ago
|
a `tty.WriteStream` instance. The preferred way to check if Node.js is being run
|
||
10 years ago
|
in a TTY context is to check `process.stdout.isTTY`:
|
||
14 years ago
|
|
||
9 years ago
|
```
|
||
|
$ node -p -e "Boolean(process.stdout.isTTY)"
|
||
|
true
|
||
|
$ node -p -e "Boolean(process.stdout.isTTY)" | cat
|
||
|
false
|
||
|
```
|
||
14 years ago
|
|
||
13 years ago
|
## Class: ReadStream
|
||
|
|
||
|
A `net.Socket` subclass that represents the readable portion of a tty. In normal
|
||
|
circumstances, `process.stdin` will be the only `tty.ReadStream` instance in any
|
||
10 years ago
|
Node.js program (only when `isatty(0)` is true).
|
||
13 years ago
|
|
||
|
### rs.isRaw
|
||
|
|
||
|
A `Boolean` that is initialized to `false`. It represents the current "raw" state
|
||
|
of the `tty.ReadStream` instance.
|
||
|
|
||
|
### rs.setRawMode(mode)
|
||
|
|
||
|
`mode` should be `true` or `false`. This sets the properties of the
|
||
|
`tty.ReadStream` to act either as a raw device or default. `isRaw` will be set
|
||
|
to the resulting mode.
|
||
|
|
||
12 years ago
|
## Class: WriteStream
|
||
13 years ago
|
|
||
|
A `net.Socket` subclass that represents the writable portion of a tty. In normal
|
||
|
circumstances, `process.stdout` will be the only `tty.WriteStream` instance
|
||
|
ever created (and only when `isatty(1)` is true).
|
||
|
|
||
|
### Event: 'resize'
|
||
|
|
||
|
`function () {}`
|
||
|
|
||
|
Emitted by `refreshSize()` when either of the `columns` or `rows` properties
|
||
|
has changed.
|
||
|
|
||
9 years ago
|
```js
|
||
|
process.stdout.on('resize', () => {
|
||
|
console.log('screen size has changed!');
|
||
|
console.log(`${process.stdout.columns}x${process.stdout.rows}`);
|
||
|
});
|
||
|
```
|
||
10 years ago
|
|
||
9 years ago
|
### ws.columns
|
||
10 years ago
|
|
||
9 years ago
|
A `Number` that gives the number of columns the TTY currently has. This property
|
||
9 years ago
|
gets updated on `'resize'` events.
|
||
9 years ago
|
|
||
|
### ws.rows
|
||
|
|
||
|
A `Number` that gives the number of rows the TTY currently has. This property
|
||
9 years ago
|
gets updated on `'resize'` events.
|
||
9 years ago
|
|
||
|
## tty.isatty(fd)
|
||
|
|
||
|
Returns `true` or `false` depending on if the `fd` is associated with a
|
||
|
terminal.
|
||
|
|
||
|
## tty.setRawMode(mode)
|
||
|
|
||
|
Stability: 0 - Deprecated: Use [tty.ReadStream#setRawMode][] (i.e. process.stdin.setRawMode) instead.
|
||
9 years ago
|
|
||
|
[tty.ReadStream#setRawMode]: #tty_rs_setrawmode_mode
|