doc: fix reference to API `hash.final`
[platform/upstream/nodejs.git] / doc / api / tty.markdown
1 # TTY
2
3     Stability: 2 - Stable
4
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.
7
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`:
12
13 ```
14 $ node -p -e "Boolean(process.stdout.isTTY)"
15 true
16 $ node -p -e "Boolean(process.stdout.isTTY)" | cat
17 false
18 ```
19
20 ## Class: ReadStream
21
22 A `net.Socket` subclass that represents the readable portion of a tty. In normal
23 circumstances, `process.stdin` will be the only `tty.ReadStream` instance in any
24 Node.js program (only when `isatty(0)` is true).
25
26 ### rs.isRaw
27
28 A `Boolean` that is initialized to `false`. It represents the current "raw" state
29 of the `tty.ReadStream` instance.
30
31 ### rs.setRawMode(mode)
32
33 `mode` should be `true` or `false`. This sets the properties of the
34 `tty.ReadStream` to act either as a raw device or default. `isRaw` will be set
35 to the resulting mode.
36
37 ## Class: WriteStream
38
39 A `net.Socket` subclass that represents the writable portion of a tty. In normal
40 circumstances, `process.stdout` will be the only `tty.WriteStream` instance
41 ever created (and only when `isatty(1)` is true).
42
43 ### Event: 'resize'
44
45 `function () {}`
46
47 Emitted by `refreshSize()` when either of the `columns` or `rows` properties
48 has changed.
49
50 ```js
51 process.stdout.on('resize', () => {
52   console.log('screen size has changed!');
53   console.log(`${process.stdout.columns}x${process.stdout.rows}`);
54 });
55 ```
56
57 ### ws.columns
58
59 A `Number` that gives the number of columns the TTY currently has. This property
60 gets updated on `'resize'` events.
61
62 ### ws.rows
63
64 A `Number` that gives the number of rows the TTY currently has. This property
65 gets updated on `'resize'` events.
66
67 ## tty.isatty(fd)
68
69 Returns `true` or `false` depending on if the `fd` is associated with a
70 terminal.
71
72 ## tty.setRawMode(mode)
73
74     Stability: 0 - Deprecated: Use [tty.ReadStream#setRawMode][] (i.e. process.stdin.setRawMode) instead.
75
76 [tty.ReadStream#setRawMode]: #tty_rs_setrawmode_mode