Skip to content

createConsFS

createConsFS(tty, opts): ConsResult

Defined in: packages/core/src/kernel/tty/cons.ts:293

Create a consolidated tty fileserver (data/ctl/size) bound to a TtyConfig.

TtyConfig

TTY device configuration (backing ttyFS settings).

ConsOpts

Size polling callback + optional signal hook; see ConsOpts.

ConsResult

A ConsResult pairing the mountable fileserver with the host-side terminal handle.

Plan 9’s unified /dev/cons replaces the older ttyFS + ldisc + ttyCtlFS trio with a single directory whose three inner nodes own the whole terminal protocol:

  • data — byte stream; reads go through the line discipline’s cooked or raw mode, writes pass through to the host stdout.
  • ctl — writable commands rawon / rawoff (toggle ldisc mode) and setfg <pgid> (set foreground process group for signal delivery). Reads return a one-shot status line then EOF.
  • size — reads return ${cols} ${rows}\n (polls ConsOpts.getTermSize each time).

The returned ConsResult.terminal is the host-side I/O handle; the ConsResult.server mounts at /dev/cons. mkdir, remove, rename, wstat all throw EPERM. Post-dispose(), every fileserver method throws EIO.

import { createConsFS, Unix } from '@fishnet/core'
const { server, terminal } = createConsFS(ttyConfig, {
getTermSize: () => ({ cols: process.stdout.columns, rows: process.stdout.rows }),
onSignal: (sig, fgPgid) => kernel.signalGroup(fgPgid, sig),
})
const sys = await Unix().mount('/dev/cons', server).build().boot()
// host-side: pipe process.stdin → terminal.stdin, terminal.stdout → process.stdout

Single-owner: the returned ConsTerminal assumes exclusive host-side control. Multiplexing one consFS across two host adapters is not supported.