// TTY detection for Bun compatibility. // Bun does not set process.stdin.isTTY, so we use fs.fstatSync. import { fstatSync } from "node:fs"; let _stdinTTY: boolean | null = null; export function initTTY(): void { if (_stdinTTY !== null) return; try { // fd 0 = stdin. On Unix, a TTY is a character device. const stat = fstatSync(0); _stdinTTY = stat.isCharacterDevice(); } catch { _stdinTTY = false; } } export function isStdinTTY(): boolean { if (_stdinTTY === null) initTTY(); return _stdinTTY!; } export function isStdoutTTY(): boolean { // Use a heuristic for stdout — check if we're in a terminal if (process.env.TERM || process.env.TERM_PROGRAM) return true; if (process.env.NO_COLOR) return false; // Try fstat on fd 1 (stdout) try { const stat = fstatSync(1); return stat.isCharacterDevice(); } catch { return false; } }