- Assertion testing
- Asynchronous context tracking
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:module
API - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
Node.js v18.12.1 documentation
- Node.js v18.12.1
-
► Table of contents
- TTY
- Class:
tty.ReadStream
- Class:
tty.WriteStream
- Event:
'resize'
writeStream.clearLine(dir[, callback])
writeStream.clearScreenDown([callback])
writeStream.columns
writeStream.cursorTo(x[, y][, callback])
writeStream.getColorDepth([env])
writeStream.getWindowSize()
writeStream.hasColors([count][, env])
writeStream.isTTY
writeStream.moveCursor(dx, dy[, callback])
writeStream.rows
- Event:
tty.isatty(fd)
- Class:
- TTY
-
► Index
- Assertion testing
- Asynchronous context tracking
- Async hooks
- Buffer
- C++ addons
- C/C++ addons with Node-API
- C++ embedder API
- Child processes
- Cluster
- Command-line options
- Console
- Corepack
- Crypto
- Debugger
- Deprecated APIs
- Diagnostics Channel
- DNS
- Domain
- Errors
- Events
- File system
- Globals
- HTTP
- HTTP/2
- HTTPS
- Inspector
- Internationalization
- Modules: CommonJS modules
- Modules: ECMAScript modules
- Modules:
node:module
API - Modules: Packages
- Net
- OS
- Path
- Performance hooks
- Permissions
- Process
- Punycode
- Query strings
- Readline
- REPL
- Report
- Stream
- String decoder
- Test runner
- Timers
- TLS/SSL
- Trace events
- TTY
- UDP/datagram
- URL
- Utilities
- V8
- VM
- WASI
- Web Crypto API
- Web Streams API
- Worker threads
- Zlib
- ► Other versions
- ► Options
Table of contents
- TTY
- Class:
tty.ReadStream
- Class:
tty.WriteStream
- Event:
'resize'
writeStream.clearLine(dir[, callback])
writeStream.clearScreenDown([callback])
writeStream.columns
writeStream.cursorTo(x[, y][, callback])
writeStream.getColorDepth([env])
writeStream.getWindowSize()
writeStream.hasColors([count][, env])
writeStream.isTTY
writeStream.moveCursor(dx, dy[, callback])
writeStream.rows
- Event:
tty.isatty(fd)
- Class:
TTY#
Source Code: lib/tty.js
The node:tty
module provides the tty.ReadStream
and tty.WriteStream
classes. node:tty
模块提供了tty.ReadStream
和tty.WriteStream
类。In most cases, it will not be necessary or possible to use this module directly. However, it can be accessed using:在大多数情况下,没有必要也不可能直接使用此模块。但是,可以使用以下方式访问:
const tty = require('node:tty');
When Node.js detects that it is being run with a text terminal ("TTY") attached, 当Node.js检测到它是在附加文本终端(“TTY”)的情况下运行时,process.stdin
will, by default, be initialized as an instance of tty.ReadStream
and both process.stdout
and process.stderr
will, by default, be instances of tty.WriteStream
. process.stdin
默认情况下将初始化为tty.ReadStream
的实例,process.stdout
和process.stderr
默认情况下都将是tty.WriteStream
的实例。The preferred method of determining whether Node.js is being run within a TTY context is to check that the value of the 确定Node.js是否在TTY上下文中运行的首选方法是检查process.stdout.isTTY
property is true
:process.stdout.isTTY
属性的值是否为true
:
$ node -p -e "Boolean(process.stdout.isTTY)"
true
$ node -p -e "Boolean(process.stdout.isTTY)" | cat
false
In most cases, there should be little to no reason for an application to manually create instances of the 在大多数情况下,应用程序几乎没有理由手动创建tty.ReadStream
and tty.WriteStream
classes.tty.ReadStream
和tty.WriteStream
类的实例。