1{ 2 "type": "module", 3 "source": "doc/api/tty.md", 4 "modules": [ 5 { 6 "textRaw": "TTY", 7 "name": "tty", 8 "introduced_in": "v0.10.0", 9 "stability": 2, 10 "stabilityText": "Stable", 11 "desc": "<p><strong>Source Code:</strong> <a href=\"https://github.com/nodejs/node/blob/v14.20.1/lib/tty.js\">lib/tty.js</a></p>\n<p>The <code>tty</code> module provides the <code>tty.ReadStream</code> and <code>tty.WriteStream</code> classes.\nIn most cases, it will not be necessary or possible to use this module directly.\nHowever, it can be accessed using:</p>\n<pre><code class=\"language-js\">const tty = require('tty');\n</code></pre>\n<p>When Node.js detects that it is being run with a text terminal (\"TTY\")\nattached, <a href=\"process.html#process_process_stdin\"><code>process.stdin</code></a> will, by default, be initialized as an instance of\n<code>tty.ReadStream</code> and both <a href=\"process.html#process_process_stdout\"><code>process.stdout</code></a> and <a href=\"process.html#process_process_stderr\"><code>process.stderr</code></a> will, by\ndefault, be instances of <code>tty.WriteStream</code>. The preferred method of determining\nwhether Node.js is being run within a TTY context is to check that the value of\nthe <code>process.stdout.isTTY</code> property is <code>true</code>:</p>\n<pre><code class=\"language-console\">$ node -p -e \"Boolean(process.stdout.isTTY)\"\ntrue\n$ node -p -e \"Boolean(process.stdout.isTTY)\" | cat\nfalse\n</code></pre>\n<p>In most cases, there should be little to no reason for an application to\nmanually create instances of the <code>tty.ReadStream</code> and <code>tty.WriteStream</code>\nclasses.</p>", 12 "classes": [ 13 { 14 "textRaw": "Class: `tty.ReadStream`", 15 "type": "class", 16 "name": "tty.ReadStream", 17 "meta": { 18 "added": [ 19 "v0.5.8" 20 ], 21 "changes": [] 22 }, 23 "desc": "<ul>\n<li>Extends: <a href=\"net.html#net_class_net_socket\" class=\"type\"><net.Socket></a></li>\n</ul>\n<p>Represents the readable side of a TTY. In normal circumstances\n<a href=\"process.html#process_process_stdin\"><code>process.stdin</code></a> will be the only <code>tty.ReadStream</code> instance in a Node.js\nprocess and there should be no reason to create additional instances.</p>", 24 "properties": [ 25 { 26 "textRaw": "`readStream.isRaw`", 27 "name": "isRaw", 28 "meta": { 29 "added": [ 30 "v0.7.7" 31 ], 32 "changes": [] 33 }, 34 "desc": "<p>A <code>boolean</code> that is <code>true</code> if the TTY is currently configured to operate as a\nraw device. Defaults to <code>false</code>.</p>" 35 }, 36 { 37 "textRaw": "`readStream.isTTY`", 38 "name": "isTTY", 39 "meta": { 40 "added": [ 41 "v0.5.8" 42 ], 43 "changes": [] 44 }, 45 "desc": "<p>A <code>boolean</code> that is always <code>true</code> for <code>tty.ReadStream</code> instances.</p>" 46 } 47 ], 48 "methods": [ 49 { 50 "textRaw": "`readStream.setRawMode(mode)`", 51 "type": "method", 52 "name": "setRawMode", 53 "meta": { 54 "added": [ 55 "v0.7.7" 56 ], 57 "changes": [] 58 }, 59 "signatures": [ 60 { 61 "return": { 62 "textRaw": "Returns: {this} The read stream instance.", 63 "name": "return", 64 "type": "this", 65 "desc": "The read stream instance." 66 }, 67 "params": [ 68 { 69 "textRaw": "`mode` {boolean} If `true`, configures the `tty.ReadStream` to operate as a raw device. If `false`, configures the `tty.ReadStream` to operate in its default mode. The `readStream.isRaw` property will be set to the resulting mode.", 70 "name": "mode", 71 "type": "boolean", 72 "desc": "If `true`, configures the `tty.ReadStream` to operate as a raw device. If `false`, configures the `tty.ReadStream` to operate in its default mode. The `readStream.isRaw` property will be set to the resulting mode." 73 } 74 ] 75 } 76 ], 77 "desc": "<p>Allows configuration of <code>tty.ReadStream</code> so that it operates as a raw device.</p>\n<p>When in raw mode, input is always available character-by-character, not\nincluding modifiers. Additionally, all special processing of characters by the\nterminal is disabled, including echoing input characters.\n<kbd>Ctrl</kbd>+<kbd>C</kbd> will no longer cause a <code>SIGINT</code> when in this mode.</p>" 78 } 79 ] 80 }, 81 { 82 "textRaw": "Class: `tty.WriteStream`", 83 "type": "class", 84 "name": "tty.WriteStream", 85 "meta": { 86 "added": [ 87 "v0.5.8" 88 ], 89 "changes": [] 90 }, 91 "desc": "<ul>\n<li>Extends: <a href=\"net.html#net_class_net_socket\" class=\"type\"><net.Socket></a></li>\n</ul>\n<p>Represents the writable side of a TTY. In normal circumstances,\n<a href=\"process.html#process_process_stdout\"><code>process.stdout</code></a> and <a href=\"process.html#process_process_stderr\"><code>process.stderr</code></a> will be the only\n<code>tty.WriteStream</code> instances created for a Node.js process and there\nshould be no reason to create additional instances.</p>", 92 "events": [ 93 { 94 "textRaw": "Event: `'resize'`", 95 "type": "event", 96 "name": "resize", 97 "meta": { 98 "added": [ 99 "v0.7.7" 100 ], 101 "changes": [] 102 }, 103 "params": [], 104 "desc": "<p>The <code>'resize'</code> event is emitted whenever either of the <code>writeStream.columns</code>\nor <code>writeStream.rows</code> properties have changed. No arguments are passed to the\nlistener callback when called.</p>\n<pre><code class=\"language-js\">process.stdout.on('resize', () => {\n console.log('screen size has changed!');\n console.log(`${process.stdout.columns}x${process.stdout.rows}`);\n});\n</code></pre>" 105 } 106 ], 107 "methods": [ 108 { 109 "textRaw": "`writeStream.clearLine(dir[, callback])`", 110 "type": "method", 111 "name": "clearLine", 112 "meta": { 113 "added": [ 114 "v0.7.7" 115 ], 116 "changes": [ 117 { 118 "version": "v12.7.0", 119 "pr-url": "https://github.com/nodejs/node/pull/28721", 120 "description": "The stream's write() callback and return value are exposed." 121 } 122 ] 123 }, 124 "signatures": [ 125 { 126 "return": { 127 "textRaw": "Returns: {boolean} `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.", 128 "name": "return", 129 "type": "boolean", 130 "desc": "`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`." 131 }, 132 "params": [ 133 { 134 "textRaw": "`dir` {number}", 135 "name": "dir", 136 "type": "number", 137 "options": [ 138 { 139 "textRaw": "`-1`: to the left from cursor", 140 "name": "-1", 141 "desc": "to the left from cursor" 142 }, 143 { 144 "textRaw": "`1`: to the right from cursor", 145 "name": "1", 146 "desc": "to the right from cursor" 147 }, 148 { 149 "textRaw": "`0`: the entire line", 150 "name": "0", 151 "desc": "the entire line" 152 } 153 ] 154 }, 155 { 156 "textRaw": "`callback` {Function} Invoked once the operation completes.", 157 "name": "callback", 158 "type": "Function", 159 "desc": "Invoked once the operation completes." 160 } 161 ] 162 } 163 ], 164 "desc": "<p><code>writeStream.clearLine()</code> clears the current line of this <code>WriteStream</code> in a\ndirection identified by <code>dir</code>.</p>" 165 }, 166 { 167 "textRaw": "`writeStream.clearScreenDown([callback])`", 168 "type": "method", 169 "name": "clearScreenDown", 170 "meta": { 171 "added": [ 172 "v0.7.7" 173 ], 174 "changes": [ 175 { 176 "version": "v12.7.0", 177 "pr-url": "https://github.com/nodejs/node/pull/28721", 178 "description": "The stream's write() callback and return value are exposed." 179 } 180 ] 181 }, 182 "signatures": [ 183 { 184 "return": { 185 "textRaw": "Returns: {boolean} `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.", 186 "name": "return", 187 "type": "boolean", 188 "desc": "`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`." 189 }, 190 "params": [ 191 { 192 "textRaw": "`callback` {Function} Invoked once the operation completes.", 193 "name": "callback", 194 "type": "Function", 195 "desc": "Invoked once the operation completes." 196 } 197 ] 198 } 199 ], 200 "desc": "<p><code>writeStream.clearScreenDown()</code> clears this <code>WriteStream</code> from the current\ncursor down.</p>" 201 }, 202 { 203 "textRaw": "`writeStream.cursorTo(x[, y][, callback])`", 204 "type": "method", 205 "name": "cursorTo", 206 "meta": { 207 "added": [ 208 "v0.7.7" 209 ], 210 "changes": [ 211 { 212 "version": "v12.7.0", 213 "pr-url": "https://github.com/nodejs/node/pull/28721", 214 "description": "The stream's write() callback and return value are exposed." 215 } 216 ] 217 }, 218 "signatures": [ 219 { 220 "return": { 221 "textRaw": "Returns: {boolean} `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.", 222 "name": "return", 223 "type": "boolean", 224 "desc": "`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`." 225 }, 226 "params": [ 227 { 228 "textRaw": "`x` {number}", 229 "name": "x", 230 "type": "number" 231 }, 232 { 233 "textRaw": "`y` {number}", 234 "name": "y", 235 "type": "number" 236 }, 237 { 238 "textRaw": "`callback` {Function} Invoked once the operation completes.", 239 "name": "callback", 240 "type": "Function", 241 "desc": "Invoked once the operation completes." 242 } 243 ] 244 } 245 ], 246 "desc": "<p><code>writeStream.cursorTo()</code> moves this <code>WriteStream</code>'s cursor to the specified\nposition.</p>" 247 }, 248 { 249 "textRaw": "`writeStream.getColorDepth([env])`", 250 "type": "method", 251 "name": "getColorDepth", 252 "meta": { 253 "added": [ 254 "v9.9.0" 255 ], 256 "changes": [] 257 }, 258 "signatures": [ 259 { 260 "return": { 261 "textRaw": "Returns: {number}", 262 "name": "return", 263 "type": "number" 264 }, 265 "params": [ 266 { 267 "textRaw": "`env` {Object} An object containing the environment variables to check. This enables simulating the usage of a specific terminal. **Default:** `process.env`.", 268 "name": "env", 269 "type": "Object", 270 "default": "`process.env`", 271 "desc": "An object containing the environment variables to check. This enables simulating the usage of a specific terminal." 272 } 273 ] 274 } 275 ], 276 "desc": "<p>Returns:</p>\n<ul>\n<li><code>1</code> for 2,</li>\n<li><code>4</code> for 16,</li>\n<li><code>8</code> for 256,</li>\n<li><code>24</code> for 16,777,216</li>\n</ul>\n<p>colors supported.</p>\n<p>Use this to determine what colors the terminal supports. Due to the nature of\ncolors in terminals it is possible to either have false positives or false\nnegatives. It depends on process information and the environment variables that\nmay lie about what terminal is used.\nIt is possible to pass in an <code>env</code> object to simulate the usage of a specific\nterminal. This can be useful to check how specific environment settings behave.</p>\n<p>To enforce a specific color support, use one of the below environment settings.</p>\n<ul>\n<li>2 colors: <code>FORCE_COLOR = 0</code> (Disables colors)</li>\n<li>16 colors: <code>FORCE_COLOR = 1</code></li>\n<li>256 colors: <code>FORCE_COLOR = 2</code></li>\n<li>16,777,216 colors: <code>FORCE_COLOR = 3</code></li>\n</ul>\n<p>Disabling color support is also possible by using the <code>NO_COLOR</code> and\n<code>NODE_DISABLE_COLORS</code> environment variables.</p>" 277 }, 278 { 279 "textRaw": "`writeStream.getWindowSize()`", 280 "type": "method", 281 "name": "getWindowSize", 282 "meta": { 283 "added": [ 284 "v0.7.7" 285 ], 286 "changes": [] 287 }, 288 "signatures": [ 289 { 290 "return": { 291 "textRaw": "Returns: {number[]}", 292 "name": "return", 293 "type": "number[]" 294 }, 295 "params": [] 296 } 297 ], 298 "desc": "<p><code>writeStream.getWindowSize()</code> returns the size of the TTY\ncorresponding to this <code>WriteStream</code>. The array is of the type\n<code>[numColumns, numRows]</code> where <code>numColumns</code> and <code>numRows</code> represent the number\nof columns and rows in the corresponding TTY.</p>" 299 }, 300 { 301 "textRaw": "`writeStream.hasColors([count][, env])`", 302 "type": "method", 303 "name": "hasColors", 304 "meta": { 305 "added": [ 306 "v11.13.0", 307 "v10.16.0" 308 ], 309 "changes": [] 310 }, 311 "signatures": [ 312 { 313 "return": { 314 "textRaw": "Returns: {boolean}", 315 "name": "return", 316 "type": "boolean" 317 }, 318 "params": [ 319 { 320 "textRaw": "`count` {integer} The number of colors that are requested (minimum 2). **Default:** 16.", 321 "name": "count", 322 "type": "integer", 323 "default": "16", 324 "desc": "The number of colors that are requested (minimum 2)." 325 }, 326 { 327 "textRaw": "`env` {Object} An object containing the environment variables to check. This enables simulating the usage of a specific terminal. **Default:** `process.env`.", 328 "name": "env", 329 "type": "Object", 330 "default": "`process.env`", 331 "desc": "An object containing the environment variables to check. This enables simulating the usage of a specific terminal." 332 } 333 ] 334 } 335 ], 336 "desc": "<p>Returns <code>true</code> if the <code>writeStream</code> supports at least as many colors as provided\nin <code>count</code>. Minimum support is 2 (black and white).</p>\n<p>This has the same false positives and negatives as described in\n<a href=\"#tty_writestream_getcolordepth_env\"><code>writeStream.getColorDepth()</code></a>.</p>\n<pre><code class=\"language-js\">process.stdout.hasColors();\n// Returns true or false depending on if `stdout` supports at least 16 colors.\nprocess.stdout.hasColors(256);\n// Returns true or false depending on if `stdout` supports at least 256 colors.\nprocess.stdout.hasColors({ TMUX: '1' });\n// Returns true.\nprocess.stdout.hasColors(2 ** 24, { TMUX: '1' });\n// Returns false (the environment setting pretends to support 2 ** 8 colors).\n</code></pre>" 337 }, 338 { 339 "textRaw": "`writeStream.moveCursor(dx, dy[, callback])`", 340 "type": "method", 341 "name": "moveCursor", 342 "meta": { 343 "added": [ 344 "v0.7.7" 345 ], 346 "changes": [ 347 { 348 "version": "v12.7.0", 349 "pr-url": "https://github.com/nodejs/node/pull/28721", 350 "description": "The stream's write() callback and return value are exposed." 351 } 352 ] 353 }, 354 "signatures": [ 355 { 356 "return": { 357 "textRaw": "Returns: {boolean} `false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`.", 358 "name": "return", 359 "type": "boolean", 360 "desc": "`false` if the stream wishes for the calling code to wait for the `'drain'` event to be emitted before continuing to write additional data; otherwise `true`." 361 }, 362 "params": [ 363 { 364 "textRaw": "`dx` {number}", 365 "name": "dx", 366 "type": "number" 367 }, 368 { 369 "textRaw": "`dy` {number}", 370 "name": "dy", 371 "type": "number" 372 }, 373 { 374 "textRaw": "`callback` {Function} Invoked once the operation completes.", 375 "name": "callback", 376 "type": "Function", 377 "desc": "Invoked once the operation completes." 378 } 379 ] 380 } 381 ], 382 "desc": "<p><code>writeStream.moveCursor()</code> moves this <code>WriteStream</code>'s cursor <em>relative</em> to its\ncurrent position.</p>" 383 } 384 ], 385 "properties": [ 386 { 387 "textRaw": "`writeStream.columns`", 388 "name": "columns", 389 "meta": { 390 "added": [ 391 "v0.7.7" 392 ], 393 "changes": [] 394 }, 395 "desc": "<p>A <code>number</code> specifying the number of columns the TTY currently has. This property\nis updated whenever the <code>'resize'</code> event is emitted.</p>" 396 }, 397 { 398 "textRaw": "`writeStream.isTTY`", 399 "name": "isTTY", 400 "meta": { 401 "added": [ 402 "v0.5.8" 403 ], 404 "changes": [] 405 }, 406 "desc": "<p>A <code>boolean</code> that is always <code>true</code>.</p>" 407 }, 408 { 409 "textRaw": "`writeStream.rows`", 410 "name": "rows", 411 "meta": { 412 "added": [ 413 "v0.7.7" 414 ], 415 "changes": [] 416 }, 417 "desc": "<p>A <code>number</code> specifying the number of rows the TTY currently has. This property\nis updated whenever the <code>'resize'</code> event is emitted.</p>" 418 } 419 ] 420 } 421 ], 422 "methods": [ 423 { 424 "textRaw": "`tty.isatty(fd)`", 425 "type": "method", 426 "name": "isatty", 427 "meta": { 428 "added": [ 429 "v0.5.8" 430 ], 431 "changes": [] 432 }, 433 "signatures": [ 434 { 435 "return": { 436 "textRaw": "Returns: {boolean}", 437 "name": "return", 438 "type": "boolean" 439 }, 440 "params": [ 441 { 442 "textRaw": "`fd` {number} A numeric file descriptor", 443 "name": "fd", 444 "type": "number", 445 "desc": "A numeric file descriptor" 446 } 447 ] 448 } 449 ], 450 "desc": "<p>The <code>tty.isatty()</code> method returns <code>true</code> if the given <code>fd</code> is associated with\na TTY and <code>false</code> if it is not, including whenever <code>fd</code> is not a non-negative\ninteger.</p>" 451 } 452 ], 453 "type": "module", 454 "displayName": "TTY" 455 } 456 ] 457}