Skip to content

Commit 3909209

Browse files
jasnellrvagg
authored andcommittedJun 2, 2016
doc: general improvements to tty.md
PR-URL: #6931 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
1 parent b5949f8 commit 3909209

File tree

1 file changed

+48
-34
lines changed

1 file changed

+48
-34
lines changed
 

Diff for: ‎doc/api/tty.md

+48-34
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,20 @@
22

33
Stability: 2 - Stable
44

5-
The `tty` module houses the `tty.ReadStream` and `tty.WriteStream` classes. In
6-
most cases, you will not need to use this module directly.
5+
The `tty` module provides the `tty.ReadStream` and `tty.WriteStream` classes.
6+
In most cases, it will not be necessary or possible to use this module directly.
7+
However, it can be accessed using:
78

8-
When Node.js detects that it is being run inside a TTY context, then `process.stdin`
9-
will be a `tty.ReadStream` instance and `process.stdout` will be
10-
a `tty.WriteStream` instance. The preferred way to check if Node.js is being run
11-
in a TTY context is to check `process.stdout.isTTY`:
9+
```js
10+
const tty = require('tty');
11+
```
12+
13+
When Node.js detects that it is being run inside a text terminal ("TTY")
14+
context, the `process.stdin` will, by default, be initialized as an instance of
15+
`tty.ReadStream` and both `process.stdout` and `process.stderr` will, by
16+
default be instances of `tty.WriteStream`. The preferred method of determining
17+
whether Node.js is being run within a TTY context is to check that the value of
18+
the `process.stdout.isTTY` property is `true`:
1219

1320
```
1421
$ node -p -e "Boolean(process.stdout.isTTY)"
@@ -17,50 +24,55 @@ $ node -p -e "Boolean(process.stdout.isTTY)" | cat
1724
false
1825
```
1926

20-
## Class: ReadStream
27+
In most cases, there should be little to no reason for an application to
28+
create instances of the `tty.ReadStream` and `tty.WriteStream` classes.
29+
30+
## Class: tty.ReadStream
2131
<!-- YAML
2232
added: v0.5.8
2333
-->
2434

25-
A `net.Socket` subclass that represents the readable portion of a tty. In normal
26-
circumstances, `process.stdin` will be the only `tty.ReadStream` instance in any
27-
Node.js program (only when `isatty(0)` is true).
35+
The `tty.ReadStream` class is a subclass of `net.Socket` that represents the
36+
readable side of a TTY. In normal circumstances `process.stdin` will be the
37+
only `tty.ReadStream` instance in a Node.js process and there should be no
38+
reason to create additional instances.
2839

29-
### rs.isRaw
40+
### readStream.isRaw
3041
<!-- YAML
3142
added: v0.7.7
3243
-->
3344

34-
A `Boolean` that is initialized to `false`. It represents the current "raw" state
35-
of the `tty.ReadStream` instance.
45+
A `boolean` that is `true` if the TTY is currently configured to operate as a
46+
raw device. Defaults to `false`.
3647

37-
### rs.setRawMode(mode)
48+
### readStream.setRawMode(mode)
3849
<!-- YAML
3950
added: v0.7.7
4051
-->
4152

42-
`mode` should be `true` or `false`. This sets the properties of the
43-
`tty.ReadStream` to act either as a raw device or default. `isRaw` will be set
44-
to the resulting mode.
53+
* `mode` {boolean} If `true`, configures the `tty.ReadStream` to operate as a
54+
raw device. If `false`, configures the `tty.ReadStream` to operate in its
55+
default mode. The `readStream.isRaw` property will be set to the resulting
56+
mode.
4557

46-
## Class: WriteStream
58+
## Class: tty.WriteStream
4759
<!-- YAML
4860
added: v0.5.8
4961
-->
5062

51-
A `net.Socket` subclass that represents the writable portion of a tty. In normal
52-
circumstances, `process.stdout` will be the only `tty.WriteStream` instance
53-
ever created (and only when `isatty(1)` is true).
63+
The `tty.WriteStream` class is a subclass of `net.Socket` that represents the
64+
writable side of a TTY. In normal circumstances, `process.stdout` and
65+
`process.stderr` will be the only `tty.WriteStream` instances created for a
66+
Node.js process and there should be no reason to create additional instances.
5467

5568
### Event: 'resize'
5669
<!-- YAML
5770
added: v0.7.7
5871
-->
5972

60-
`function () {}`
61-
62-
Emitted by `refreshSize()` when either of the `columns` or `rows` properties
63-
has changed.
73+
The `'resize'` event is emitted whenever either of the `writeStream.columns`
74+
or `writeStream.rows` properties have changed. No arguments are passed to the
75+
listener callback when called.
6476

6577
```js
6678
process.stdout.on('resize', () => {
@@ -69,28 +81,30 @@ process.stdout.on('resize', () => {
6981
});
7082
```
7183

72-
### ws.columns
84+
### writeStream.columns
7385
<!-- YAML
7486
added: v0.7.7
7587
-->
7688

77-
A `Number` that gives the number of columns the TTY currently has. This property
78-
gets updated on `'resize'` events.
89+
A `number` specifying the number of columns the TTY currently has. This property
90+
is updated whenever the `'resize'` event is emitted.
7991

80-
### ws.rows
92+
### writeStream.rows
8193
<!-- YAML
8294
added: v0.7.7
8395
-->
8496

85-
A `Number` that gives the number of rows the TTY currently has. This property
86-
gets updated on `'resize'` events.
97+
A `number` specifying the number of rows the TTY currently has. This property
98+
is updated whenever the `'resize'` event is emitted.
8799

88100
## tty.isatty(fd)
89101
<!-- YAML
90102
added: v0.5.8
91103
-->
92104

93-
Returns `true` or `false` depending on if the `fd` is associated with a
94-
terminal.
105+
* `fd` {number} A numeric file descriptor
106+
107+
The `tty.isatty()` method returns `true` if the given `fd` is associated with
108+
a TTY and `false` if is not.
95109

96-
[tty.ReadStream#setRawMode]: #tty_rs_setrawmode_mode
110+
[tty.ReadStream#setRawMode]: #tty_readstream_setrawmode_mode

0 commit comments

Comments
 (0)
Please sign in to comment.