Skip to content

Commit

Permalink
完成对 tty 章节的翻译
Browse files Browse the repository at this point in the history
  • Loading branch information
Amery2010 committed Nov 19, 2016
1 parent c311cd5 commit 63e24b0
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 2 deletions.
6 changes: 6 additions & 0 deletions appendix/functions_glossary.md
Expand Up @@ -798,6 +798,8 @@

[response.setTimeout(msecs, callback)](../http/class_http_ServerResponse.md#responsesettimeoutmsecs-callback)

[rs.setRawMode(mode)](../tty/class_ReadStream.md#rssetrawmodemode)

### S

[setTimeout(cb, ms)](../globals/global.md#setTimeout)
Expand Down Expand Up @@ -980,6 +982,10 @@

[tlsSocket.setMaxSendFragment(size)](../tls/class_tls_TLSSocket.md#tlssocketsetmaxsendfragmentsize)

[tty.isatty(fd)](../tty/tty.md#ttyisattyfd)

[tty.setRawMode(mode)](../tty/tty.md#ttysetrawmodemode)

### U

[unref()](../timers/timer.md#unref)
Expand Down
13 changes: 13 additions & 0 deletions tty/README.md
@@ -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
```
17 changes: 17 additions & 0 deletions tty/class_ReadStream.md
@@ -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` 将被设置为结果模式。
32 changes: 32 additions & 0 deletions tty/class_WriteStream.md
@@ -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'` 事件。
15 changes: 13 additions & 2 deletions tty/tty.md
@@ -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)代替。

0 comments on commit 63e24b0

Please sign in to comment.