IF Commons GitHub

surfaces/cli/style

Written to: 3 requirements: 3 proved, 0 partly, 0 failing, 0 with no test recorded. 0004-headless-cli FR-001, 0004-headless-cli FR-005, 0004-headless-cli FR-002

How the command line looks (commons headless 0004-headless-cli FR-001, FR-002, FR-005): the marks, the colours and the widths. The marks are the terminal's one palette and no other (an ASCII fallback where the terminal shows no emoji); colour is written only where the look allows it; a text is cut to the columns of the terminal, never inside a character or an escape sequence. The spinner and the progress bar are pure functions of a number, so that a test draws them without a terminal.

import { line, progressBar } from "./style.ts";
const look = { tty: false, colour: false, emoji: false, columns: 80 };
line("ok", "built", look); // "[ok] built"
progressBar(5, 10, 10, look); // "[#####-----]"

Source: commons/headless/src/surfaces/cli/style.ts

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

Looktype
type Look = palette.Capabilities & { readonly tty: boolean };

What the terminal written to can show, and whether it is one.

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

Tonetype
type Tone = ProblemLevel | "ok" | "skip" | "hint" | "cancelled";

What a line of output is about: a problem's level, or how something ended.

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

markKindOffunction
function markKindOf(tone: Tone): MarkKind

The mark of the palette a tone is written with (the palette's marks are the only marks).

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

markfunction
function mark(tone: Tone, look: Look): string

The tone's mark, painted.

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

linefunction
function line(tone: Tone, text: string, look: Look): string

A line's beginning: the tone's mark, a space and the text.

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

paintfunctionno test imports it
function paint(role: Role, text: string, look: Look): string

A text painted in a role.

dimfunctionno test imports it
function dim(text: string, look: Look): string

A text dimmed.

SPINNERconst
const SPINNER: { readonly emoji: readonly string[]; readonly ascii: readonly string[]; }

The frames of the spinner: braille where the terminal is a modern one (it shows emoji), else ASCII.

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

spinnerFramefunction
function spinnerFrame(step: number, look: Look): string

The frame of the spinner at a step; any integer is a step.

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

progressBarfunction
function progressBar(n: number, total: number, width: number, look: Look): string

A progress bar of width cells for n of total: [█████░░░░░], or [#####-----] where the terminal shows no emoji.

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

fmtDurationfunction
function fmtDuration(ms: number): string

A duration for a person: 640ms, 12s, 1m12s, 2h03m.

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

fitfunction
function fit(text: string, look: Look): string

A line cut to the terminal's width (one column is left free so that the line never wraps), with … where it was cut.

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

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