Skip to content

Colors

The @std/console/colors module provides chalk-like helpers for coloring terminal output. Each function wraps its text in an ANSI escape code and returns a new string — pass the result straight to console.log.

import { red, green, bold } from "@std/console/colors";
function main(): i32 {
console.log(red("Something went wrong"));
console.log(green("All tests passed"));
console.log(bold("Important!"));
return 0;
}

Combining styles

Because each function just returns a string, you compose styles by nesting calls:

import { red, bold, underline } from "@std/console/colors";
console.log(bold(red("Fatal error"))); // bold + red
console.log(underline(bold("Heading"))); // underline + bold

Available functions

Every function has the signature (text: string): string.

Foreground colors

black, red, green, yellow, blue, magenta, cyan, white, gray (alias grey)

Background colors

bgBlack, bgRed, bgGreen, bgYellow, bgBlue, bgMagenta, bgCyan, bgWhite

Styles

bold, dim, italic, underline, inverse, strikethrough

import { yellow, bgBlue, white, italic } from "@std/console/colors";
console.log(yellow("warning: low disk space"));
console.log(bgBlue(white(" INFO ")));
console.log(italic("a subtle note"));