Node.js v0.10.18 手册 & 文档
目录
TTY#
稳定度: 2 - 不稳定
The tty
module houses the tty.ReadStream
and tty.WriteStream
classes. In
most cases, you will not need to use this module directly.
tty
模块提供了 tty.ReadStream
和 tty.WriteStream
类。在大部分情况下,您都不会需要直接使用此模块。
When node detects that it is being run inside a TTY context, then process.stdin
will be a tty.ReadStream
instance and process.stdout
will be
a tty.WriteStream
instance. The preferred way to check if node is being run in
a TTY context is to check process.stdout.isTTY
:
当 node 检测到它正运行于 TTY 上下文中时,process.stdin
将会是一个 tty.ReadStream
实例,且 process.stdout
也将会是一个 tty.WriteStream
实例。检查 node 是否运行于 TTY 上下文的首选方式是检查 process.stdout.isTTY
:
$ node -p -e "Boolean(process.stdout.isTTY)"
true
$ node -p -e "Boolean(process.stdout.isTTY)" | cat
false
tty.isatty(fd)#
Returns true
or false
depending on if the fd
is associated with a
terminal.
若 fd
关联于中端则返回 true
,反之返回 false
。
tty.setRawMode(mode)#
Deprecated. Use tty.ReadStream#setRawMode()
(i.e. process.stdin.setRawMode()
) instead.
已废弃,请使用 tty.ReadStream#setRawMode()
(如 process.stdin.setRawMode()
)。
类: ReadStream#
A net.Socket
subclass that represents the readable portion of a tty. In normal
circumstances, process.stdin
will be the only tty.ReadStream
instance in any
node program (only when isatty(0)
is true).
一个 net.Socket
子类,代表 TTY 的可读部分。通常情况下在所有 node 程序中 process.stdin
会是仅有的 tty.ReadStream
实例(进当 isatty(0)
为 true 时)。
rs.isRaw#
A Boolean
that is initialized to false
. It represents the current "raw" state
of the tty.ReadStream
instance.
一个 Boolean
,初始为 false
,代表 tty.ReadStream
实例的当前 "raw" 状态。
rs.setRawMode(mode)#
mode
should be true
or false
. This sets the properties of the
tty.ReadStream
to act either as a raw device or default. isRaw
will be set
to the resulting mode.
mode
可以是 true
或 false
。它设定 tty.ReadStream
的属性表现为原始设备或缺省。isRaw
会被设置为结果模式。
类: WriteStream#
A net.Socket
subclass that represents the writable portion of a tty. In normal
circumstances, process.stdout
will be the only tty.WriteStream
instance
ever created (and only when isatty(1)
is true).
一个 net.Socket
子类,代表 TTY 的可写部分。通常情况下 process.stdout
会是仅有的 tty.WriteStream
实例(进当 isatty(1)
为 true 时)。
ws.columns#
A Number
that gives the number of columns the TTY currently has. This property
gets updated on "resize" events.
一个 `Number,表示 TTY 当前的列数。该属性会在 "resize" 事件中被更新。
ws.rows#
A Number
that gives the number of rows the TTY currently has. This property
gets updated on "resize" events.
一个 `Number,表示 TTY 当前的行数。该属性会在 "resize" 事件中被更新。
事件: 'resize'#
function () {}
function () {}
Emitted by refreshSize()
when either of the columns
or rows
properties
has changed.
由 refreshSize()
在 columns
或 rows
属性被改变时触发。
process.stdout.on('resize', function() {
console.log('screen size has changed!');
console.log(process.stdout.columns + 'x' + process.stdout.rows);
});
process.stdout.on('resize', function() {
console.log('屏幕大小已改变!');
console.log(process.stdout.columns + 'x' + process.stdout.rows);
});