ansiWrap()function
Wrap a string in the ANSI color/style codes (at the start), and ANSI_RESET at the end.
ansiWrap(input: string, ...wrappers: ImmutableArray<string>): void
Constants and a helper for wrapping terminal output in ANSI escape codes. Use these when writing CLI tools or test reporters that need colour and style without pulling in a third-party library.
ansiWrap().ansiWrap is a no-op when the NO_COLOR environment variable is set, following the no-color.org convention.import { ansiWrap, ANSI_RED, ANSI_BOLD } from "shelving/util";
console.log(ansiWrap("Error!", ANSI_RED));
console.log(ansiWrap("Warning", ANSI_YELLOW, ANSI_BOLD)); // multiple wrappersimport { ANSI_SUCCESS, ANSI_FAILURE, ANSI_WAITING } from "shelving/util";
console.log(ANSI_SUCCESS); // ✓ in green
console.log(ANSI_FAILURE); // ✗ in red
console.log(ANSI_WAITING); // ⋯ in blueArrow icons (ANSI_UP, ANSI_DOWN, ANSI_LEFT, ANSI_RIGHT) are also available in blue.
import { ANSI_CYAN, ANSI_UNDERLINE, ANSI_RESET } from "shelving/util";
const styled = `${ANSI_CYAN}${ANSI_UNDERLINE}link text${ANSI_RESET}`;Wrap a string in the ANSI color/style codes (at the start), and ANSI_RESET at the end.
ansiWrap(input: string, ...wrappers: ImmutableArray<string>): void
A lazily-coloured icon that re-evaluates its ANSI colouring against the live NO_COLOR environment variable every time it is converted to a string.
{
toString(): string;
}ANSI escape code that resets the foreground colour to the terminal default.
ANSI escape code that sets the foreground colour to black.
ANSI escape code that sets the foreground colour to red.
ANSI escape code that sets the foreground colour to green.
ANSI escape code that sets the foreground colour to yellow.
ANSI escape code that sets the foreground colour to blue.
ANSI escape code that sets the foreground colour to magenta.
ANSI escape code that sets the foreground colour to cyan.
ANSI escape code that sets the foreground colour to white.
ANSI escape code that enables bold text.
ANSI escape code that enables italic text.
ANSI escape code that enables underlined text.
ANSI escape code that enables strikethrough text.
ANSI escape code that enables inverse (swapped foreground/background) text.
ANSI escape code that resets all colour and style attributes.
Lazily blue-coloured waiting icon (⋯) for use in template literals.
Lazily green-coloured success icon (✓) for use in template literals.
Lazily red-coloured failure icon (✗) for use in template literals.
Lazily blue-coloured up arrow icon (↑) for use in template literals.
Lazily blue-coloured down arrow icon (↓) for use in template literals.
Lazily blue-coloured right arrow icon (→) for use in template literals.
Lazily blue-coloured left arrow icon (←) for use in template literals.