0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/doc/api/tty.markdown
Chris Dickinson cf0306cd71 doc: update stability index
This simplifies the stability index to 4 levels:

0 - deprecated
1 - experimental / feature-flagged
2 - stable
3 - locked

Domains has been downgraded to deprecated, assert has been
downgraded to stable. Timers and Module remain locked. All
other APIs are now stable.

PR-URL: https://github.com/iojs/io.js/pull/943
Fixes: https://github.com/iojs/io.js/issues/930
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
Reviewed-By: Vladimir Kurchatkin <vladimir.kurchatkin@gmail.com>
2015-02-27 14:23:01 -08:00

2.1 KiB

TTY

Stability: 2 - Stable

The tty module houses the tty.ReadStream and tty.WriteStream classes. In most cases, you will not need to use this module directly.

When io.js detects that it is being run inside a TTY context, then process.stdin will be a tty.ReadStream instance and process.stdout will be a tty.WriteStream instance. The preferred way to check if io.js is being run in a TTY context is to check process.stdout.isTTY:

$ iojs -p -e "Boolean(process.stdout.isTTY)"
true
$ iojs -p -e "Boolean(process.stdout.isTTY)" | cat
false

tty.isatty(fd)

Returns true or false depending on if the fd is associated with a terminal.

tty.setRawMode(mode)

Deprecated. Use tty.ReadStream#setRawMode() (i.e. process.stdin.setRawMode()) instead.

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 io.js program (only when isatty(0) is true).

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.

Class: WriteStream

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).

ws.columns

A Number that gives the number of columns the TTY currently has. This property gets updated on "resize" events.

ws.rows

A Number that gives the number of rows the TTY currently has. This property gets updated on "resize" events.

Event: 'resize'

function () {}

Emitted by refreshSize() when either of the columns or rows properties has changed.

process.stdout.on('resize', function() {
  console.log('screen size has changed!');
  console.log(process.stdout.columns + 'x' + process.stdout.rows);
});