bare-tty
Native TTY streams for JavaScript
v5.2.1bare-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?: ReadStreamOptions)
Create a ReadStream for the TTY file descriptor fd.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fd | number | — | The file descriptor of the TTY. |
opts? | ReadStreamOptions | — | Options; readBufferSize defaults to 65536 and allowHalfOpen to true. |
ReadStream._destroy(err: Error | null, cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
err | Error | null | — | — |
cb | StreamCallback | — | — |
ReadStream._open(cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cb | StreamCallback | — | — |
ReadStream._predestroy(): void
_read(size: number): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
size | number | — | — |
ReadStream.closed: boolean
ReadStream.destroy(err?: Error | null): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
err? | Error | null | — | — |
ReadStream.destroyed: boolean
ReadStream.destroying: boolean
ReadStream.errored: Error | null
ReadStream.fd: number
The stream's underlying file descriptor.
ReadStream.isTTY: true
Always true, identifying the stream as a TTY.
pause(): this
pipe<S extends Writable>(dest: S, cb?: StreamCallback): S
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
dest | S | — | — |
cb? | StreamCallback | — | — |
push(data: unknown | null, encoding?: BufferEncoding): boolean
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown | null | — | — |
encoding? | BufferEncoding | — | — |
read(): unknown | null
ReadStream.readable: boolean
resume(): this
setEncoding(encoding: BufferEncoding): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
encoding | BufferEncoding | — | — |
setMode(mode: number): this
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
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. |
unshift(data: unknown | null, encoding?: BufferEncoding): boolean
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown | null | — | — |
encoding? | BufferEncoding | — | — |
ReadStream.writable: boolean
WriteStream
new WriteStream(fd: number, opts?: WritableOptions)
Create a WriteStream for the TTY file descriptor fd.
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
fd | number | — | The file descriptor of the TTY. |
opts? | WritableOptions | — | — |
WriteStream._destroy(err: Error | null, cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
err | Error | null | — | — |
cb | StreamCallback | — | — |
_final(cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cb | StreamCallback | — | — |
WriteStream._open(cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cb | StreamCallback | — | — |
WriteStream._predestroy(): void
_write(data: unknown, encoding: StreamEncoding, cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown | — | — |
encoding | StreamEncoding | — | — |
cb | StreamCallback | — | — |
_writev(batch: { chunk: unknown; encoding: StreamEncoding }[], cb: StreamCallback): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
batch | { chunk: unknown; encoding: StreamEncoding }[] | — | — |
cb | StreamCallback | — | — |
WriteStream.closed: boolean
columns: number
The current number of columns in the TTY.
cork(): void
WriteStream.destroy(err?: Error | null): void
Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
err? | Error | null | — | — |
WriteStream.destroyed: boolean
WriteStream.destroying: boolean
end(cb?: StreamCallback): this
Overloads:
end(cb?: StreamCallback): this
end(data: unknown, encoding?: BufferEncoding, cb?: StreamCallback): this
end(data: unknown, cb?: StreamCallback): thisParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
cb? | StreamCallback | — | — |
WriteStream.errored: Error | null
WriteStream.fd: number
The stream's underlying file descriptor.
getWindowSize(): [width: number, height: number]
Return the current TTY dimensions as [width, height].
WriteStream.isTTY: true
Always true, identifying the stream as a TTY.
WriteStream.readable: boolean
rows: number
The current number of rows in the TTY.
uncork(): void
WriteStream.writable: boolean
write(data: unknown, encoding?: BufferEncoding, cb?: StreamCallback): boolean
Overloads:
write(data: unknown, encoding?: BufferEncoding, cb?: StreamCallback): boolean
write(data: unknown, cb?: StreamCallback): booleanParameters
| Parameter | Type | Default | Description |
|---|---|---|---|
data | unknown | — | — |
encoding? | BufferEncoding | — | — |
cb? | StreamCallback | — | — |
Functions
isTTY(fd: number): boolean
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; CLOSED: number }
}Native mode and internal state flags used by ReadStream/WriteStream, such as mode.NORMAL
and mode.RAW.
Types
ReadStreamOptions
interface ReadStreamOptions {
readBufferSize?: number
encoding?: BufferEncoding
read?(this: S, size: number): void
eagerOpen?: boolean
highWaterMark?: number
signal?: AbortSignal
open?(this: S, cb: StreamCallback): void
predestroy?(this: S): void
destroy?(this: S, err: Error | null, cb: StreamCallback): void
}Classes
TTYError
class TTYError {
code: string
}bare-tty/constants
Constants and variables
constants
constants: {
mode: { NORMAL: number; RAW: number; IO: number }
state: { READING: number; CLOSING: number; CLOSED: number }
}Native mode and internal state flags used by ReadStream/WriteStream, such as mode.NORMAL
and mode.RAW.
bare-tty/errors
Classes
errors.TTYError
See also
- Builds on
bare-events,bare-signals, andbare-stream. - Bare modules — the full
bare-*catalog. - Bare runtime API — the runtime these modules extend.
Last updated on