@omniblack/color
v0.0.6
Published
Tagged template functions for colorful terminal output, powered by [@cliffy/ansi](https://cliffy.io/docs/v1.2.1/ansi).
Readme
@omniblack/color
Tagged template functions for colorful terminal output, powered by @cliffy/ansi.
Install
bunx jsr add @omniblack/colorUsage
import { c, s } from "@omniblack/color";
const name = "world";
console.log(c`Hello, ${name}!`);
// ^blue ^green ^blue
console.log(s`════════════════`);
// ^purple (structural)c
A tagged template that colors static text blue and interpolated values green. Returns a ColoredString.
If an interpolated value is already a ColoredString, it passes through without being re-colored:
const header = s`[info]`;
console.log(c`${header} something happened`);
// header stays purple, " something happened" is bluee
A tagged template for error text. Colors static text red and interpolated values green. Returns a ColoredString.
const path = "/tmp/missing.txt";
console.log(e`File not found: ${path}`);
// ^red ^green ^reds
A tagged template for structural/decorative text (borders, brackets, separators). Colors static text purple (RGB 175, 0, 255) and interpolated values green. Returns a ColoredString.
const title = "status";
console.log(s`══[ ${title} ]══`);
// ^purple ^green ^purplepaint
Apply a single color to a plain string. Useful when you have a dynamic string that isn't known at template-literal time.
const label = paint("success", "c"); // blue
const err = paint(reason, "e"); // red
const sep = paint("──", "s"); // purpleprint
Writes a ColoredString to stderr. Returns a Promise<void>. By default appends a newline; override with the end option.
await print(e`something went wrong: ${err}`);
// writes colored text + newline to stderr
await print(s`> `, { end: "" });
// writes without trailing newlineDevelopment
bun install
bun test
make check # type-check
make build # emit to dist/Publishing
SRC=. dev-tools/bin/publishLicense
Apache-2.0
