ttynamespacenamespace ttyThe terminal (commons 0001-system FR-018): whether a stream is one, its size, raw mode, and the choice of colour and emoji the three ui modules each made (Stolos's core/ui.ts, the setup's ui.ts, erga's console). The choice is a pure function of the environment and the facts about the terminal (lookOf), so it is tested without one; currentLook reads them from the host.
Rules: colour only where NO_COLOR is unset or empty, and only at a terminal unless FORCE_COLOR is set; a terminal whose TERM is dumb counts as none; emoji where the locale is UTF-8, or on Windows in a terminal that says so (WT_SESSION, TERM_PROGRAM, ConEmuANSI=ON), or on a Mac with TERM_PROGRAM.
import { lookOf } from "./tty.ts";
lookOf({ env: { LANG: "en_US.UTF-8" }, terminal: true, os: "linux", columns: 120 });
// { tty: true, colour: true, emoji: true, columns: 120 }ttynamespacenamespace ttytty.StdStreamtypeno test imports ittype StdStream = "stdin" | "stdout" | "stderr";A standard stream of the process.
tty.isTerminalfunctionno test imports itfunction isTerminal(stream: StdStream): booleanWhether a standard stream is a terminal.
tty.consoleSizefunctionno test imports itfunction consoleSize(): { readonly columns: number; readonly rows: number; } | undefinedThe size of the terminal on standard output or, failing that, standard error; undefined where neither is one.
tty.setRawfunctionno test imports itfunction setRaw(on: boolean): voidRaw mode on standard input turned on (every key as it is pressed, no echo) or off; NotSupported where standard input is not a terminal.
tty.Looktypeno test imports ittype Look = { readonly tty: boolean; readonly colour: boolean; readonly emoji: boolean; readonly columns: number };How output should look.
tty.LookFactstypeno test imports ittype LookFacts = {
/** The environment's variables. */
readonly env: Readonly<Record<string, string | undefined>>;
/** Whether the stream written to is a terminal. */
readonly terminal: boolean;
/** The operating system. */
readonly os: Os;
/** The terminal's width, where known. */
readonly columns?: number;
};What the choice of a look depends on.
tty.lookOffunctionno test imports itfunction lookOf(facts: LookFacts): LookThe look the facts call for: see the module's rules. The width is the terminal's where it is at least 40, else 80.
tty.currentLookfunctionno test imports itfunction currentLook(stream?: StdStream): LookThe look for writing to a standard stream (standard error by default) of this process.
StdStreamtypeno test imports ittype StdStream = "stdin" | "stdout" | "stderr";A standard stream of the process.
isTerminalfunctionfunction isTerminal(stream: StdStream): booleanWhether a standard stream is a terminal.
consoleSizefunctionfunction consoleSize(): { readonly columns: number; readonly rows: number; } | undefinedThe size of the terminal on standard output or, failing that, standard error; undefined where neither is one.
setRawfunctionfunction setRaw(on: boolean): voidRaw mode on standard input turned on (every key as it is pressed, no echo) or off; NotSupported where standard input is not a terminal.
Looktypeno test imports ittype Look = { readonly tty: boolean; readonly colour: boolean; readonly emoji: boolean; readonly columns: number };How output should look.
LookFactstypeno test imports ittype LookFacts = {
/** The environment's variables. */
readonly env: Readonly<Record<string, string | undefined>>;
/** Whether the stream written to is a terminal. */
readonly terminal: boolean;
/** The operating system. */
readonly os: Os;
/** The terminal's width, where known. */
readonly columns?: number;
};What the choice of a look depends on.
lookOffunctionfunction lookOf(facts: LookFacts): LookThe look the facts call for: see the module's rules. The width is the terminal's where it is at least 40, else 80.
currentLookfunctionfunction currentLook(stream?: StdStream): LookThe look for writing to a standard stream (standard error by default) of this process.