roundel
API reference

roundel/tokens

Every export of roundel/tokens, with its signature and doc comment: painted, sgr, UNPAINTED, painter, error, warn and 7 more, plus 3 types.

import { painted, sgr, UNPAINTED, … } from 'roundel/tokens';

Functions

painted

s through a painter. No escape inside skips the re-open pass, no line break the line pass — chalk's own shortcut.

function painted({ open, close, back }: Painter, s: string): string;
ParameterType
{ open, close, back }Painter
sstring

Returns string

Constants

command

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

error

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

flag

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

heading

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

hint

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

muted

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

ok

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

painter

at with one more pair inside it.

const painter: (at: Painter, p: SgrPair) => Painter;

sgr

Wrap s in a chain of SGR pairs, outermost first, as chalk does: a close already inside s is followed by a re-open so a nested style survives it, and every line break closes before it and re-opens after (chalk/chalk#92). The façade computes parameters; the escape itself is emitted here and nowhere else (R3, R6).

const sgr: (chain: readonly SgrPair[], s: string) => string;

UNPAINTED

No pairs: painted hands a string back as it came.

const UNPAINTED: Painter;

value

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

warn

const error: Token, warn: Token, ok: Token, hint: Token, muted: Token, command: Token, flag: Token, value: Token, heading: Token;

Interfaces

Painter

A chain's escapes, built one pair at a time as a chalk builder grows its chain: what opens it, what closes it, and each pair's close and re-open, innermost first. A builder keeps its painter, so a styled string costs one pass over the text rather than rebuilding every escape in the chain on every call — which was most of what it cost (B5).

interface Painter {
    open: string;
    close: string;
    back: readonly (readonly [string, string])[];
}

SgrPair

One SGR pair as the chalk façade composes them: the parameters that open and close it, no escape.

interface SgrPair {
    readonly open: string;
    readonly close: string;
}

Types

Token

type Token = (s: string) => string;

On this page