Skip to content

@jsvision/core / detectTty

Function: detectTty()

detectTty(options?): boolean

Defined in: host/streams.ts:144

Check whether the app has an interactive terminal, before starting the host. Returns true when both ends are a real TTY (or the POSIX /dev/tty bind succeeds).

Use this to gate startup — a running Host exposes host.isTTY, but that is only meaningful after start(), so a pre-start check needs detectTty() instead. It is ephemeral: it binds the same streams the host would, reads the flag, and immediately disposes anything it opened (e.g. a /dev/tty fd), so no descriptor lingers.

Parameters

options?

StreamOptions = {}

Optional input/output/preferDevTty. Defaults match the host: the standard streams, with the POSIX /dev/tty fallback when piped.

Returns

boolean

true when the terminal is interactive.

Example

ts
import { detectTty, assertEssentials, resolveCapabilities } from '@jsvision/core';

if (!detectTty()) {
  console.error('This program must be run in an interactive terminal.');
  process.exit(1);
}
// Or feed it straight into the essentials gate:
assertEssentials(resolveCapabilities().profile, { isTTY: detectTty() });