Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,14 @@ | ||
# 终端(TTY) | ||
|
||
> 稳定度:2 - 稳定 | ||
`tty` 提供了 `tty.ReadStream` 和 `tty.WriteStream` 类。在大多数情况下,你不需要直接使用此模块。 | ||
|
||
当 Node.js 检测到它正在 TTY 上下文中运行时,那么 `process.stdin` 会是一个 `tty.ReadStream` 实例并且 `process.stdout` 会是一个 `tty.WriteStream` 实例。检查 Node.js 是否正在 TTY 上下文中运行的首选方法是去检测 `process.stdout.isTTY`: | ||
|
||
``` bash | ||
$ node -p -e "Boolean(process.stdout.isTTY)" | ||
true | ||
$ node -p -e "Boolean(process.stdout.isTTY)" | cat | ||
false | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,18 @@ | ||
# ReadStream类 | ||
|
||
* [rs.isRaw](#rsisraw) | ||
* [rs.setRawMode(mode)](#rssetrawmodemode) | ||
|
||
-------------------------------------------------- | ||
|
||
一个 `net.Socket` 子类,它表示 tty 的可读部分。在正常情况下,`process.stdin` 将是任何 Node.js 程序中唯一的 `tty.ReadStream` 实例(仅当 `isatty(0)` 为 true 时)。 | ||
|
||
|
||
## rs.isRaw | ||
|
||
一个 `Boolean`,初始化为 `false`。它表示 `tty.ReadStream` 实例的当前“原始”状态。 | ||
|
||
|
||
## rs.setRawMode(mode) | ||
|
||
`mode` 应该是 `true` 或 `false`。这将设置 `tty.ReadStream` 的属性作为原始设备或默认值。`isRaw` 将被设置为结果模式。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,33 @@ | ||
# WriteStream类 | ||
|
||
* ['resize' 事件](#resize-事件) | ||
* [ws.columns](#wscolumns) | ||
* [ws.rows](#wsrows) | ||
|
||
-------------------------------------------------- | ||
|
||
一个 `net.Socket` 子类,它表示 tty 的可写部分。在正常情况下,`process.stdout` 将是任何 Node.js 程序中唯一的 `tty.WriteStream` 实例(仅当 `isatty(1)` 为 true 时)。 | ||
|
||
|
||
## 'resize' 事件 | ||
|
||
`function () {}` | ||
|
||
当 `columns` 或 `rows` 属性中的任何一个已更改时,由 `refreshSize()` 发出。 | ||
|
||
``` javascript | ||
process.stdout.on('resize', () => { | ||
console.log('screen size has changed!'); | ||
console.log(`${process.stdout.columns}x${process.stdout.rows}`); | ||
}); | ||
``` | ||
|
||
|
||
## ws.columns | ||
|
||
一个 `Number`,给出 TTY 当前具有的列数。此属性将更新 `'resize'` 事件。 | ||
|
||
|
||
## ws.rows | ||
|
||
一个 `Number`,给出 TTY 当前具有的行数。此属性将更新 `'resize'` 事件。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,15 @@ | ||
# 方法和属性 | ||
|
||
* [tty.isatty(fd)](#isatty) | ||
* [tty.setRawMode(mode)](#setRawMode) | ||
* [tty.isatty(fd)](#ttyisattyfd) | ||
* [tty.setRawMode(mode)](#ttysetrawmodemode) | ||
|
||
-------------------------------------------------- | ||
|
||
## tty.isatty(fd) | ||
|
||
返回 `true` 或 `false` 取决于 `fd` 是否与终端相关联。 | ||
|
||
|
||
## tty.setRawMode(mode) | ||
|
||
> 稳定度:0 - 已废弃:使用 [tty.ReadStream#setRawMode](./class_ReadStream.md#rssetrawmodemode)(即 process.stdin.setRawMode)代替。 |