symfony-style-console
Version:
Use the style and utilities of the Symfony Console in Node.js
126 lines (125 loc) • 3.65 kB
TypeScript
import OutputFormatterStyleStack from './OutputFormatterStyleStack';
import OutputFormatterInterface from './OutputFormatterInterface';
import OutputFormatterStyleInterface from './OutputFormatterStyleInterface';
/**
* Represents an object literal with [[OutputFormatterStyleInterface]] values mapped to their respective names.
*/
export interface OutputFormatterStyleInterfaceCollection {
[s: string]: OutputFormatterStyleInterface;
}
/**
* Formatter class for console output.
*
*
* @author Konstantin Kudryashov <ever.zet@gmail.com>
*
* Original PHP class
*
* @author Florian Reuschel <florian@loilo.de>
*
* Port to TypeScript
*/
export default class OutputFormatter implements OutputFormatterInterface {
/**
* Indicates whether the output may contain ANSI control characters.
*/
private decorated;
/**
* A mapping of formatter style names to their respective classes.
*/
private styles;
/**
* The stack manager used for nesting styles.
*/
private styleStack;
/**
* Initializes console output formatter.
*
* @param decorated Whether this formatter should actually decorate strings
* @param styles Object mappping names to [[OutputFormatterStyleInterface]] instances
*/
constructor(decorated?: boolean, styles?: OutputFormatterStyleInterfaceCollection);
/**
* Escapes the "<" special char in given text.
*
* @param text Text to escape
* @return Escaped text
*/
static escape(text: string): string;
/**
* Escapes trailing backslash "\" in given text.
*
* @param text Text to escape
* @return Escaped text
*
* @internal
*/
static escapeTrailingBackslash(text: string): string;
/**
* Creates a new instance containing the same `decorated` flag and styles.
*
* @return The cloned [[OutputFormatter]] instance
*/
clone(): OutputFormatter;
/**
* Sets the `decorated` flag property.
*
* @param decorated Whether to decorate the messages or not
*/
setDecorated(decorated: boolean): void;
/**
* Gets the `decorated` flag property.
*
* @return True if the output will decorate messages, false otherwise
*/
isDecorated(): boolean;
/**
* Sets a new style.
*
* @param name The style name
* @param style The style instance
*/
setStyle(name: string, style: OutputFormatterStyleInterface): void;
/**
* Checks if output formatter has style with specified name.
*
* @param string name
* @return bool
*/
hasStyle(name: string): boolean;
/**
* Gets style options from style with specified name.
*
* @param name
* @return The style
*
* @throws ReferenceError When style isn't defined
*/
getStyle(name: string): OutputFormatterStyleInterface;
/**
* Formats a message according to the given styles.
*
* @param message The message to style
*
* @return The styled message
*/
format(message: string): string;
/**
* Gets the used style stack.
*/
getStyleStack(): OutputFormatterStyleStack;
/**
* Tries to create new [[OutputFormatterStyleInterface]] instance from string.
*
* @param str The string to create the formatter style from
* @return `false` if `str` is not format string
*/
private createStyleFromString;
/**
* Applies current style from stack to text, if must be applied.
*
* @param text The text to format
* @return The formatted text
*/
private applyCurrentStyle;
}