IF Commons GitHub

tty

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-system FR-018

The 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 }

Source: commons/system/src/tty.ts

5 of 16 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

ttynamespace
namespace tty
tty.StdStreamtypeno test imports it
type StdStream = "stdin" | "stdout" | "stderr";

A standard stream of the process.

tty.isTerminalfunctionno test imports it
function isTerminal(stream: StdStream): boolean

Whether a standard stream is a terminal.

tty.consoleSizefunctionno test imports it
function consoleSize(): { readonly columns: number; readonly rows: number; } | undefined

The size of the terminal on standard output or, failing that, standard error; undefined where neither is one.

tty.setRawfunctionno test imports it
function setRaw(on: boolean): void

Raw 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 it
type Look = { readonly tty: boolean; readonly colour: boolean; readonly emoji: boolean; readonly columns: number };

How output should look.

tty.LookFactstypeno test imports it
type 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 it
function lookOf(facts: LookFacts): Look

The 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 it
function currentLook(stream?: StdStream): Look

The look for writing to a standard stream (standard error by default) of this process.

StdStreamtypeno test imports it
type StdStream = "stdin" | "stdout" | "stderr";

A standard stream of the process.

isTerminalfunction
function isTerminal(stream: StdStream): boolean

Whether a standard stream is a terminal.

Imported by 1 test of the run (1 passed, 0 failed): the library's results

consoleSizefunction
function consoleSize(): { readonly columns: number; readonly rows: number; } | undefined

The size of the terminal on standard output or, failing that, standard error; undefined where neither is one.

Imported by 1 test of the run (1 passed, 0 failed): the library's results

setRawfunction
function setRaw(on: boolean): void

Raw mode on standard input turned on (every key as it is pressed, no echo) or off; NotSupported where standard input is not a terminal.

Imported by 1 test of the run (1 passed, 0 failed): the library's results

Looktypeno test imports it
type Look = { readonly tty: boolean; readonly colour: boolean; readonly emoji: boolean; readonly columns: number };

How output should look.

LookFactstypeno test imports it
type 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.

lookOffunction
function lookOf(facts: LookFacts): Look

The look the facts call for: see the module's rules. The width is the terminal's where it is at least 40, else 80.

Imported by 1 test of the run (1 passed, 0 failed): the library's results

currentLookfunction
function currentLook(stream?: StdStream): Look

The look for writing to a standard stream (standard error by default) of this process.

Imported by 1 test of the run (1 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.