LogoPear Docs

bare-tty

Native TTY streams for JavaScript

stable

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-tty

Usage

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

ParameterTypeDefaultDescription
fdnumberThe file descriptor of the TTY.
opts?ReadableOptionsOptions; 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

ParameterTypeDefaultDescription
modenumberThe 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

ParameterTypeDefaultDescription
modebooleantrue 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

ParameterTypeDefaultDescription
fdnumberThe 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

ParameterTypeDefaultDescription
fdnumberThe file descriptor to check.

Constants and variables

constants

constants: {
  mode: { NORMAL: number; RAW: number; IO: number }
  state: { READING: number; CLOSING: number }
}
Source

Native mode and internal state flags used by ReadStream/WriteStream, such as mode.NORMAL and mode.RAW.

See also

On this page