Usage in Deno
import * as mod from "node:tty";
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:
import tty from '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.
Represents the readable side of a TTY. In normal circumstances process.stdin
will be the only tty.ReadStream
instance in a Node.jsprocess and there should be no reason to create additional instances.
Represents the writable side of a TTY. In normal circumstances, process.stdout
and process.stderr
will be the onlytty.WriteStream
instances created for a Node.js process and thereshould be no reason to create additional instances.
The tty.isatty()
method returns true
if the given fd
is associated witha TTY and false
if it is not, including whenever fd
is not a non-negativeinteger.
-1 - to the left from cursor0 - the entire line1 - to the right from cursor