@visulima/ansi
Version:
ANSI escape codes for some terminal swag.
26 lines (25 loc) • 974 B
TypeScript
/** A colour resolved to 8-bit channels. */
interface Rgb {
b: number;
g: number;
r: number;
}
/**
* Parses a colour as OSC 10/11/12 and `xparsecolor` accept it.
*
* Terminals are inconsistent about how they answer a colour query: `rgb:` device specifications are
* the documented form, but `#rrggbb` and bare X11 names both occur in the wild. Accepting all three
* means a caller reading a reply does not have to guess which terminal it is talking to.
* @param spec The colour specification.
* @returns The colour, or `undefined` when `spec` is not a colour.
* @example
* ```typescript
* import { parseColor } from "@visulima/ansi";
*
* parseColor("rgb:ffff/0000/0000"); // { b: 0, g: 0, r: 255 }
* parseColor("#ff0000"); // { b: 0, g: 0, r: 255 }
* parseColor("CornflowerBlue"); // { b: 237, g: 149, r: 100 }
* ```
*/
declare const parseColor: (spec: string) => Rgb | undefined;
export { type Rgb, parseColor as default, parseColor };