function highlight
highlight(
source: string,
palette: Theme
): string

Source as the terminal should draw it: every token wrapped in its capture's style.

Unstyled captures are written as they are rather than wrapped in a no-op sequence, so a plainly themed line costs no bytes and a piped session stays comparable text.

import { highlight } from './highlight.ts';
import { theme } from './theme.ts';

highlight('const a = 1', theme()).includes('const'); // true — painted, not replaced
const plain = { painter: () => (text: string) => text };
highlight('const a = 1', plain); // 'const a = 1' — an unstyled theme changes nothing

Parameters

source: string
palette: Theme

Return Type

string

Usage

import { highlight } from "lib/repl/highlight.ts";