This commit is contained in:
2024-02-07 01:33:07 -05:00
commit c1af19d441
4088 changed files with 1260170 additions and 0 deletions

View File

@ -0,0 +1,34 @@
/**
* Options for {@link AnsiEscape.formatForTests}.
* @public
*/
export interface IAnsiEscapeConvertForTestsOptions {
/**
* If true then `\n` will be replaced by `[n]`, and `\r` will be replaced by `[r]`.
*/
encodeNewlines?: boolean;
}
/**
* Operations for working with text strings that contain
* {@link https://en.wikipedia.org/wiki/ANSI_escape_code | ANSI escape codes}.
* The most commonly used escape codes set the foreground/background color for console output.
* @public
*/
export declare class AnsiEscape {
private static readonly _csiRegExp;
private static readonly _sgrRegExp;
private static readonly _backslashNRegExp;
private static readonly _backslashRRegExp;
/**
* Returns the input text with all ANSI escape codes removed. For example, this is useful when saving
* colorized console output to a log file.
*/
static removeCodes(text: string): string;
/**
* Replaces ANSI escape codes with human-readable tokens. This is useful for unit tests
* that compare text strings in test assertions or snapshot files.
*/
static formatForTests(text: string, options?: IAnsiEscapeConvertForTestsOptions): string;
private static _tryGetSgrFriendlyName;
}
//# sourceMappingURL=AnsiEscape.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"AnsiEscape.d.ts","sourceRoot":"","sources":["../../src/Terminal/AnsiEscape.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,MAAM,WAAW,iCAAiC;IAChD;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED;;;;;GAKG;AACH,qBAAa,UAAU;IAGrB,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAA2D;IAI7F,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAwB;IAE1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAiB;IAC1D,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,iBAAiB,CAAiB;IAE1D;;;OAGG;WACW,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAK/C;;;OAGG;WACW,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,iCAAiC,GAAG,MAAM;IAiC/F,OAAO,CAAC,MAAM,CAAC,sBAAsB;CAsEtC"}

View File

