palettenamespacenamespace paletteThe console's one palette (commons 0006-signals FR-022): the colour roles as a union type, and the marks a person reads at a glance, each with an ASCII fallback for a terminal with no emoji. Whether colour and emoji may be used is the terminal's (commons 0001-system FR-018, runtime/tty.ts's lookOf); this module only obeys it: paint writes SGR sequences only where colour is allowed, and mark an emoji only where emoji are.
Capabilities has the fields of the runtime's Look that output depends on (colour, emoji, columns, the same names), so a Look is a Capabilities as it is.
import { label, mark, paint } from "./palette.ts";
mark("done", { emoji: true }); // "✅"
mark("done", { emoji: false }); // "[ok]"
paint("failure", "3 failed", { colour: true }); // "\u001b[31m3 failed\u001b[0m"
label("warning", "slow", { colour: false, emoji: false }); // "[!] slow"palettenamespacenamespace palettepalette.Capabilitiestypeno test imports ittype Capabilities = { readonly colour: boolean; readonly emoji: boolean; readonly columns: number };What the terminal written to can show: colour, emoji, and its width in columns (the fields of the runtime's Look).
palette.Roletypeno test imports ittype Role = "success" | "failure" | "skipped" | "cancelled" | "hint" | "warning" | "dim" | "accent" | "plain";What a piece of output means, and so its colour.
palette.ROLESconstno test imports itconst ROLES: readonly Role[]Every role, in a fixed order.
palette.MarkKindtypeno test imports ittype MarkKind = "done" | "failed" | "skipped" | "cancelled" | "hint" | "warning" | "pending" | "action";A mark at the start of a line: how something ended, or what a line is.
palette.MARK_KINDSconstno test imports itconst MARK_KINDS: readonly MarkKind[]Every mark, in a fixed order.
palette.MarkStyletypeno test imports ittype MarkStyle = { readonly emoji: string; readonly ascii: string; readonly role: Role };A mark as an emoji, its ASCII fallback, and the role it is painted in.
palette.MARKSconstno test imports itconst MARKS: Readonly<Record<MarkKind, MarkStyle>>The marks: ✅ ❌ ⏭️ ⏹️ 👉 ⚠️ ⏳ ⚡, and [ok] [x] [skip] [stop] -> [!] [todo] [you] where there are no emoji. ❌ and ⚠️ are problems; ⏳ (pending) is something not set up yet, expected until someone does it; ⚡ (action) is a step that is the person's to take (send a change, back up, approve): nothing is wrong, so it is neither a warning nor an error (FR-027).
palette.markfunctionno test imports itfunction mark(kind: MarkKind, caps: { readonly emoji: boolean; }): stringA mark: its emoji where the terminal shows emoji, else its ASCII fallback.
palette.sgrOffunctionno test imports itfunction sgrOf(role: Role): stringThe SGR parameters of a role; empty for plain.
palette.paintfunctionno test imports itfunction paint(role: Role, text: string, caps: { readonly colour: boolean; }): stringA text in a role's colour, followed by a reset, where colour is allowed; the text as it is where it is not, for the role plain, and for an empty text. Painted texts are put side by side, not inside one another: the inner reset would end the outer colour.
palette.labelfunctionno test imports itfunction label(kind: MarkKind, text: string, caps: { readonly colour: boolean; readonly emoji: boolean; }): stringA line's beginning: the mark painted in its role, a space, and the text.
Capabilitiestypetype Capabilities = { readonly colour: boolean; readonly emoji: boolean; readonly columns: number };What the terminal written to can show: colour, emoji, and its width in columns (the fields of the runtime's Look).
Roletypetype Role = "success" | "failure" | "skipped" | "cancelled" | "hint" | "warning" | "dim" | "accent" | "plain";What a piece of output means, and so its colour.
ROLESconstconst ROLES: readonly Role[]Every role, in a fixed order.
MarkKindtypetype MarkKind = "done" | "failed" | "skipped" | "cancelled" | "hint" | "warning" | "pending" | "action";A mark at the start of a line: how something ended, or what a line is.
MARK_KINDSconstconst MARK_KINDS: readonly MarkKind[]Every mark, in a fixed order.
MarkStyletypeno test imports ittype MarkStyle = { readonly emoji: string; readonly ascii: string; readonly role: Role };A mark as an emoji, its ASCII fallback, and the role it is painted in.
MARKSconstconst MARKS: Readonly<Record<MarkKind, MarkStyle>>The marks: ✅ ❌ ⏭️ ⏹️ 👉 ⚠️ ⏳ ⚡, and [ok] [x] [skip] [stop] -> [!] [todo] [you] where there are no emoji. ❌ and ⚠️ are problems; ⏳ (pending) is something not set up yet, expected until someone does it; ⚡ (action) is a step that is the person's to take (send a change, back up, approve): nothing is wrong, so it is neither a warning nor an error (FR-027).
markfunctionfunction mark(kind: MarkKind, caps: { readonly emoji: boolean; }): stringA mark: its emoji where the terminal shows emoji, else its ASCII fallback.
sgrOffunctionfunction sgrOf(role: Role): stringThe SGR parameters of a role; empty for plain.
paintfunctionfunction paint(role: Role, text: string, caps: { readonly colour: boolean; }): stringA text in a role's colour, followed by a reset, where colour is allowed; the text as it is where it is not, for the role plain, and for an empty text. Painted texts are put side by side, not inside one another: the inner reset would end the outer colour.
labelfunctionfunction label(kind: MarkKind, text: string, caps: { readonly colour: boolean; readonly emoji: boolean; }): stringA line's beginning: the mark painted in its role, a space, and the text.