UNPKG

@thi.ng/text-format

Version:

Customizable color text formatting with presets for ANSI & HTML

150 lines 4.29 kB
import type { Fn, Keys } from "@thi.ng/api"; export declare const NONE = 0; export declare const FG_BLACK = 1; export declare const FG_RED = 2; export declare const FG_GREEN = 3; export declare const FG_YELLOW = 4; export declare const FG_BLUE = 5; export declare const FG_MAGENTA = 6; export declare const FG_CYAN = 7; export declare const FG_LIGHT_GRAY = 8; export declare const FG_GRAY = 17; export declare const FG_LIGHT_RED = 18; export declare const FG_LIGHT_GREEN = 19; export declare const FG_LIGHT_YELLOW = 20; export declare const FG_LIGHT_BLUE = 21; export declare const FG_LIGHT_MAGENTA = 22; export declare const FG_LIGHT_CYAN = 23; export declare const FG_WHITE = 24; export declare const BG_BLACK = 32; export declare const BG_RED = 64; export declare const BG_GREEN = 96; export declare const BG_YELLOW = 128; export declare const BG_BLUE = 160; export declare const BG_MAGENTA = 192; export declare const BG_CYAN = 224; export declare const BG_LIGHT_GRAY = 256; export declare const BG_GRAY = 544; export declare const BG_LIGHT_RED = 576; export declare const BG_LIGHT_GREEN = 608; export declare const BG_LIGHT_YELLOW = 640; export declare const BG_LIGHT_BLUE = 672; export declare const BG_LIGHT_MAGENTA = 704; export declare const BG_LIGHT_CYAN = 736; export declare const BG_WHITE = 768; export declare const BOLD = 1024; export declare const DIM = 2048; export declare const UNDERLINE = 4096; export declare const PRESETS_TPL: { black: number; blue: number; cyan: number; gray: number; green: number; magenta: number; red: number; white: number; yellow: number; lightBlue: number; lightCyan: number; lightGray: number; lightGreen: number; lightMagenta: number; lightRed: number; lightYellow: number; bgBlack: number; bgBlue: number; bgCyan: number; bgGray: number; bgGreen: number; bgMagenta: number; bgRed: number; bgWhite: number; bgYellow: number; bgLightBlue: number; bgLightCyan: number; bgLightGray: number; bgLightGreen: number; bgLightMagenta: number; bgLightRed: number; bgLightYellow: number; }; export type PresetID = Keys<typeof PRESETS_TPL>; export type FormatPresets = Record<PresetID, Fn<any, string>> & { format: StringFormat; }; export interface StringFormat { /** * Coerces `x` into a string and wraps it with formatting corresponding to * provided `code`. See {@link StringFormat.start} and * {@link StringFormat.end}. */ format(code: number, x: any): string; /** * Function translating format codes (e.g. {@link BG_RED}) to the actual * output format. This function will only be called when needed, i.e. when a * character's format is different than that of the previous. */ start: Fn<number, string>; /** * Format end string (e.g. to ANSI reset or `</span>`). */ end: string; /** * Prefix for each canvas row / line result string */ prefix: string; /** * Suffix for each canvas row / line result string (e.g. linebreak) */ suffix: string; /** * If true, DON'T skip 0-valued format IDs during formatting. * * @remarks * This is needed for various custom color-only formats, e.g. in order to * reproduce black in `FMT_ANSI565`. In the default format, a zero refers to * the default format of the target. * * @defaultValue false */ zero?: boolean; } export interface HtmlFormatOpts { /** * Array of 16 color strings, in this order: black, red, green, * yellow, blue, magenta, cyan, white, then repeated as bright * versions. */ colors: string[]; /** * HTML attrib name. */ attrib: string; /** * Delimiter between individual formatting terms (e.g. `;` for CSS * rules or ` ` for CSS class names). */ delim: string; /** * Prefix string for foreground colors */ fg: string; /** * Prefix string for background colors */ bg: string; /** * Bold format string */ bold: string; /** * Dimmed format string */ dim: string; /** * Underline format string */ underline: string; } //# sourceMappingURL=api.d.ts.map