@ -0,0 +1,133 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.AnsiEscape = void 0;
const Colors_1 = require("./Colors");
/**
* Operations for working with text strings that contain
* {@link https://en.wikipedia.org/wiki/ANSI_escape_code | ANSI escape codes}.
* The most commonly used escape codes set the foreground/background color for console output.
* @public
*/
class AnsiEscape {
/**
* Returns the input text with all ANSI escape codes removed. For example, this is useful when saving
* colorized console output to a log file.
*/
static removeCodes(text) {
// eslint-disable-next-line no-control-regex
return text.replace(AnsiEscape._csiRegExp, '');
}
/**
* Replaces ANSI escape codes with human-readable tokens. This is useful for unit tests
* that compare text strings in test assertions or snapshot files.
*/
static formatForTests(text, options) {
if (!options) {
options = {};
}
let result = text.replace(AnsiEscape._csiRegExp, (capture, csiCode) => {
// If it is an SGR code, then try to show a friendly token
const match = csiCode.match(AnsiEscape._sgrRegExp);
if (match) {
const sgrParameter = parseInt(match[1], 10);
const sgrParameterName = AnsiEscape._tryGetSgrFriendlyName(sgrParameter);
if (sgrParameterName) {
// Example: "[black-bg]"
return `[${sgrParameterName}]`;
}
}
// Otherwise show the raw code, but without the "[" from the CSI prefix
// Example: "[31m]"
return `[${csiCode}]`;
});
if (options.encodeNewlines) {
result = result
.replace(AnsiEscape._backslashNRegExp, '[n]')
.replace(AnsiEscape._backslashRRegExp, `[r]`);
}
return result;
}
// Returns a human-readable token representing an SGR parameter, or undefined for parameter that is not well-known.
// The SGR parameter numbers are documented in this table:
// https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters
static _tryGetSgrFriendlyName(sgiParameter) {
switch (sgiParameter) {
case Colors_1.ConsoleColorCodes.BlackForeground:
return 'black';
case Colors_1.ConsoleColorCodes.RedForeground:
return 'red';
case Colors_1.ConsoleColorCodes.GreenForeground:
return 'green';
case Colors_1.ConsoleColorCodes.YellowForeground:
return 'yellow';
case Colors_1.ConsoleColorCodes.BlueForeground:
return 'blue';
case Colors_1.ConsoleColorCodes.MagentaForeground:
return 'magenta';
case Colors_1.ConsoleColorCodes.CyanForeground:
return 'cyan';
case Colors_1.ConsoleColorCodes.WhiteForeground:
return 'white';
case Colors_1.ConsoleColorCodes.GrayForeground:
return 'gray';
case Colors_1.ConsoleColorCodes.DefaultForeground:
return 'default';
case Colors_1.ConsoleColorCodes.BlackBackground:
return 'black-bg';
case Colors_1.ConsoleColorCodes.RedBackground:
return 'red-bg';
case Colors_1.ConsoleColorCodes.GreenBackground:
return 'green-bg';
case Colors_1.ConsoleColorCodes.YellowBackground:
return 'yellow-bg';
case Colors_1.ConsoleColorCodes.BlueBackground:
return 'blue-bg';
case Colors_1.ConsoleColorCodes.MagentaBackground:
return 'magenta-bg';
case Colors_1.ConsoleColorCodes.CyanBackground:
return 'cyan-bg';
case Colors_1.ConsoleColorCodes.WhiteBackground:
return 'white-bg';
case Colors_1.ConsoleColorCodes.GrayBackground:
return 'gray-bg';
case Colors_1.ConsoleColorCodes.DefaultBackground:
return 'default-bg';
case Colors_1.ConsoleColorCodes.Bold:
return 'bold';
case Colors_1.ConsoleColorCodes.Dim:
return 'dim';
case Colors_1.ConsoleColorCodes.NormalColorOrIntensity:
return 'normal';
case Colors_1.ConsoleColorCodes.Underline:
return 'underline';
case Colors_1.ConsoleColorCodes.UnderlineOff:
return 'underline-off';
case Colors_1.ConsoleColorCodes.Blink:
return 'blink';
case Colors_1.ConsoleColorCodes.BlinkOff:
return 'blink-off';
case Colors_1.ConsoleColorCodes.InvertColor:
return 'invert';
case Colors_1.ConsoleColorCodes.InvertColorOff:
return 'invert-off';
case Colors_1.ConsoleColorCodes.Hidden:
return 'hidden';
case Colors_1.ConsoleColorCodes.HiddenOff:
return 'hidden-off';
default:
return undefined;
}
}
}
// For now, we only care about the Control Sequence Introducer (CSI) commands which always start with "[".
// eslint-disable-next-line no-control-regex
AnsiEscape._csiRegExp = /\x1b\[([\x30-\x3f]*[\x20-\x2f]*[\x40-\x7e])/gu;
// Text coloring is performed using Select Graphic Rendition (SGR) codes, which come after the
// CSI introducer "ESC [". The SGR sequence is a number followed by "m".
AnsiEscape._sgrRegExp = /([0-9]+)m/u;
AnsiEscape._backslashNRegExp = /\n/g;
AnsiEscape._backslashRRegExp = /\r/g;
exports.AnsiEscape = AnsiEscape;
//# sourceMappingURL=AnsiEscape.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,115 @@
/**
* @beta
*/
export interface IColorableSequence {
text: string;
isEol?: boolean;
foregroundColor?: ColorValue;
backgroundColor?: ColorValue;
textAttributes?: TextAttribute[];
}
export declare const eolSequence: IColorableSequence;
/**
* Colors used with {@link IColorableSequence}.
* @beta
*/
export declare enum ColorValue {
Black = 0,
Red = 1,
Green = 2,
Yellow = 3,
Blue = 4,
Magenta = 5,
Cyan = 6,
White = 7,
Gray = 8
}
/**
* Text styles used with {@link IColorableSequence}.
* @beta
*/
export declare enum TextAttribute {
Bold = 0,
Dim = 1,
Underline = 2,
Blink = 3,
InvertColor = 4,
Hidden = 5
}
export declare enum ConsoleColorCodes {
BlackForeground = 30,
RedForeground = 31,
GreenForeground = 32,
YellowForeground = 33,
BlueForeground = 34,
MagentaForeground = 35,
CyanForeground = 36,
WhiteForeground = 37,
GrayForeground = 90,
DefaultForeground = 39,
BlackBackground = 40,
RedBackground = 41,
GreenBackground = 42,
YellowBackground = 43,
BlueBackground = 44,
MagentaBackground = 45,
CyanBackground = 46,
WhiteBackground = 47,
GrayBackground = 100,
DefaultBackground = 49,
Bold = 1,
Dim = 2,
NormalColorOrIntensity = 22,
Underline = 4,
UnderlineOff = 24,
Blink = 5,
BlinkOff = 25,
InvertColor = 7,
InvertColorOff = 27,
Hidden = 8,
HiddenOff = 28
}
/**
* The static functions on this class are used to produce colored text
* for use with the node-core-library terminal.
*
* @example
* terminal.writeLine(Colors.green('Green Text!'), ' ', Colors.blue('Blue Text!'));
*
* @beta
*/
export declare class Colors {
static black(text: string | IColorableSequence): IColorableSequence;
static red(text: string | IColorableSequence): IColorableSequence;
static green(text: string | IColorableSequence): IColorableSequence;
static yellow(text: string | IColorableSequence): IColorableSequence;
static blue(text: string | IColorableSequence): IColorableSequence;
static magenta(text: string | IColorableSequence): IColorableSequence;
static cyan(text: string | IColorableSequence): IColorableSequence;
static white(text: string | IColorableSequence): IColorableSequence;
static gray(text: string | IColorableSequence): IColorableSequence;
static blackBackground(text: string | IColorableSequence): IColorableSequence;
static redBackground(text: string | IColorableSequence): IColorableSequence;
static greenBackground(text: string | IColorableSequence): IColorableSequence;
static yellowBackground(text: string | IColorableSequence): IColorableSequence;
static blueBackground(text: string | IColorableSequence): IColorableSequence;
static magentaBackground(text: string | IColorableSequence): IColorableSequence;
static cyanBackground(text: string | IColorableSequence): IColorableSequence;
static whiteBackground(text: string | IColorableSequence): IColorableSequence;
static grayBackground(text: string | IColorableSequence): IColorableSequence;
static bold(text: string | IColorableSequence): IColorableSequence;
static dim(text: string | IColorableSequence): IColorableSequence;
static underline(text: string | IColorableSequence): IColorableSequence;
static blink(text: string | IColorableSequence): IColorableSequence;
static invertColor(text: string | IColorableSequence): IColorableSequence;
static hidden(text: string | IColorableSequence): IColorableSequence;
/**
* If called with a string, returns the string wrapped in a {@link IColorableSequence}.
* If called with a {@link IColorableSequence}, returns the {@link IColorableSequence}.
*
* @internal
*/
static _normalizeStringOrColorableSequence(value: string | IColorableSequence): IColorableSequence;
private static _applyTextAttribute;
}
//# sourceMappingURL=Colors.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"Colors.d.ts","sourceRoot":"","sources":["../../src/Terminal/Colors.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,cAAc,CAAC,EAAE,aAAa,EAAE,CAAC;CAClC;AAED,eAAO,MAAM,WAAW,EAAE,kBAEH,CAAC;AAExB;;;GAGG;AACH,oBAAY,UAAU;IACpB,KAAK,IAAA;IACL,GAAG,IAAA;IACH,KAAK,IAAA;IACL,MAAM,IAAA;IACN,IAAI,IAAA;IACJ,OAAO,IAAA;IACP,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,IAAI,IAAA;CACL;AAED;;;GAGG;AACH,oBAAY,aAAa;IACvB,IAAI,IAAA;IACJ,GAAG,IAAA;IACH,SAAS,IAAA;IACT,KAAK,IAAA;IACL,WAAW,IAAA;IACX,MAAM,IAAA;CACP;AAED,oBAAY,iBAAiB;IAC3B,eAAe,KAAK;IACpB,aAAa,KAAK;IAClB,eAAe,KAAK;IACpB,gBAAgB,KAAK;IACrB,cAAc,KAAK;IACnB,iBAAiB,KAAK;IACtB,cAAc,KAAK;IACnB,eAAe,KAAK;IACpB,cAAc,KAAK;IACnB,iBAAiB,KAAK;IAEtB,eAAe,KAAK;IACpB,aAAa,KAAK;IAClB,eAAe,KAAK;IACpB,gBAAgB,KAAK;IACrB,cAAc,KAAK;IACnB,iBAAiB,KAAK;IACtB,cAAc,KAAK;IACnB,eAAe,KAAK;IACpB,cAAc,MAAM;IACpB,iBAAiB,KAAK;IAEtB,IAAI,IAAI;IAOR,GAAG,IAAI;IACP,sBAAsB,KAAK;IAC3B,SAAS,IAAI;IACb,YAAY,KAAK;IACjB,KAAK,IAAI;IACT,QAAQ,KAAK;IACb,WAAW,IAAI;IACf,cAAc,KAAK;IACnB,MAAM,IAAI;IACV,SAAS,KAAK;CACf;AAED;;;;;;;;GAQG;AACH,qBAAa,MAAM;WACH,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO5D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO1D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO5D,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO7D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO3D,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO9D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO3D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO5D,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAO3D,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOtE,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOpE,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOtE,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOvE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOrE,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOxE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOrE,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOtE,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAOrE,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAI3D,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAI1D,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAIhE,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAI5D,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;WAIlE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;IAI3E;;;;;OAKG;WACW,mCAAmC,CAAC,KAAK,EAAE,MAAM,GAAG,kBAAkB,GAAG,kBAAkB;IAUzG,OAAO,CAAC,MAAM,CAAC,mBAAmB;CAYnC"}

View File

@ -0,0 +1,184 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Colors = exports.ConsoleColorCodes = exports.TextAttribute = exports.ColorValue = exports.eolSequence = void 0;
exports.eolSequence = {
isEol: true
};
/**
* Colors used with {@link IColorableSequence}.
* @beta
*/
var ColorValue;
(function (ColorValue) {
ColorValue[ColorValue["Black"] = 0] = "Black";
ColorValue[ColorValue["Red"] = 1] = "Red";
ColorValue[ColorValue["Green"] = 2] = "Green";
ColorValue[ColorValue["Yellow"] = 3] = "Yellow";
ColorValue[ColorValue["Blue"] = 4] = "Blue";
ColorValue[ColorValue["Magenta"] = 5] = "Magenta";
ColorValue[ColorValue["Cyan"] = 6] = "Cyan";
ColorValue[ColorValue["White"] = 7] = "White";
ColorValue[ColorValue["Gray"] = 8] = "Gray";
})(ColorValue = exports.ColorValue || (exports.ColorValue = {}));
/**
* Text styles used with {@link IColorableSequence}.
* @beta
*/
var TextAttribute;
(function (TextAttribute) {
TextAttribute[TextAttribute["Bold"] = 0] = "Bold";
TextAttribute[TextAttribute["Dim"] = 1] = "Dim";
TextAttribute[TextAttribute["Underline"] = 2] = "Underline";
TextAttribute[TextAttribute["Blink"] = 3] = "Blink";
TextAttribute[TextAttribute["InvertColor"] = 4] = "InvertColor";
TextAttribute[TextAttribute["Hidden"] = 5] = "Hidden";
})(TextAttribute = exports.TextAttribute || (exports.TextAttribute = {}));
var ConsoleColorCodes;
(function (ConsoleColorCodes) {
ConsoleColorCodes[ConsoleColorCodes["BlackForeground"] = 30] = "BlackForeground";
ConsoleColorCodes[ConsoleColorCodes["RedForeground"] = 31] = "RedForeground";
ConsoleColorCodes[ConsoleColorCodes["GreenForeground"] = 32] = "GreenForeground";
ConsoleColorCodes[ConsoleColorCodes["YellowForeground"] = 33] = "YellowForeground";
ConsoleColorCodes[ConsoleColorCodes["BlueForeground"] = 34] = "BlueForeground";
ConsoleColorCodes[ConsoleColorCodes["MagentaForeground"] = 35] = "MagentaForeground";
ConsoleColorCodes[ConsoleColorCodes["CyanForeground"] = 36] = "CyanForeground";
ConsoleColorCodes[ConsoleColorCodes["WhiteForeground"] = 37] = "WhiteForeground";
ConsoleColorCodes[ConsoleColorCodes["GrayForeground"] = 90] = "GrayForeground";
ConsoleColorCodes[ConsoleColorCodes["DefaultForeground"] = 39] = "DefaultForeground";
ConsoleColorCodes[ConsoleColorCodes["BlackBackground"] = 40] = "BlackBackground";
ConsoleColorCodes[ConsoleColorCodes["RedBackground"] = 41] = "RedBackground";
ConsoleColorCodes[ConsoleColorCodes["GreenBackground"] = 42] = "GreenBackground";
ConsoleColorCodes[ConsoleColorCodes["YellowBackground"] = 43] = "YellowBackground";
ConsoleColorCodes[ConsoleColorCodes["BlueBackground"] = 44] = "BlueBackground";
ConsoleColorCodes[ConsoleColorCodes["MagentaBackground"] = 45] = "MagentaBackground";
ConsoleColorCodes[ConsoleColorCodes["CyanBackground"] = 46] = "CyanBackground";
ConsoleColorCodes[ConsoleColorCodes["WhiteBackground"] = 47] = "WhiteBackground";
ConsoleColorCodes[ConsoleColorCodes["GrayBackground"] = 100] = "GrayBackground";
ConsoleColorCodes[ConsoleColorCodes["DefaultBackground"] = 49] = "DefaultBackground";
ConsoleColorCodes[ConsoleColorCodes["Bold"] = 1] = "Bold";
// On Linux, the "BoldOff" code instead causes the text to be double-underlined:
// https://en.wikipedia.org/wiki/Talk:ANSI_escape_code#SGR_21%E2%80%94%60Bold_off%60_not_widely_supported
// Use "NormalColorOrIntensity" instead
// BoldOff = 21,
ConsoleColorCodes[ConsoleColorCodes["Dim"] = 2] = "Dim";
ConsoleColorCodes[ConsoleColorCodes["NormalColorOrIntensity"] = 22] = "NormalColorOrIntensity";
ConsoleColorCodes[ConsoleColorCodes["Underline"] = 4] = "Underline";
ConsoleColorCodes[ConsoleColorCodes["UnderlineOff"] = 24] = "UnderlineOff";
ConsoleColorCodes[ConsoleColorCodes["Blink"] = 5] = "Blink";
ConsoleColorCodes[ConsoleColorCodes["BlinkOff"] = 25] = "BlinkOff";
ConsoleColorCodes[ConsoleColorCodes["InvertColor"] = 7] = "InvertColor";
ConsoleColorCodes[ConsoleColorCodes["InvertColorOff"] = 27] = "InvertColorOff";
ConsoleColorCodes[ConsoleColorCodes["Hidden"] = 8] = "Hidden";
ConsoleColorCodes[ConsoleColorCodes["HiddenOff"] = 28] = "HiddenOff";
})(ConsoleColorCodes = exports.ConsoleColorCodes || (exports.ConsoleColorCodes = {}));
/**
* The static functions on this class are used to produce colored text
* for use with the node-core-library terminal.
*
* @example
* terminal.writeLine(Colors.green('Green Text!'), ' ', Colors.blue('Blue Text!'));
*
* @beta
*/
class Colors {
static black(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Black });
}
static red(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Red });
}
static green(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Green });
}
static yellow(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Yellow });
}
static blue(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Blue });
}
static magenta(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Magenta });
}
static cyan(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Cyan });
}
static white(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.White });
}
static gray(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { foregroundColor: ColorValue.Gray });
}
static blackBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Black });
}
static redBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Red });
}
static greenBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Green });
}
static yellowBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Yellow });
}
static blueBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Blue });
}
static magentaBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Magenta });
}
static cyanBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Cyan });
}
static whiteBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.White });
}
static grayBackground(text) {
return Object.assign(Object.assign({}, Colors._normalizeStringOrColorableSequence(text)), { backgroundColor: ColorValue.Gray });
}
static bold(text) {
return Colors._applyTextAttribute(text, TextAttribute.Bold);
}
static dim(text) {
return Colors._applyTextAttribute(text, TextAttribute.Dim);
}
static underline(text) {
return Colors._applyTextAttribute(text, TextAttribute.Underline);
}
static blink(text) {
return Colors._applyTextAttribute(text, TextAttribute.Blink);
}
static invertColor(text) {
return Colors._applyTextAttribute(text, TextAttribute.InvertColor);
}
static hidden(text) {
return Colors._applyTextAttribute(text, TextAttribute.Hidden);
}
/**
* If called with a string, returns the string wrapped in a {@link IColorableSequence}.
* If called with a {@link IColorableSequence}, returns the {@link IColorableSequence}.
*
* @internal
*/
static _normalizeStringOrColorableSequence(value) {
if (typeof value === 'string') {
return {
text: value
};
}
else {
return value;
}
}
static _applyTextAttribute(text, attribute) {
const sequence = Colors._normalizeStringOrColorableSequence(text);
if (!sequence.textAttributes) {
sequence.textAttributes = [];
}
sequence.textAttributes.push(attribute);
return sequence;
}
}
exports.Colors = Colors;
//# sourceMappingURL=Colors.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,48 @@
import { type ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';
/**
* Options to be provided to a {@link ConsoleTerminalProvider}
*
* @beta
*/
export interface IConsoleTerminalProviderOptions {
/**
* If true, print verbose logging messages.
*/
verboseEnabled: boolean;
/**
* If true, print debug logging messages. Note that "verbose" and "debug" are considered
* separate message filters; if you want debug to imply verbose, it is up to your
* application code to enforce that.
*/
debugEnabled: boolean;
}
/**
* Terminal provider that prints to STDOUT (for log- and verbose-level messages) and
* STDERR (for warning- and error-level messsages).
*
* @beta
*/
export declare class ConsoleTerminalProvider implements ITerminalProvider {
/**
* If true, verbose-level messages should be written to the console.
*/
verboseEnabled: boolean;
/**
* If true, debug-level messages should be written to the console.
*/
debugEnabled: boolean;
constructor(options?: Partial<IConsoleTerminalProviderOptions>);
/**
* {@inheritDoc ITerminalProvider.write}
*/
write(data: string, severity: TerminalProviderSeverity): void;
/**
* {@inheritDoc ITerminalProvider.eolCharacter}
*/
get eolCharacter(): string;
/**
* {@inheritDoc ITerminalProvider.supportsColor}
*/
get supportsColor(): boolean;
}
//# sourceMappingURL=ConsoleTerminalProvider.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ConsoleTerminalProvider.d.ts","sourceRoot":"","sources":["../../src/Terminal/ConsoleTerminalProvider.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEvF;;;;GAIG;AACH,MAAM,WAAW,+BAA+B;IAC9C;;OAEG;IACH,cAAc,EAAE,OAAO,CAAC;IAExB;;;;OAIG;IACH,YAAY,EAAE,OAAO,CAAC;CACvB;AAED;;;;;GAKG;AACH,qBAAa,uBAAwB,YAAW,iBAAiB;IAC/D;;OAEG;IACI,cAAc,EAAE,OAAO,CAAS;IAEvC;;OAEG;IACI,YAAY,EAAE,OAAO,CAAS;gBAElB,OAAO,GAAE,OAAO,CAAC,+BAA+B,CAAM;IAKzE;;OAEG;IACI,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IA8BpE;;OAEG;IACH,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAElC;CACF"}

View File

@ -0,0 +1,71 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConsoleTerminalProvider = void 0;
const os_1 = require("os");
const safe_1 = require("colors/safe");
const ITerminalProvider_1 = require("./ITerminalProvider");
/**
* Terminal provider that prints to STDOUT (for log- and verbose-level messages) and
* STDERR (for warning- and error-level messsages).
*
* @beta
*/
class ConsoleTerminalProvider {
constructor(options = {}) {
/**
* If true, verbose-level messages should be written to the console.
*/
this.verboseEnabled = false;
/**
* If true, debug-level messages should be written to the console.
*/
this.debugEnabled = false;
this.verboseEnabled = !!options.verboseEnabled;
this.debugEnabled = !!options.debugEnabled;
}
/**
* {@inheritDoc ITerminalProvider.write}
*/
write(data, severity) {
switch (severity) {
case ITerminalProvider_1.TerminalProviderSeverity.warning:
case ITerminalProvider_1.TerminalProviderSeverity.error: {
process.stderr.write(data);
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.verbose: {
if (this.verboseEnabled) {
process.stdout.write(data);
}
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.debug: {
if (this.debugEnabled) {
process.stdout.write(data);
}
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.log:
default: {
process.stdout.write(data);
break;
}
}
}
/**
* {@inheritDoc ITerminalProvider.eolCharacter}
*/
get eolCharacter() {
return os_1.EOL;
}
/**
* {@inheritDoc ITerminalProvider.supportsColor}
*/
get supportsColor() {
return safe_1.enabled;
}
}
exports.ConsoleTerminalProvider = ConsoleTerminalProvider;
//# sourceMappingURL=ConsoleTerminalProvider.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ConsoleTerminalProvider.js","sourceRoot":"","sources":["../../src/Terminal/ConsoleTerminalProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,2BAAyB;AACzB,sCAAuD;AAEvD,2DAAuF;AAqBvF;;;;;GAKG;AACH,MAAa,uBAAuB;IAWlC,YAAmB,UAAoD,EAAE;QAVzE;;WAEG;QACI,mBAAc,GAAY,KAAK,CAAC;QAEvC;;WAEG;QACI,iBAAY,GAAY,KAAK,CAAC;QAGnC,IAAI,CAAC,cAAc,GAAG,CAAC,CAAC,OAAO,CAAC,cAAc,CAAC;QAC/C,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAY,EAAE,QAAkC;QAC3D,QAAQ,QAAQ,EAAE;YAChB,KAAK,4CAAwB,CAAC,OAAO,CAAC;YACtC,KAAK,4CAAwB,CAAC,KAAK,CAAC,CAAC;gBACnC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM;aACP;YAED,KAAK,4CAAwB,CAAC,OAAO,CAAC,CAAC;gBACrC,IAAI,IAAI,CAAC,cAAc,EAAE;oBACvB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;iBAC5B;gBACD,MAAM;aACP;YAED,KAAK,4CAAwB,CAAC,KAAK,CAAC,CAAC;gBACnC,IAAI,IAAI,CAAC,YAAY,EAAE;oBACrB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;iBAC5B;gBACD,MAAM;aACP;YAED,KAAK,4CAAwB,CAAC,GAAG,CAAC;YAClC,OAAO,CAAC,CAAC;gBACP,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;gBAC3B,MAAM;aACP;SACF;IACH,CAAC;IAED;;OAEG;IACH,IAAW,YAAY;QACrB,OAAO,QAAG,CAAC;IACb,CAAC;IAED;;OAEG;IACH,IAAW,aAAa;QACtB,OAAO,cAAa,CAAC;IACvB,CAAC;CACF;AA9DD,0DA8DC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport { EOL } from 'os';\nimport { enabled as supportsColor } from 'colors/safe';\n\nimport { type ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';\n\n/**\n * Options to be provided to a {@link ConsoleTerminalProvider}\n *\n * @beta\n */\nexport interface IConsoleTerminalProviderOptions {\n /**\n * If true, print verbose logging messages.\n */\n verboseEnabled: boolean;\n\n /**\n * If true, print debug logging messages. Note that \"verbose\" and \"debug\" are considered\n * separate message filters; if you want debug to imply verbose, it is up to your\n * application code to enforce that.\n */\n debugEnabled: boolean;\n}\n\n/**\n * Terminal provider that prints to STDOUT (for log- and verbose-level messages) and\n * STDERR (for warning- and error-level messsages).\n *\n * @beta\n */\nexport class ConsoleTerminalProvider implements ITerminalProvider {\n /**\n * If true, verbose-level messages should be written to the console.\n */\n public verboseEnabled: boolean = false;\n\n /**\n * If true, debug-level messages should be written to the console.\n */\n public debugEnabled: boolean = false;\n\n public constructor(options: Partial<IConsoleTerminalProviderOptions> = {}) {\n this.verboseEnabled = !!options.verboseEnabled;\n this.debugEnabled = !!options.debugEnabled;\n }\n\n /**\n * {@inheritDoc ITerminalProvider.write}\n */\n public write(data: string, severity: TerminalProviderSeverity): void {\n switch (severity) {\n case TerminalProviderSeverity.warning:\n case TerminalProviderSeverity.error: {\n process.stderr.write(data);\n break;\n }\n\n case TerminalProviderSeverity.verbose: {\n if (this.verboseEnabled) {\n process.stdout.write(data);\n }\n break;\n }\n\n case TerminalProviderSeverity.debug: {\n if (this.debugEnabled) {\n process.stdout.write(data);\n }\n break;\n }\n\n case TerminalProviderSeverity.log:\n default: {\n process.stdout.write(data);\n break;\n }\n }\n }\n\n /**\n * {@inheritDoc ITerminalProvider.eolCharacter}\n */\n public get eolCharacter(): string {\n return EOL;\n }\n\n /**\n * {@inheritDoc ITerminalProvider.supportsColor}\n */\n public get supportsColor(): boolean {\n return supportsColor;\n }\n}\n"]}

View File

@ -0,0 +1,68 @@
import type { ITerminalProvider } from './ITerminalProvider';
import type { IColorableSequence } from './Colors';
/**
* @beta
*/
export interface ITerminal {
/**
* Subscribe a new terminal provider.
*/
registerProvider(provider: ITerminalProvider): void;
/**
* Unsubscribe a terminal provider. If the provider isn't subscribed, this function does nothing.
*/
unregisterProvider(provider: ITerminalProvider): void;
/**
* Write a generic message to the terminal
*/
write(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a generic message to the terminal, followed by a newline
*/
writeLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a warning message to the console with yellow text.
*
* @remarks
* The yellow color takes precedence over any other foreground colors set.
*/
writeWarning(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a warning message to the console with yellow text, followed by a newline.
*
* @remarks
* The yellow color takes precedence over any other foreground colors set.
*/
writeWarningLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write an error message to the console with red text.
*
* @remarks
* The red color takes precedence over any other foreground colors set.
*/
writeError(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write an error message to the console with red text, followed by a newline.
*
* @remarks
* The red color takes precedence over any other foreground colors set.
*/
writeErrorLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a verbose-level message.
*/
writeVerbose(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a verbose-level message followed by a newline.
*/
writeVerboseLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a debug-level message.
*/
writeDebug(...messageParts: (string | IColorableSequence)[]): void;
/**
* Write a debug-level message followed by a newline.
*/
writeDebugLine(...messageParts: (string | IColorableSequence)[]): void;
}
//# sourceMappingURL=ITerminal.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ITerminal.d.ts","sourceRoot":"","sources":["../../src/Terminal/ITerminal.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,SAAS;IACxB;;OAEG;IACH,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAEpD;;OAEG;IACH,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAC;IAEtD;;OAEG;IACH,KAAK,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAE9D;;OAEG;IACH,SAAS,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAElE;;;;;OAKG;IACH,YAAY,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAErE;;;;;OAKG;IACH,gBAAgB,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAEzE;;;;;OAKG;IACH,UAAU,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAEnE;;;;;OAKG;IACH,cAAc,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAEvE;;OAEG;IACH,YAAY,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAErE;;OAEG;IACH,gBAAgB,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAEzE;;OAEG;IACH,UAAU,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;IAEnE;;OAEG;IACH,cAAc,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI,CAAC;CACxE"}

View File

@ -0,0 +1,5 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=ITerminal.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ITerminal.js","sourceRoot":"","sources":["../../src/Terminal/ITerminal.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ITerminalProvider } from './ITerminalProvider';\nimport type { IColorableSequence } from './Colors';\n\n/**\n * @beta\n */\nexport interface ITerminal {\n /**\n * Subscribe a new terminal provider.\n */\n registerProvider(provider: ITerminalProvider): void;\n\n /**\n * Unsubscribe a terminal provider. If the provider isn't subscribed, this function does nothing.\n */\n unregisterProvider(provider: ITerminalProvider): void;\n\n /**\n * Write a generic message to the terminal\n */\n write(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a generic message to the terminal, followed by a newline\n */\n writeLine(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a warning message to the console with yellow text.\n *\n * @remarks\n * The yellow color takes precedence over any other foreground colors set.\n */\n writeWarning(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a warning message to the console with yellow text, followed by a newline.\n *\n * @remarks\n * The yellow color takes precedence over any other foreground colors set.\n */\n writeWarningLine(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write an error message to the console with red text.\n *\n * @remarks\n * The red color takes precedence over any other foreground colors set.\n */\n writeError(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write an error message to the console with red text, followed by a newline.\n *\n * @remarks\n * The red color takes precedence over any other foreground colors set.\n */\n writeErrorLine(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a verbose-level message.\n */\n writeVerbose(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a verbose-level message followed by a newline.\n */\n writeVerboseLine(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a debug-level message.\n */\n writeDebug(...messageParts: (string | IColorableSequence)[]): void;\n\n /**\n * Write a debug-level message followed by a newline.\n */\n writeDebugLine(...messageParts: (string | IColorableSequence)[]): void;\n}\n"]}

View File

@ -0,0 +1,54 @@
/**
* Similar to many popular logging packages, terminal providers support a range of message
* severities. These severities have built-in formatting defaults in the Terminal object
* (warnings are yellow, errors are red, etc.).
*
* Terminal providers may choose to suppress certain messages based on their severity,
* or to route some messages to other providers or not based on severity.
*
* Severity | Purpose
* --------- | -------
* error | Build errors and fatal issues
* warning | Not necessarily fatal, but indicate a problem the user should fix
* log | Informational messages
* verbose | Additional information that may not always be necessary
* debug | Highest detail level, best used for troubleshooting information
*
* @beta
*/
export declare enum TerminalProviderSeverity {
log = 0,
warning = 1,
error = 2,
verbose = 3,
debug = 4
}
/**
* Implement the interface to create a terminal provider. Terminal providers
* can be registered to a {@link Terminal} instance to receive messages.
*
* @beta
*/
export interface ITerminalProvider {
/**
* This property should return true only if the terminal provider supports
* rendering console colors.
*/
supportsColor: boolean;
/**
* This property should return the newline character the terminal provider
* expects.
*/
eolCharacter: string;
/**
* This function gets called on every terminal provider upon every
* message function call on the terminal instance.
*
* @param data - The terminal message.
* @param severity - The message severity. Terminal providers can
* route different kinds of messages to different streams and may choose
* to ignore verbose or debug messages.
*/
write(data: string, severity: TerminalProviderSeverity): void;
}
//# sourceMappingURL=ITerminalProvider.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ITerminalProvider.d.ts","sourceRoot":"","sources":["../../src/Terminal/ITerminalProvider.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,oBAAY,wBAAwB;IAClC,GAAG,IAAA;IACH,OAAO,IAAA;IACP,KAAK,IAAA;IACL,OAAO,IAAA;IACP,KAAK,IAAA;CACN;AAED;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,aAAa,EAAE,OAAO,CAAC;IAEvB;;;OAGG;IACH,YAAY,EAAE,MAAM,CAAC;IAErB;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI,CAAC;CAC/D"}

View File

@ -0,0 +1,32 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TerminalProviderSeverity = void 0;
/**
* Similar to many popular logging packages, terminal providers support a range of message
* severities. These severities have built-in formatting defaults in the Terminal object
* (warnings are yellow, errors are red, etc.).
*
* Terminal providers may choose to suppress certain messages based on their severity,
* or to route some messages to other providers or not based on severity.
*
* Severity | Purpose
* --------- | -------
* error | Build errors and fatal issues
* warning | Not necessarily fatal, but indicate a problem the user should fix
* log | Informational messages
* verbose | Additional information that may not always be necessary
* debug | Highest detail level, best used for troubleshooting information
*
* @beta
*/
var TerminalProviderSeverity;
(function (TerminalProviderSeverity) {
TerminalProviderSeverity[TerminalProviderSeverity["log"] = 0] = "log";
TerminalProviderSeverity[TerminalProviderSeverity["warning"] = 1] = "warning";
TerminalProviderSeverity[TerminalProviderSeverity["error"] = 2] = "error";
TerminalProviderSeverity[TerminalProviderSeverity["verbose"] = 3] = "verbose";
TerminalProviderSeverity[TerminalProviderSeverity["debug"] = 4] = "debug";
})(TerminalProviderSeverity = exports.TerminalProviderSeverity || (exports.TerminalProviderSeverity = {}));
//# sourceMappingURL=ITerminalProvider.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"ITerminalProvider.js","sourceRoot":"","sources":["../../src/Terminal/ITerminalProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,IAAY,wBAMX;AAND,WAAY,wBAAwB;IAClC,qEAAG,CAAA;IACH,6EAAO,CAAA;IACP,yEAAK,CAAA;IACL,6EAAO,CAAA;IACP,yEAAK,CAAA;AACP,CAAC,EANW,wBAAwB,GAAxB,gCAAwB,KAAxB,gCAAwB,QAMnC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\n/**\n * Similar to many popular logging packages, terminal providers support a range of message\n * severities. These severities have built-in formatting defaults in the Terminal object\n * (warnings are yellow, errors are red, etc.).\n *\n * Terminal providers may choose to suppress certain messages based on their severity,\n * or to route some messages to other providers or not based on severity.\n *\n * Severity | Purpose\n * --------- | -------\n * error | Build errors and fatal issues\n * warning | Not necessarily fatal, but indicate a problem the user should fix\n * log | Informational messages\n * verbose | Additional information that may not always be necessary\n * debug | Highest detail level, best used for troubleshooting information\n *\n * @beta\n */\nexport enum TerminalProviderSeverity {\n log,\n warning,\n error,\n verbose,\n debug\n}\n\n/**\n * Implement the interface to create a terminal provider. Terminal providers\n * can be registered to a {@link Terminal} instance to receive messages.\n *\n * @beta\n */\nexport interface ITerminalProvider {\n /**\n * This property should return true only if the terminal provider supports\n * rendering console colors.\n */\n supportsColor: boolean;\n\n /**\n * This property should return the newline character the terminal provider\n * expects.\n */\n eolCharacter: string;\n\n /**\n * This function gets called on every terminal provider upon every\n * message function call on the terminal instance.\n *\n * @param data - The terminal message.\n * @param severity - The message severity. Terminal providers can\n * route different kinds of messages to different streams and may choose\n * to ignore verbose or debug messages.\n */\n write(data: string, severity: TerminalProviderSeverity): void;\n}\n"]}

View File

@ -0,0 +1,57 @@
import type { ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';
/**
* @beta
*/
export interface IPrefixProxyTerminalProviderOptionsBase {
/**
* The {@link ITerminalProvider} that will be wrapped.
*/
terminalProvider: ITerminalProvider;
}
/**
* Options for {@link PrefixProxyTerminalProvider}, with a static prefix.
*
* @beta
*/
export interface IStaticPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {
/**
* The prefix that should be added to each line of output.
*/
prefix: string;
}
/**
* Options for {@link PrefixProxyTerminalProvider}.
*
* @beta
*/
export interface IDynamicPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {
/**
* A function that returns the prefix that should be added to each line of output. This is useful
* for prefixing each line with a timestamp.
*/
getPrefix: () => string;
}
/**
* @beta
*/
export type IPrefixProxyTerminalProviderOptions = IStaticPrefixProxyTerminalProviderOptions | IDynamicPrefixProxyTerminalProviderOptions;
/**
* Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified
* prefix string.
*
* @beta
*/
export declare class PrefixProxyTerminalProvider implements ITerminalProvider {
private readonly _parentTerminalProvider;
private readonly _getPrefix;
private readonly _newlineRegex;
private _isOnNewline;
constructor(options: IPrefixProxyTerminalProviderOptions);
/** @override */
get supportsColor(): boolean;
/** @override */
get eolCharacter(): string;
/** @override */
write(data: string, severity: TerminalProviderSeverity): void;
}
//# sourceMappingURL=PrefixProxyTerminalProvider.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"PrefixProxyTerminalProvider.d.ts","sourceRoot":"","sources":["../../src/Terminal/PrefixProxyTerminalProvider.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAGvF;;GAEG;AACH,MAAM,WAAW,uCAAuC;IACtD;;OAEG;IACH,gBAAgB,EAAE,iBAAiB,CAAC;CACrC;AAED;;;;GAIG;AACH,MAAM,WAAW,yCAA0C,SAAQ,uCAAuC;IACxG;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;;;GAIG;AACH,MAAM,WAAW,0CAA2C,SAAQ,uCAAuC;IACzG;;;OAGG;IACH,SAAS,EAAE,MAAM,MAAM,CAAC;CACzB;AAED;;GAEG;AACH,MAAM,MAAM,mCAAmC,GAC3C,yCAAyC,GACzC,0CAA0C,CAAC;AAE/C;;;;;GAKG;AACH,qBAAa,2BAA4B,YAAW,iBAAiB;IACnE,OAAO,CAAC,QAAQ,CAAC,uBAAuB,CAAoB;IAC5D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAS;IACvC,OAAO,CAAC,YAAY,CAAU;gBAEX,OAAO,EAAE,mCAAmC;IAmB/D,gBAAgB;IAChB,IAAW,aAAa,IAAI,OAAO,CAElC;IAED,gBAAgB;IAChB,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED,gBAAgB;IACT,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI;CA0BrE"}

View File

@ -0,0 +1,64 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.PrefixProxyTerminalProvider = void 0;
const Text_1 = require("../Text");
/**
* Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified
* prefix string.
*
* @beta
*/
class PrefixProxyTerminalProvider {
constructor(options) {
const { terminalProvider } = options;
this._parentTerminalProvider = terminalProvider;
if (options.prefix !== undefined) {
const { prefix } = options;
this._getPrefix = () => prefix;
}
else {
const { getPrefix } = options;
this._getPrefix = getPrefix;
}
this._isOnNewline = true;
// eslint-disable-next-line @rushstack/security/no-unsafe-regexp
this._newlineRegex = new RegExp(`${Text_1.Text.escapeRegExp(terminalProvider.eolCharacter)}|\\n`, 'g');
}
/** @override */
get supportsColor() {
return this._parentTerminalProvider.supportsColor;
}
/** @override */
get eolCharacter() {
return this._parentTerminalProvider.eolCharacter;
}
/** @override */
write(data, severity) {
// We need to track newlines to ensure that the prefix is added to each line
let currentIndex = 0;
// eslint-disable-next-line @rushstack/no-new-null
let newlineMatch;
while ((newlineMatch = this._newlineRegex.exec(data))) {
// Extract the line, add the prefix, and write it out with the newline
const newlineIndex = newlineMatch.index;
const newIndex = newlineIndex + newlineMatch[0].length;
const prefix = this._isOnNewline ? this._getPrefix() : '';
const dataToWrite = `${prefix}${data.substring(currentIndex, newIndex)}`;
this._parentTerminalProvider.write(dataToWrite, severity);
// Update the currentIndex to start the search from the char after the newline
currentIndex = newIndex;
this._isOnNewline = true;
}
// The remaining data is not postfixed by a newline, so write out the data and set _isNewline to false
const remainingData = data.substring(currentIndex);
if (remainingData.length) {
const prefix = this._isOnNewline ? this._getPrefix() : '';
this._parentTerminalProvider.write(`${prefix}${remainingData}`, severity);
this._isOnNewline = false;
}
}
}
exports.PrefixProxyTerminalProvider = PrefixProxyTerminalProvider;
//# sourceMappingURL=PrefixProxyTerminalProvider.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,63 @@
import { type ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';
/**
* @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;
}
/**
* Terminal provider that stores written data in buffers separated by severity.
* This terminal provider is designed to be used when code that prints to a terminal
* is being unit tested.
*
* @beta
*/
export declare class StringBufferTerminalProvider implements ITerminalProvider {
private _standardBuffer;
private _verboseBuffer;
private _debugBuffer;
private _warningBuffer;
private _errorBuffer;
private _supportsColor;
constructor(supportsColor?: boolean);
/**
* {@inheritDoc ITerminalProvider.write}
*/
write(data: string, severity: TerminalProviderSeverity): void;
/**
* {@inheritDoc ITerminalProvider.eolCharacter}
*/
get eolCharacter(): string;
/**
* {@inheritDoc ITerminalProvider.supportsColor}
*/
get supportsColor(): boolean;
/**
* Get everything that has been written at log-level severity.
*/
getOutput(options?: IStringBufferOutputOptions): string;
/**
* Get everything that has been written at verbose-level severity.
*/
getVerbose(options?: IStringBufferOutputOptions): string;
/**
* Get everything that has been written at debug-level severity.
*/
getDebugOutput(options?: IStringBufferOutputOptions): string;
/**
* Get everything that has been written at error-level severity.
*/
getErrorOutput(options?: IStringBufferOutputOptions): string;
/**
* Get everything that has been written at warning-level severity.
*/
getWarningOutput(options?: IStringBufferOutputOptions): string;
private _normalizeOutput;
}
//# sourceMappingURL=StringBufferTerminalProvider.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"StringBufferTerminalProvider.d.ts","sourceRoot":"","sources":["../../src/Terminal/StringBufferTerminalProvider.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAKvF;;GAEG;AACH,MAAM,WAAW,0BAA0B;IACzC;;;;;OAKG;IACH,0BAA0B,EAAE,OAAO,CAAC;CACrC;AAED;;;;;;GAMG;AACH,qBAAa,4BAA6B,YAAW,iBAAiB;IACpE,OAAO,CAAC,eAAe,CAAsC;IAC7D,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,YAAY,CAAsC;IAC1D,OAAO,CAAC,cAAc,CAAsC;IAC5D,OAAO,CAAC,YAAY,CAAsC;IAE1D,OAAO,CAAC,cAAc,CAAU;gBAEb,aAAa,GAAE,OAAe;IAIjD;;OAEG;IACI,KAAK,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,wBAAwB,GAAG,IAAI;IA8BpE;;OAEG;IACH,IAAW,YAAY,IAAI,MAAM,CAEhC;IAED;;OAEG;IACH,IAAW,aAAa,IAAI,OAAO,CAElC;IAED;;OAEG;IACI,SAAS,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM;IAI9D;;OAEG;IACI,UAAU,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM;IAI/D;;OAEG;IACI,cAAc,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM;IAInE;;OAEG;IACI,cAAc,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM;IAInE;;OAEG;IACI,gBAAgB,CAAC,OAAO,CAAC,EAAE,0BAA0B,GAAG,MAAM;IAIrE,OAAO,CAAC,gBAAgB;CAezB"}

View File

@ -0,0 +1,108 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.StringBufferTerminalProvider = void 0;
const ITerminalProvider_1 = require("./ITerminalProvider");
const StringBuilder_1 = require("../StringBuilder");
const Text_1 = require("../Text");
const AnsiEscape_1 = require("./AnsiEscape");
/**
* Terminal provider that stores written data in buffers separated by severity.
* This terminal provider is designed to be used when code that prints to a terminal
* is being unit tested.
*
* @beta
*/
class StringBufferTerminalProvider {
constructor(supportsColor = false) {
this._standardBuffer = new StringBuilder_1.StringBuilder();
this._verboseBuffer = new StringBuilder_1.StringBuilder();
this._debugBuffer = new StringBuilder_1.StringBuilder();
this._warningBuffer = new StringBuilder_1.StringBuilder();
this._errorBuffer = new StringBuilder_1.StringBuilder();
this._supportsColor = supportsColor;
}
/**
* {@inheritDoc ITerminalProvider.write}
*/
write(data, severity) {
switch (severity) {
case ITerminalProvider_1.TerminalProviderSeverity.warning: {
this._warningBuffer.append(data);
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.error: {
this._errorBuffer.append(data);
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.verbose: {
this._verboseBuffer.append(data);
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.debug: {
this._debugBuffer.append(data);
break;
}
case ITerminalProvider_1.TerminalProviderSeverity.log:
default: {
this._standardBuffer.append(data);
break;
}
}
}
/**
* {@inheritDoc ITerminalProvider.eolCharacter}
*/
get eolCharacter() {
return '[n]';
}
/**
* {@inheritDoc ITerminalProvider.supportsColor}
*/
get supportsColor() {
return this._supportsColor;
}
/**
* Get everything that has been written at log-level severity.
*/
getOutput(options) {
return this._normalizeOutput(this._standardBuffer.toString(), options);
}
/**
* Get everything that has been written at verbose-level severity.
*/
getVerbose(options) {
return this._normalizeOutput(this._verboseBuffer.toString(), options);
}
/**
* Get everything that has been written at debug-level severity.
*/
getDebugOutput(options) {
return this._normalizeOutput(this._debugBuffer.toString(), options);
}
/**
* Get everything that has been written at error-level severity.
*/
getErrorOutput(options) {
return this._normalizeOutput(this._errorBuffer.toString(), options);
}
/**
* Get everything that has been written at warning-level severity.
*/
getWarningOutput(options) {
return this._normalizeOutput(this._warningBuffer.toString(), options);
}
_normalizeOutput(s, options) {
options = Object.assign({ normalizeSpecialCharacters: true }, (options || {}));
s = Text_1.Text.convertToLf(s);
if (options.normalizeSpecialCharacters) {
return AnsiEscape_1.AnsiEscape.formatForTests(s, { encodeNewlines: true });
}
else {
return s;
}
}
}
exports.StringBufferTerminalProvider = StringBufferTerminalProvider;
//# sourceMappingURL=StringBufferTerminalProvider.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,63 @@
import { type ITerminalProvider } from './ITerminalProvider';
import { type IColorableSequence } from './Colors';
import type { ITerminal } from './ITerminal';
/**
* This class facilitates writing to a console.
*
* @beta
*/
export declare class Terminal implements ITerminal {
private _providers;
constructor(provider: ITerminalProvider);
/**
* {@inheritdoc ITerminal.registerProvider}
*/
registerProvider(provider: ITerminalProvider): void;
/**
* {@inheritdoc ITerminal.unregisterProvider}
*/
unregisterProvider(provider: ITerminalProvider): void;
/**
* {@inheritdoc ITerminal.write}
*/
write(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeLine}
*/
writeLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeWarning}
*/
writeWarning(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeWarningLine}
*/
writeWarningLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeError}
*/
writeError(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeErrorLine}
*/
writeErrorLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeVerbose}
*/
writeVerbose(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeVerboseLine}
*/
writeVerboseLine(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeDebug}
*/
writeDebug(...messageParts: (string | IColorableSequence)[]): void;
/**
* {@inheritdoc ITerminal.writeDebugLine}
*/
writeDebugLine(...messageParts: (string | IColorableSequence)[]): void;
private _writeSegmentsToProviders;
private _serializeFormattableTextSegments;
}
//# sourceMappingURL=Terminal.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"Terminal.d.ts","sourceRoot":"","sources":["../../src/Terminal/Terminal.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,KAAK,iBAAiB,EAA4B,MAAM,qBAAqB,CAAC;AACvF,OAAO,EACL,KAAK,kBAAkB,EAMxB,MAAM,UAAU,CAAC;AAClB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;;;GAIG;AACH,qBAAa,QAAS,YAAW,SAAS;IACxC,OAAO,CAAC,UAAU,CAAyB;gBAExB,QAAQ,EAAE,iBAAiB;IAK9C;;OAEG;IACI,gBAAgB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAI1D;;OAEG;IACI,kBAAkB,CAAC,QAAQ,EAAE,iBAAiB,GAAG,IAAI;IAM5D;;OAEG;IACI,KAAK,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAIpE;;OAEG;IACI,SAAS,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAIxE;;OAEG;IACI,YAAY,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAY3E;;OAEG;IACI,gBAAgB,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAe/E;;OAEG;IACI,UAAU,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAYzE;;OAEG;IACI,cAAc,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAe7E;;OAEG;IACI,YAAY,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAI3E;;OAEG;IACI,gBAAgB,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAI/E;;OAEG;IACI,UAAU,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAIzE;;OAEG;IACI,cAAc,CAAC,GAAG,YAAY,EAAE,CAAC,MAAM,GAAG,kBAAkB,CAAC,EAAE,GAAG,IAAI;IAI7E,OAAO,CAAC,yBAAyB;IAsCjC,OAAO,CAAC,iCAAiC;CAsM1C"}

View File

@ -0,0 +1,297 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.Terminal = void 0;
const ITerminalProvider_1 = require("./ITerminalProvider");
const Colors_1 = require("./Colors");
/**
* This class facilitates writing to a console.
*
* @beta
*/
class Terminal {
constructor(provider) {
this._providers = new Set();
this._providers.add(provider);
}
/**
* {@inheritdoc ITerminal.registerProvider}
*/
registerProvider(provider) {
this._providers.add(provider);
}
/**
* {@inheritdoc ITerminal.unregisterProvider}
*/
unregisterProvider(provider) {
if (this._providers.has(provider)) {
this._providers.delete(provider);
}
}
/**
* {@inheritdoc ITerminal.write}
*/
write(...messageParts) {
this._writeSegmentsToProviders(messageParts, ITerminalProvider_1.TerminalProviderSeverity.log);
}
/**
* {@inheritdoc ITerminal.writeLine}
*/
writeLine(...messageParts) {
this.write(...messageParts, Colors_1.eolSequence);
}
/**
* {@inheritdoc ITerminal.writeWarning}
*/
writeWarning(...messageParts) {
this._writeSegmentsToProviders(messageParts.map((part) => (Object.assign(Object.assign({}, Colors_1.Colors._normalizeStringOrColorableSequence(part)), { foregroundColor: Colors_1.ColorValue.Yellow }))), ITerminalProvider_1.TerminalProviderSeverity.warning);
}
/**
* {@inheritdoc ITerminal.writeWarningLine}
*/
writeWarningLine(...messageParts) {
this._writeSegmentsToProviders([
...messageParts.map((part) => (Object.assign(Object.assign({}, Colors_1.Colors._normalizeStringOrColorableSequence(part)), { foregroundColor: Colors_1.ColorValue.Yellow }))),
Colors_1.eolSequence
], ITerminalProvider_1.TerminalProviderSeverity.warning);
}
/**
* {@inheritdoc ITerminal.writeError}
*/
writeError(...messageParts) {
this._writeSegmentsToProviders(messageParts.map((part) => (Object.assign(Object.assign({}, Colors_1.Colors._normalizeStringOrColorableSequence(part)), { foregroundColor: Colors_1.ColorValue.Red }))), ITerminalProvider_1.TerminalProviderSeverity.error);
}
/**
* {@inheritdoc ITerminal.writeErrorLine}
*/
writeErrorLine(...messageParts) {
this._writeSegmentsToProviders([
...messageParts.map((part) => (Object.assign(Object.assign({}, Colors_1.Colors._normalizeStringOrColorableSequence(part)), { foregroundColor: Colors_1.ColorValue.Red }))),
Colors_1.eolSequence
], ITerminalProvider_1.TerminalProviderSeverity.error);
}
/**
* {@inheritdoc ITerminal.writeVerbose}
*/
writeVerbose(...messageParts) {
this._writeSegmentsToProviders(messageParts, ITerminalProvider_1.TerminalProviderSeverity.verbose);
}
/**
* {@inheritdoc ITerminal.writeVerboseLine}
*/
writeVerboseLine(...messageParts) {
this.writeVerbose(...messageParts, Colors_1.eolSequence);
}
/**
* {@inheritdoc ITerminal.writeDebug}
*/
writeDebug(...messageParts) {
this._writeSegmentsToProviders(messageParts, ITerminalProvider_1.TerminalProviderSeverity.debug);
}
/**
* {@inheritdoc ITerminal.writeDebugLine}
*/
writeDebugLine(...messageParts) {
this.writeDebug(...messageParts, Colors_1.eolSequence);
}
_writeSegmentsToProviders(segments, severity) {
const withColorText = {};
const withoutColorText = {};
let withColorLines;
let withoutColorLines;
this._providers.forEach((provider) => {
const eol = provider.eolCharacter;
let textToWrite;
if (provider.supportsColor) {
if (!withColorLines) {
withColorLines = this._serializeFormattableTextSegments(segments, true);
}
if (!withColorText[eol]) {
withColorText[eol] = withColorLines.join(eol);
}
textToWrite = withColorText[eol];
}
else {
if (!withoutColorLines) {
withoutColorLines = this._serializeFormattableTextSegments(segments, false);
}
if (!withoutColorText[eol]) {
withoutColorText[eol] = withoutColorLines.join(eol);
}
textToWrite = withoutColorText[eol];
}
provider.write(textToWrite, severity);
});
}
_serializeFormattableTextSegments(segments, withColor) {
const lines = [];
let segmentsToJoin = [];
let lastSegmentWasEol = false;
for (let i = 0; i < segments.length; i++) {
const segment = Colors_1.Colors._normalizeStringOrColorableSequence(segments[i]);
lastSegmentWasEol = !!segment.isEol;
if (lastSegmentWasEol) {
lines.push(segmentsToJoin.join(''));
segmentsToJoin = [];
}
else {
if (withColor) {
const startColorCodes = [];
const endColorCodes = [];
switch (segment.foregroundColor) {
case Colors_1.ColorValue.Black: {
startColorCodes.push(Colors_1.ConsoleColorCodes.BlackForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Red: {
startColorCodes.push(Colors_1.ConsoleColorCodes.RedForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Green: {
startColorCodes.push(Colors_1.ConsoleColorCodes.GreenForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Yellow: {
startColorCodes.push(Colors_1.ConsoleColorCodes.YellowForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Blue: {
startColorCodes.push(Colors_1.ConsoleColorCodes.BlueForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Magenta: {
startColorCodes.push(Colors_1.ConsoleColorCodes.MagentaForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Cyan: {
startColorCodes.push(Colors_1.ConsoleColorCodes.CyanForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.White: {
startColorCodes.push(Colors_1.ConsoleColorCodes.WhiteForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
case Colors_1.ColorValue.Gray: {
startColorCodes.push(Colors_1.ConsoleColorCodes.GrayForeground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultForeground);
break;
}
}
switch (segment.backgroundColor) {
case Colors_1.ColorValue.Black: {
startColorCodes.push(Colors_1.ConsoleColorCodes.BlackBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Red: {
startColorCodes.push(Colors_1.ConsoleColorCodes.RedBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Green: {
startColorCodes.push(Colors_1.ConsoleColorCodes.GreenBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Yellow: {
startColorCodes.push(Colors_1.ConsoleColorCodes.YellowBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Blue: {
startColorCodes.push(Colors_1.ConsoleColorCodes.BlueBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Magenta: {
startColorCodes.push(Colors_1.ConsoleColorCodes.MagentaBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Cyan: {
startColorCodes.push(Colors_1.ConsoleColorCodes.CyanBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.White: {
startColorCodes.push(Colors_1.ConsoleColorCodes.WhiteBackground);
endColorCodes.push(Colors_1.ConsoleColorCodes.DefaultBackground);
break;
}
case Colors_1.ColorValue.Gray: {
startColorCodes.push(Colors_1.ConsoleColorCodes.GrayBackground);
endColorCodes.push(49);
break;
}
}
if (segment.textAttributes) {
for (const textAttribute of segment.textAttributes) {
switch (textAttribute) {
case Colors_1.TextAttribute.Bold: {
startColorCodes.push(Colors_1.ConsoleColorCodes.Bold);
endColorCodes.push(Colors_1.ConsoleColorCodes.NormalColorOrIntensity);
break;
}
case Colors_1.TextAttribute.Dim: {
startColorCodes.push(Colors_1.ConsoleColorCodes.Dim);
endColorCodes.push(Colors_1.ConsoleColorCodes.NormalColorOrIntensity);
break;
}
case Colors_1.TextAttribute.Underline: {
startColorCodes.push(Colors_1.ConsoleColorCodes.Underline);
endColorCodes.push(Colors_1.ConsoleColorCodes.UnderlineOff);
break;
}
case Colors_1.TextAttribute.Blink: {
startColorCodes.push(Colors_1.ConsoleColorCodes.Blink);
endColorCodes.push(Colors_1.ConsoleColorCodes.BlinkOff);
break;
}
case Colors_1.TextAttribute.InvertColor: {
startColorCodes.push(Colors_1.ConsoleColorCodes.InvertColor);
endColorCodes.push(Colors_1.ConsoleColorCodes.InvertColorOff);
break;
}
case Colors_1.TextAttribute.Hidden: {
startColorCodes.push(Colors_1.ConsoleColorCodes.Hidden);
endColorCodes.push(Colors_1.ConsoleColorCodes.HiddenOff);
break;
}
}
}
}
for (let j = 0; j < startColorCodes.length; j++) {
const code = startColorCodes[j];
segmentsToJoin.push(...['\u001b[', code.toString(), 'm']);
}
segmentsToJoin.push(segment.text);
for (let j = endColorCodes.length - 1; j >= 0; j--) {
const code = endColorCodes[j];
segmentsToJoin.push(...['\u001b[', code.toString(), 'm']);
}
}
else {
segmentsToJoin.push(segment.text);
}
}
}
if (segmentsToJoin.length > 0) {
lines.push(segmentsToJoin.join(''));
}
if (lastSegmentWasEol) {
lines.push('');
}
return lines;
}
}
exports.Terminal = Terminal;
//# sourceMappingURL=Terminal.js.map

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,35 @@
/// <reference types="node" />
/// <reference types="node" />
import type { ITerminal } from './ITerminal';
import { TerminalProviderSeverity } from './ITerminalProvider';
import { Writable, type WritableOptions } from 'stream';
/**
* Options for {@link TerminalWritable}.
*
* @beta
*/
export interface ITerminalWritableOptions {
/**
* The {@link ITerminal} that the Writable will write to.
*/
terminal: ITerminal;
/**
* The severity of the messages that will be written to the {@link ITerminal}.
*/
severity: TerminalProviderSeverity;
/**
* Options for the underlying Writable.
*/
writableOptions?: WritableOptions;
}
/**
* A adapter to allow writing to a provided terminal using Writable streams.
*
* @beta
*/
export declare class TerminalWritable extends Writable {
private _writeMethod;
constructor(options: ITerminalWritableOptions);
_write(chunk: string | Buffer | Uint8Array, encoding: string, callback: (error?: Error | null) => void): void;
}
//# sourceMappingURL=TerminalWritable.d.ts.map

View File

@ -0,0 +1 @@
{"version":3,"file":"TerminalWritable.d.ts","sourceRoot":"","sources":["../../src/Terminal/TerminalWritable.ts"],"names":[],"mappings":";;AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,KAAK,eAAe,EAAE,MAAM,QAAQ,CAAC;AAExD;;;;GAIG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IACpB;;OAEG;IACH,QAAQ,EAAE,wBAAwB,CAAC;IACnC;;OAEG;IACH,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC;AAED;;;;GAIG;AACH,qBAAa,gBAAiB,SAAQ,QAAQ;IAC5C,OAAO,CAAC,YAAY,CAAyB;gBAE1B,OAAO,EAAE,wBAAwB;IA0B7C,MAAM,CACX,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,EACnC,QAAQ,EAAE,MAAM,EAEhB,QAAQ,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI,KAAK,IAAI,GACvC,IAAI;CAUR"}

View File

@ -0,0 +1,53 @@
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TerminalWritable = void 0;
const ITerminalProvider_1 = require("./ITerminalProvider");
const stream_1 = require("stream");
/**
* A adapter to allow writing to a provided terminal using Writable streams.
*
* @beta
*/
class TerminalWritable extends stream_1.Writable {
constructor(options) {
const { terminal, severity, writableOptions } = options;
super(writableOptions);
this._writev = undefined;
switch (severity) {
case ITerminalProvider_1.TerminalProviderSeverity.log:
this._writeMethod = terminal.write.bind(terminal);
break;
case ITerminalProvider_1.TerminalProviderSeverity.verbose:
this._writeMethod = terminal.writeVerbose.bind(terminal);
break;
case ITerminalProvider_1.TerminalProviderSeverity.debug:
this._writeMethod = terminal.writeDebug.bind(terminal);
break;
case ITerminalProvider_1.TerminalProviderSeverity.warning:
this._writeMethod = terminal.writeWarning.bind(terminal);
break;
case ITerminalProvider_1.TerminalProviderSeverity.error:
this._writeMethod = terminal.writeError.bind(terminal);
break;
default:
throw new Error(`Unknown severity: ${severity}`);
}
}
_write(chunk, encoding,
// eslint-disable-next-line @rushstack/no-new-null
callback) {
try {
const chunkData = typeof chunk === 'string' ? chunk : Buffer.from(chunk);
this._writeMethod(chunkData.toString());
}
catch (e) {
callback(e);
return;
}
callback();
}
}
exports.TerminalWritable = TerminalWritable;
//# sourceMappingURL=TerminalWritable.js.map

View File

@ -0,0 +1 @@
{"version":3,"file":"TerminalWritable.js","sourceRoot":"","sources":["../../src/Terminal/TerminalWritable.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,2DAA+D;AAC/D,mCAAwD;AAsBxD;;;;GAIG;AACH,MAAa,gBAAiB,SAAQ,iBAAQ;IAG5C,YAAmB,OAAiC;QAClD,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC;QACxD,KAAK,CAAC,eAAe,CAAC,CAAC;QAEvB,IAAI,CAAC,OAAO,GAAG,SAAS,CAAC;QACzB,QAAQ,QAAQ,EAAE;YAChB,KAAK,4CAAwB,CAAC,GAAG;gBAC/B,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBAClD,MAAM;YACR,KAAK,4CAAwB,CAAC,OAAO;gBACnC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACzD,MAAM;YACR,KAAK,4CAAwB,CAAC,KAAK;gBACjC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvD,MAAM;YACR,KAAK,4CAAwB,CAAC,OAAO;gBACnC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACzD,MAAM;YACR,KAAK,4CAAwB,CAAC,KAAK;gBACjC,IAAI,CAAC,YAAY,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;gBACvD,MAAM;YACR;gBACE,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,EAAE,CAAC,CAAC;SACpD;IACH,CAAC;IAEM,MAAM,CACX,KAAmC,EACnC,QAAgB;IAChB,kDAAkD;IAClD,QAAwC;QAExC,IAAI;YACF,MAAM,SAAS,GAAoB,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC1F,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,QAAQ,EAAE,CAAC,CAAC;SACzC;QAAC,OAAO,CAAU,EAAE;YACnB,QAAQ,CAAC,CAAU,CAAC,CAAC;YACrB,OAAO;SACR;QACD,QAAQ,EAAE,CAAC;IACb,CAAC;CACF;AA5CD,4CA4CC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport type { ITerminal } from './ITerminal';\nimport { TerminalProviderSeverity } from './ITerminalProvider';\nimport { Writable, type WritableOptions } from 'stream';\n\n/**\n * Options for {@link TerminalWritable}.\n *\n * @beta\n */\nexport interface ITerminalWritableOptions {\n /**\n * The {@link ITerminal} that the Writable will write to.\n */\n terminal: ITerminal;\n /**\n * The severity of the messages that will be written to the {@link ITerminal}.\n */\n severity: TerminalProviderSeverity;\n /**\n * Options for the underlying Writable.\n */\n writableOptions?: WritableOptions;\n}\n\n/**\n * A adapter to allow writing to a provided terminal using Writable streams.\n *\n * @beta\n */\nexport class TerminalWritable extends Writable {\n private _writeMethod: (data: string) => void;\n\n public constructor(options: ITerminalWritableOptions) {\n const { terminal, severity, writableOptions } = options;\n super(writableOptions);\n\n this._writev = undefined;\n switch (severity) {\n case TerminalProviderSeverity.log:\n this._writeMethod = terminal.write.bind(terminal);\n break;\n case TerminalProviderSeverity.verbose:\n this._writeMethod = terminal.writeVerbose.bind(terminal);\n break;\n case TerminalProviderSeverity.debug:\n this._writeMethod = terminal.writeDebug.bind(terminal);\n break;\n case TerminalProviderSeverity.warning:\n this._writeMethod = terminal.writeWarning.bind(terminal);\n break;\n case TerminalProviderSeverity.error:\n this._writeMethod = terminal.writeError.bind(terminal);\n break;\n default:\n throw new Error(`Unknown severity: ${severity}`);\n }\n }\n\n public _write(\n chunk: string | Buffer | Uint8Array,\n encoding: string,\n // eslint-disable-next-line @rushstack/no-new-null\n callback: (error?: Error | null) => void\n ): void {\n try {\n const chunkData: string | Buffer = typeof chunk === 'string' ? chunk : Buffer.from(chunk);\n this._writeMethod(chunkData.toString());\n } catch (e: unknown) {\n callback(e as Error);\n return;\n }\n callback();\n }\n}\n"]}