# 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);
});
~~~