import * as Effect from "effect/Effect"; import * as Layer from "effect/Layer"; import * as Path from "effect/Path"; import { announcePlatform, Tty } from "../tty.js"; export const layerTty: Layer.Layer = Layer.effect(Tty)( Effect.gen(function* () { const path = yield* Path.Path; // A no-op here, and called anyway: the rule is that the host layer // publishes its own platform, and a host that skips it is a host that // works until somebody runs it somewhere `process` is missing. announcePlatform(process.platform); return { isInteractive: Boolean(process.stderr.isTTY), // stdin, not stderr: a prompt is read, and `packall … < list.txt` has // a terminal to draw on and nothing to read from. canPrompt: Boolean(process.stdin.isTTY), platform: process.platform, columns: process.stderr.columns ?? 80, write: (text) => void process.stderr.write(text), writeOut: (text) => void process.stdout.write(text), // `exitCode` rather than `process.exit`, so pending writes still // flush. Killing the process here truncates the very error message // that explains what went wrong. exit: (code) => { process.exitCode = code; }, cwd: process.cwd(), path, }; }), );