/** * Barva — lightweight, tree-shakable ANSI color library using tagged template * literals. * * Features: * - 16 basic colors, bright variants, and the full common SGR modifier set * - 256-color palette via {@link ansi256}/{@link bgAnsi256} * - 24-bit truecolor via {@link rgb}/{@link bgRgb}/{@link hex}/{@link bgHex} * - Automatic downgrade to the level supported by the current terminal * - Chaining (e.g. `red.bold.bgYellow`) and nesting (e.g. `red\`a ${blue\`b\`}\``) * - Environment-aware (`NO_COLOR`, `FORCE_COLOR`, CI, TTY) with memoization */ /** * Color output capability. * 0 — no colors * 1 — basic 16 ANSI colors * 2 — 256-color palette (8-bit) * 3 — truecolor (24-bit RGB) */ type ColorLevel = 0 | 1 | 2 | 3; /** * Named constants for {@link ColorLevel}. Use these instead of passing raw * numbers to {@link setLevel}: * * ```ts * setLevel(ColorLevel.TrueColor); * ``` * * The `as const` assertion narrows each field to its literal type (e.g. * `ColorLevel.TrueColor` has type `3`), so values are assignable to the * {@link ColorLevel} type without casts. */ declare const ColorLevel: { readonly None: 0; readonly Basic: 1; readonly Ansi256: 2; readonly TrueColor: 3; }; /** * Recognised terminal-emulator identifiers. Exported as constants so * consumer code can introspect or match against the same values barva uses * internally for detection. * * ```ts * if (process.env.TERMINAL_EMULATOR === TerminalEmulator.JetBrainsJediTerm) { * // running inside an IntelliJ-family IDE terminal * } * ``` */ declare const TerminalEmulator: { /** * Value of the `TERMINAL_EMULATOR` environment variable set by every * JetBrains-family IDE's built-in terminal — IntelliJ IDEA, WebStorm, * PyCharm, PhpStorm, RubyMine, CLion, GoLand, Rider, DataGrip, Android * Studio, and every other product that embeds JediTerm. */ readonly JetBrainsJediTerm: "JetBrains-JediTerm"; /** * Value of the `TERM_PROGRAM` environment variable set by VS Code's * built-in terminal. */ readonly VSCode: "vscode"; }; /** Values that may be interpolated into a Barva tagged template. */ type BarvaValue = string | number | boolean | bigint | symbol | object | null | undefined; /** * A single styling directive. Stored in structured form so the final rendered * SGR string can be computed per-call based on the current color level. */ type Segment = { readonly kind: 'basic'; readonly code: number; readonly key: string; } | { readonly kind: 'ansi256'; readonly bg: boolean; readonly code: number; readonly key: string; } | { readonly kind: 'truecolor'; readonly bg: boolean; readonly r: number; readonly g: number; readonly b: number; readonly key: string; }; declare const BARVA_BRAND: unique symbol; /** Callable core of a colorizer; augmented with chainable base names below. */ interface ColorizerCore { (strings: TemplateStringsArray, ...values: BarvaValue[]): string; readonly [BARVA_BRAND]: true; /** Internal: the canonical, deduplicated segments. Read-only. */ readonly _segments: ReadonlyArray; /** Create a colorizer with an added 24-bit RGB foreground. */ rgb(r: number, g: number, b: number): BarvaColorizer; /** Create a colorizer with an added 24-bit RGB background. */ bgRgb(r: number, g: number, b: number): BarvaColorizer; /** Create a colorizer with an added foreground from a CSS hex color. */ hex(hex: string): BarvaColorizer; /** Create a colorizer with an added background from a CSS hex color. */ bgHex(hex: string): BarvaColorizer; /** Create a colorizer with an added 256-palette foreground (0-255). */ ansi256(code: number): BarvaColorizer; /** Create a colorizer with an added 256-palette background (0-255). */ bgAnsi256(code: number): BarvaColorizer; } /** Names of all modifier-style SGR codes exposed as base colorizers. */ type ModifierName = 'bold' | 'dim' | 'italic' | 'underline' | 'blink' | 'inverse' | 'hidden' | 'strikethrough' | 'doubleUnderline' | 'framed' | 'encircled' | 'overline' | 'superscript' | 'subscript'; /** Names of all basic foreground colors (including bright variants + aliases). */ type ForegroundName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'grey' | 'gray' | 'blackBright' | 'redBright' | 'greenBright' | 'yellowBright' | 'blueBright' | 'magentaBright' | 'cyanBright' | 'whiteBright' | 'greyBright' | 'grayBright'; /** Names of all basic background colors (including bright variants + aliases). */ type BackgroundName = 'bgBlack' | 'bgRed' | 'bgGreen' | 'bgYellow' | 'bgBlue' | 'bgMagenta' | 'bgCyan' | 'bgWhite' | 'bgGrey' | 'bgGray' | 'bgBlackBright' | 'bgRedBright' | 'bgGreenBright' | 'bgYellowBright' | 'bgBlueBright' | 'bgMagentaBright' | 'bgCyanBright' | 'bgWhiteBright' | 'bgGreyBright' | 'bgGrayBright'; /** Union of every base-name colorizer. */ type BaseName = ModifierName | ForegroundName | BackgroundName; /** * A colorizer: a tagged template function that is also indexable by any * base-name to yield another colorizer (for chaining) and callable via * {@link ColorizerCore.rgb}/{@link ColorizerCore.hex}/etc. */ type BarvaColorizer = ColorizerCore & { readonly [K in BaseName]: BarvaColorizer; }; /** * Returns the current color level, running detection on first access. */ declare const getLevel: () => ColorLevel; /** * Overrides the color level. Pass `undefined` to re-run environment detection. * Values outside 0-3 are clamped. */ declare const setLevel: (level: ColorLevel | undefined) => void; /** * Enables or disables colors. `undefined`/no argument re-runs environment * detection. Passing `true` keeps the detected level when it is positive, and * falls back to basic (level 1) when detection says none. */ declare const setEnabled: (enabled?: boolean) => void; /** * Disables colors. `undefined`/no argument disables; passing `false` enables * (inverse of {@link setEnabled}). */ declare const setDisabled: (disabled?: boolean) => void; /** Whether any color output is currently enabled (level > 0). */ declare const isEnabled: () => boolean; /** * Whether the environment (re-evaluated on every call, without relying on * cached state) currently supports any color output. Useful as a probe. */ declare const isColorSupported: () => boolean; /** * Internal: force a re-read of the environment. Exported so tests can verify * detection without relying on side effects of other APIs. * * @internal */ declare const _refreshEnv: () => ColorLevel; /** * Returns a fresh `RegExp` matching any ANSI escape sequence. A new instance * is returned on every call so callers can safely use it with stateful * methods (e.g. `.exec`) without interference. */ declare const ansiRegex: () => RegExp; /** * Removes every ANSI escape sequence from the input string. Safe for * non-string inputs (returned via `String()`). */ declare const strip: (input: string) => string; /** Alias for {@link strip} matching the `strip-ansi` package name. */ declare const stripAnsi: (input: string) => string; /** * Emits a plain ANSI reset sequence. Useful when manually writing to streams * and needing to cancel prior styling without wrapping content. */ declare const reset: BarvaColorizer; /** Returns a colorizer for a 24-bit RGB foreground color. */ declare const rgb: (r: number, g: number, b: number) => BarvaColorizer; /** Returns a colorizer for a 24-bit RGB background color. */ declare const bgRgb: (r: number, g: number, b: number) => BarvaColorizer; /** Returns a colorizer for a foreground color parsed from a CSS hex string. */ declare const hex: (hexCode: string) => BarvaColorizer; /** Returns a colorizer for a background color parsed from a CSS hex string. */ declare const bgHex: (hexCode: string) => BarvaColorizer; /** Returns a colorizer for a 256-palette (8-bit) foreground color. */ declare const ansi256: (code: number) => BarvaColorizer; /** Returns a colorizer for a 256-palette (8-bit) background color. */ declare const bgAnsi256: (code: number) => BarvaColorizer; declare const bold: BarvaColorizer; declare const dim: BarvaColorizer; declare const italic: BarvaColorizer; declare const underline: BarvaColorizer; declare const blink: BarvaColorizer; declare const inverse: BarvaColorizer; declare const hidden: BarvaColorizer; declare const strikethrough: BarvaColorizer; declare const doubleUnderline: BarvaColorizer; declare const framed: BarvaColorizer; declare const encircled: BarvaColorizer; declare const overline: BarvaColorizer; declare const superscript: BarvaColorizer; declare const subscript: BarvaColorizer; declare const black: BarvaColorizer; declare const red: BarvaColorizer; declare const green: BarvaColorizer; declare const yellow: BarvaColorizer; declare const blue: BarvaColorizer; declare const magenta: BarvaColorizer; declare const cyan: BarvaColorizer; declare const white: BarvaColorizer; declare const grey: BarvaColorizer; declare const gray: BarvaColorizer; declare const blackBright: BarvaColorizer; declare const redBright: BarvaColorizer; declare const greenBright: BarvaColorizer; declare const yellowBright: BarvaColorizer; declare const blueBright: BarvaColorizer; declare const magentaBright: BarvaColorizer; declare const cyanBright: BarvaColorizer; declare const whiteBright: BarvaColorizer; declare const greyBright: BarvaColorizer; declare const grayBright: BarvaColorizer; declare const bgBlack: BarvaColorizer; declare const bgRed: BarvaColorizer; declare const bgGreen: BarvaColorizer; declare const bgYellow: BarvaColorizer; declare const bgBlue: BarvaColorizer; declare const bgMagenta: BarvaColorizer; declare const bgCyan: BarvaColorizer; declare const bgWhite: BarvaColorizer; declare const bgGrey: BarvaColorizer; declare const bgGray: BarvaColorizer; declare const bgBlackBright: BarvaColorizer; declare const bgRedBright: BarvaColorizer; declare const bgGreenBright: BarvaColorizer; declare const bgYellowBright: BarvaColorizer; declare const bgBlueBright: BarvaColorizer; declare const bgMagentaBright: BarvaColorizer; declare const bgCyanBright: BarvaColorizer; declare const bgWhiteBright: BarvaColorizer; declare const bgGreyBright: BarvaColorizer; declare const bgGrayBright: BarvaColorizer; /** Namespace export with every base colorizer plus utility functions. */ interface BarvaNamespace extends Record { reset: BarvaColorizer; rgb: typeof rgb; bgRgb: typeof bgRgb; hex: typeof hex; bgHex: typeof bgHex; ansi256: typeof ansi256; bgAnsi256: typeof bgAnsi256; strip: typeof strip; stripAnsi: typeof stripAnsi; ansiRegex: typeof ansiRegex; setEnabled: typeof setEnabled; setDisabled: typeof setDisabled; setLevel: typeof setLevel; getLevel: typeof getLevel; isEnabled: typeof isEnabled; isColorSupported: typeof isColorSupported; ColorLevel: typeof ColorLevel; TerminalEmulator: typeof TerminalEmulator; } declare const barvaExport: BarvaNamespace; export { type BackgroundName, type BarvaColorizer, type BarvaNamespace, type BarvaValue, type BaseName, ColorLevel, type ForegroundName, type ModifierName, TerminalEmulator, _refreshEnv, ansi256, ansiRegex, barvaExport as barva, bgAnsi256, bgBlack, bgBlackBright, bgBlue, bgBlueBright, bgCyan, bgCyanBright, bgGray, bgGrayBright, bgGreen, bgGreenBright, bgGrey, bgGreyBright, bgHex, bgMagenta, bgMagentaBright, bgRed, bgRedBright, bgRgb, bgWhite, bgWhiteBright, bgYellow, bgYellowBright, black, blackBright, blink, blue, blueBright, bold, cyan, cyanBright, barvaExport as default, dim, doubleUnderline, encircled, framed, getLevel, gray, grayBright, green, greenBright, grey, greyBright, hex, hidden, inverse, isColorSupported, isEnabled, italic, magenta, magentaBright, overline, red, redBright, reset, rgb, setDisabled, setEnabled, setLevel, strikethrough, strip, stripAnsi, subscript, superscript, underline, white, whiteBright, yellow, yellowBright };