Skip to content

@jsvision/core / styleKey

Function: styleKey()

styleKey(fg, bg, attrs): string

Defined in: color/encode.ts:155

Build a stable string key that is identical for cells sharing the same style — use it to cache encoded sequences or merge adjacent same-style runs.

Two cells with the same fg/bg/attrs produce the same key; any difference produces a different key. It is just a cheap concatenation, not an escape sequence — pass the same inputs to encodeStyle to get the actual bytes.

Parameters

fg

Color

Foreground color.

bg

Color

Background color.

attrs

number

Attribute bitmask (see Attr).

Returns

string

A stable key string.

Example

ts
import { styleKey, Attr } from '@jsvision/core';

styleKey('#fff', '#000', Attr.bold) === styleKey('#fff', '#000', Attr.bold); // true
styleKey('#fff', '#000', Attr.bold) === styleKey('#eee', '#000', Attr.bold); // false