import { ITerminalProvider , TerminalProviderSeverity } from './ITerminalProvider' ; import { StringBuilder } from '../StringBuilder' ; import { Text } from '../Text' ; import { AnsiEscape } from './AnsiEscape' ; beta export interface IStringBufferOutputOptions { /**
     * If set to true, special characters like \\n, \\r, and the \\u001b character
     * in color control tokens will get normalized to [-n-], [-r-], and [-x-] respectively
     *
     * This option defaults to `true`
     */ normalizeSpecialCharacters : boolean ; } beta export class StringBufferTerminalProvider implements ITerminalProvider { private _standardBuffer : StringBuilder = new StringBuilder ( ) ; private _verboseBuffer : StringBuilder = new StringBuilder ( ) ; private _debugBuffer : StringBuilder = new StringBuilder ( ) ; private _warningBuffer : StringBuilder = new StringBuilder ( ) ; private _errorBuffer : StringBuilder = new StringBuilder ( ) ; private _supportsColor : boolean ; public constructor ( supportsColor = false ) { this . _supportsColor = supportsColor ; } /**
     * {@inheritDoc ITerminalProvider.write}
     */ public write ( data , severity ) { switch ( severity ) { case TerminalProviderSeverity . warning : { this . _warningBuffer . append ( data ) ; break ; } case TerminalProviderSeverity . error : { this . _errorBuffer . append ( data ) ; break ; } case TerminalProviderSeverity . verbose : { this . _verboseBuffer . append ( data ) ; break ; } case TerminalProviderSeverity . debug : { this . _debugBuffer . append ( data ) ; break ; } case TerminalProviderSeverity . log : default : { this . _standardBuffer . append ( data ) ; break ; } } } /**
     * {@inheritDoc ITerminalProvider.eolCharacter}
     */ public get eolCharacter ( ) : string { return '[n]' ; } /**
     * {@inheritDoc ITerminalProvider.supportsColor}
     */ public get supportsColor ( ) : boolean { return this . _supportsColor ; } /**
     * Get everything that has been written at log-level severity.
     */ public getOutput ( options ? ) { return this . _normalizeOutput ( this . _standardBuffer . toString ( ) , options ) ; } /**
     * Get everything that has been written at verbose-level severity.
     */ public getVerbose ( options ? ) { return this . _normalizeOutput ( this . _verboseBuffer . toString ( ) , options ) ; } /**
     * Get everything that has been written at debug-level severity.
     */ public getDebugOutput ( options ? ) { return this . _normalizeOutput ( this . _debugBuffer . toString ( ) , options ) ; } /**
     * Get everything that has been written at error-level severity.
     */ public getErrorOutput ( options ? ) { return this . _normalizeOutput ( this . _errorBuffer . toString ( ) , options ) ; } /**
     * Get everything that has been written at warning-level severity.
     */ public getWarningOutput ( options ? ) { return this . _normalizeOutput ( this . _warningBuffer . toString ( ) , options ) ; } private _normalizeOutput ( s , options ) { options = { normalizeSpecialCharacters : true , ... ( options || { } ) } ; s = Text . convertToLf ( s ) ; if ( options . normalizeSpecialCharacters ) { return AnsiEscape . formatForTests ( s , { encodeNewlines : true } ) ; } else { return s ; } } }