May 10, 2021 Node.js
稳定性: 2 - 不稳定
Node.js
tty
tty.ReadStream
and
tty.WriteStream
class, in most cases, you don't have to use the module directly, and the methods for accessing the module are as follows:
const tty = require('tty');
When node detects that it is running in the TTY context,
process.stdin
will be
tty.ReadStream
instance, and
process.stdout
be
tty.WriteStream
instance.
A good way to detect whether node is running in the TTY context
process.stdout.isTTY
$ node -p -e "Boolean(process.stdout.isTTY)"
true
$ node -p -e "Boolean(process.stdout.isTTY)" | cat
false
If
fd
with the terminal to return
true
otherwise false is
false
had been abandoned. U
se
tty.ReadStream#setRawMode()
process.stdin.setRawMode()
replacement.
net.Socket
sub-class of Socket that represents the readable part of ttty. T
ypically, in any node program (only if
isatty(0)
is true),
process.stdin
is
tty.ReadStream
Boolean
value, which defaults to
false
I
t represents the
tty.ReadStream
state of the ReadStream instance.
mode
needs to
true
or
false
I
t sets
tty.ReadStream
property is the original device or default.
isRaw
be set to result mode.
net.Socket
sub-class of Socket that represents the writeable part of ttty. T
ypically,
process.stdout
is
tty.WriteStream
unique instance (only if
isatty(1)
is true).
The number of columns currently owned by TTY. This value is updated when the "resize" event is triggered.
The number of rows currently owned by TTY. This value is updated when the "resize" event is triggered.
function () {}
The
refreshSize()
event is triggered when a row or column changes.
process.stdout.on('resize', function() {
console.log('screen size has changed!');
console.log(process.stdout.columns + 'x' + process.stdout.rows);
});