bare-tty
Native TTY streams for JavaScript
bare-tty — Native TTY streams for JavaScript. It is a native addon and requires Bare >=1.16.0.
Mirrors the Node.js tty module.
npm i bare-ttyUsage
const tty = require('bare-tty')
const stdout = new tty.WriteStream(1)
stdout.write('Hello world!\n')API
ReadStream
new ReadStream(fd: number, opts?: ReadableOptions)
Source
Create a ReadStream for the TTY file descriptor fd.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fd | number | — | The file descriptor of the TTY. |
opts? | ReadableOptions | — | Options; readBufferSize defaults to 65536 and allowHalfOpen to true. |
ReadStream.fd: number
Source
The stream's underlying file descriptor.
ReadStream.isTTY: true
Source
Always true, identifying the stream as a TTY.
setMode(mode: number): this
Source
Set the TTY mode directly, using one of the constants.mode values. Returns the stream.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mode | number | — | The TTY mode to set, one of the constants.mode values. |
setRawMode(mode: boolean): this
Source
Enable or disable raw mode. In raw mode, input is delivered byte-by-byte without line buffering or special key processing. Returns the stream.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
mode | boolean | — | true to enable raw mode, false to return to normal mode. |
WriteStream
new WriteStream(fd: number, opts?: WritableOptions)
Source
Create a WriteStream for the TTY file descriptor fd.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fd | number | — | The file descriptor of the TTY. |
opts? | WritableOptions | — | — |
columns: number
Source
The current number of columns in the TTY.
WriteStream.fd: number
Source
The stream's underlying file descriptor.
getWindowSize(): [width: number, height: number]
Source
Return the current TTY dimensions as [width, height].
WriteStream.isTTY: true
Source
Always true, identifying the stream as a TTY.
rows: number
Source
The current number of rows in the TTY.
Functions
isTTY(fd: number): boolean
Source
Return whether fd refers to a TTY.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fd | number | — | The file descriptor to check. |
Constants and variables
constants
constants: {
mode: { NORMAL: number; RAW: number; IO: number }
state: { READING: number; CLOSING: number }
}Native mode and internal state flags used by ReadStream/WriteStream, such as mode.NORMAL and mode.RAW.
See also
- Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.