- Assertion testing
- Asynchronous context tracking
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Single executable applications
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
Node.js v19.9.0 documentation
- Node.js v19.9.0
-
►
Table of contents
- TTY
- Class:
tty.ReadStream - Class:
tty.WriteStream- Event:
'resize' writeStream.clearLine(dir[, callback])writeStream.clearScreenDown([callback])writeStream.columnswriteStream.cursorTo(x[, y][, callback])writeStream.getColorDepth([env])writeStream.getWindowSize()writeStream.hasColors([count][, env])writeStream.isTTYwriteStream.moveCursor(dx, dy[, callback])writeStream.rows
- Event:
tty.isatty(fd)
- Class:
- TTY
-
►
Index
- Assertion testing
- Asynchronous context tracking
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:moduleAPI - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Single executable applications
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- ► Other versions
- ► Options
Table of contents
- TTY
- Class:
tty.ReadStream - Class:
tty.WriteStream- Event:
'resize' writeStream.clearLine(dir[, callback])writeStream.clearScreenDown([callback])writeStream.columnswriteStream.cursorTo(x[, y][, callback])writeStream.getColorDepth([env])writeStream.getWindowSize()writeStream.hasColors([count][, env])writeStream.isTTYwriteStream.moveCursor(dx, dy[, callback])writeStream.rows
- Event:
tty.isatty(fd)
- Class:
TTY#
Source Code: lib/tty.js
The node:tty module provides the tty.ReadStream and tty.WriteStream
classes. In most cases, it will not be necessary or possible to use this module
directly. However, it can be accessed using:
const tty = require('node:tty');
When Node.js detects that it is being run with a text terminal ("TTY")
attached, process.stdin will, by default, be initialized as an instance of
tty.ReadStream and both process.stdout and process.stderr will, by
default, be instances of tty.WriteStream. The preferred method of determining
whether Node.js is being run within a TTY context is to check that the value of
the process.stdout.isTTY property is true:
$ node -p -e "Boolean(process.stdout.isTTY)"
true
$ node -p -e "Boolean(process.stdout.isTTY)" | cat
false
In most cases, there should be little to no reason for an application to
manually create instances of the tty.ReadStream and tty.WriteStream
classes.
Class: tty.ReadStream#
- Extends: <net.Socket>
Represents the readable side of a TTY. In normal circumstances
process.stdin will be the only tty.ReadStream instance in a Node.js
process and there should be no reason to create additional instances.
readStream.isRaw#
A boolean that is true if the TTY is currently configured to operate as a
raw device. Defaults to false.
readStream.isTTY#
A boolean that is always true for tty.ReadStream instances.
readStream.setRawMode(mode)#
mode<boolean> Iftrue, configures thetty.ReadStreamto operate as a raw device. Iffalse, configures thetty.ReadStreamto operate in its default mode. ThereadStream.isRawproperty will be set to the resulting mode.- Returns: <this> The read stream instance.
Allows configuration of tty.ReadStream so that it operates as a raw device.
When in raw mode, input is always available character-by-character, not
including modifiers. Additionally, all special processing of characters by the
terminal is disabled, including echoing input
characters. Ctrl+C will no longer cause a SIGINT when
in this mode.
Class: tty.WriteStream#
- Extends: <net.Socket>
Represents the writable side of a TTY. In normal circumstances,
process.stdout and process.stderr will be the only
tty.WriteStream instances created for a Node.js process and there
should be no reason to create additional instances.
Event: 'resize'#
The 'resize' event is emitted whenever either of the writeStream.columns
or writeStream.rows properties have changed. No arguments are passed to the
listener callback when called.
process.stdout.on('resize', () => {
console.log('screen size has changed!');
console.log(`${process.stdout.columns}x${process.stdout.rows}`);
});
writeStream.clearLine(dir[, callback])#
dir<number>-1: to the left from cursor1: to the right from cursor0: the entire line
callback<Function> Invoked once the operation completes.- Returns: <boolean>
falseif the stream wishes for the calling code to wait for the'drain'event to be emitted before continuing to write additional data; otherwisetrue.
writeStream.clearLine() clears the current line of this WriteStream in a
direction identified by