UNPKG

symfony-style-console

Version:

Use the style and utilities of the Symfony Console in Node.js

121 lines (120 loc) 3.36 kB
import OutputFormatterStyleInterface from './OutputFormatterStyleInterface'; /** * Represents an object literal with ANSI *set* and *unset* codes */ export interface AnsiCodeConfig { set: number; unset: number; } /** * Available color names */ export declare type ColorName = 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white' | 'default'; /** * Represents an object literal with [[ColorName]] keys and [[AnsiCodeConfig]] values. */ export declare type StyleColorSet = { [key in ColorName]: AnsiCodeConfig; }; /** * Available style options */ export declare type OptionName = 'bold' | 'underscore' | 'blink' | 'reverse' | 'dim' | 'conceal'; /** * Represents an object literal with [[OptionName]] keys and [[AnsiCodeConfig]] values. */ export declare type StyleOptionsSet = { [key in OptionName]: AnsiCodeConfig; }; /** * Represents an object literal with supported ANSI codes. */ export declare type StyleSet = StyleColorSet | StyleOptionsSet; /** * Formatter style class for defining styles. * * * @author Florian Reuschel <florian@loilo.de> * * Port to TypeScript * */ export default class OutputFormatterStyle implements OutputFormatterStyleInterface { /** * The ANSI escape sequences for available foreground colors. */ private static availableForegroundColors; /** * The ANSI escape sequences for available background colors. */ private static availableBackgroundColors; /** * The ANSI escape sequences for available style options. */ private static availableOptions; /** * The chosen foreground color escape sequences. */ private foreground; /** * The chosen background color escape sequences. */ private background; /** * The enabled style options escape sequences. */ private options; /** * Initializes output formatter style. * * @param foreground The style foreground color name * @param background The style background color name * @param options The style options */ constructor(foreground?: ColorName, background?: ColorName, options?: OptionName[]); /** * Sets style foreground color. * * @param color The color name * * @throws `ReferenceError` if the color name is not available */ setForeground(color?: ColorName): void; /** * Sets style background color. * * @param color The color name * * @throws `ReferenceError` if the color name is not available */ setBackground(color?: ColorName): void; /** * Sets some specific style option. * * @param option The option name * * @throws `ReferenceError` if the option name is not available */ setOption(option: OptionName): void; /** * Unsets some specific style option. * * @param string option The option name * * @throws `ReferenceError` if the option name is not available */ unsetOption(option: OptionName): void; /** * Sets multiple style options at once. * * @param The style options to enable */ setOptions(options: OptionName[]): void; /** * Applies the style to a given text. * * @param The text to style * @return The formatted text */ apply(text: string): string; }