Node.js v4.2.4 手册 & 文档
目录
TTY#
稳定度: 2 - 不稳定
tty 模块提供了 tty.ReadStream 和 tty.WriteStream 类。在大部分情况下,您都不会需要直接使用此模块。
当 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)#
若 fd 关联于中端则返回 true,反之返回 false。
tty.setRawMode(mode)#
已废弃,请使用 tty.ReadStream#setRawMode()(如 process.stdin.setRawMode())。
类: ReadStream#
一个 net.Socket 子类,代表 TTY 的可读部分。通常情况下在所有 node 程序中 process.stdin 会是仅有的 tty.ReadStream 实例(进当 isatty(0) 为 true 时)。
rs.isRaw#
一个 Boolean,初始为 false,代表 tty.ReadStream 实例的当前 "raw" 状态。
rs.setRawMode(mode)#
mode 可以是 true 或 false。它设定 tty.ReadStream 的属性表现为原始设备或缺省。isRaw 会被设置为结果模式。
类: WriteStream#
一个 net.Socket 子类,代表 TTY 的可写部分。通常情况下 process.stdout 会是仅有的 tty.WriteStream 实例(进当 isatty(1) 为 true 时)。
ws.columns#
一个 `Number,表示 TTY 当前的列数。该属性会在 "resize" 事件中被更新。
ws.rows#
一个 `Number,表示 TTY 当前的行数。该属性会在 "resize" 事件中被更新。
事件: 'resize'#
function () {}
由 refreshSize() 在 columns 或 rows 属性被改变时触发。
process.stdout.on('resize', function() {
console.log('屏幕大小已改变!');
console.log(process.stdout.columns + 'x' + process.stdout.rows);
});
