@rushstack/terminal 0.7.24 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/terminal.d.ts +487 -2
  2. package/dist/tsdoc-metadata.json +1 -1
  3. package/lib/AnsiEscape.d.ts +35 -0
  4. package/lib/AnsiEscape.d.ts.map +1 -0
  5. package/lib/AnsiEscape.js +136 -0
  6. package/lib/AnsiEscape.js.map +1 -0
  7. package/lib/Colorize.d.ts +79 -0
  8. package/lib/Colorize.d.ts.map +1 -0
  9. package/lib/Colorize.js +143 -0
  10. package/lib/Colorize.js.map +1 -0
  11. package/lib/ConsoleTerminalProvider.d.ts +48 -0
  12. package/lib/ConsoleTerminalProvider.d.ts.map +1 -0
  13. package/lib/ConsoleTerminalProvider.js +71 -0
  14. package/lib/ConsoleTerminalProvider.js.map +1 -0
  15. package/lib/ITerminal.d.ts +81 -0
  16. package/lib/ITerminal.d.ts.map +1 -0
  17. package/lib/ITerminal.js +5 -0
  18. package/lib/ITerminal.js.map +1 -0
  19. package/lib/ITerminalProvider.d.ts +54 -0
  20. package/lib/ITerminalProvider.d.ts.map +1 -0
  21. package/lib/ITerminalProvider.js +32 -0
  22. package/lib/ITerminalProvider.js.map +1 -0
  23. package/lib/MockWritable.d.ts.map +1 -1
  24. package/lib/MockWritable.js +3 -3
  25. package/lib/MockWritable.js.map +1 -1
  26. package/lib/PrefixProxyTerminalProvider.d.ts +57 -0
  27. package/lib/PrefixProxyTerminalProvider.d.ts.map +1 -0
  28. package/lib/PrefixProxyTerminalProvider.js +64 -0
  29. package/lib/PrefixProxyTerminalProvider.js.map +1 -0
  30. package/lib/PrintUtilities.d.ts +1 -1
  31. package/lib/PrintUtilities.d.ts.map +1 -1
  32. package/lib/PrintUtilities.js.map +1 -1
  33. package/lib/RemoveColorsTextRewriter.js +2 -2
  34. package/lib/RemoveColorsTextRewriter.js.map +1 -1
  35. package/lib/StringBufferTerminalProvider.d.ts +63 -0
  36. package/lib/StringBufferTerminalProvider.d.ts.map +1 -0
  37. package/lib/StringBufferTerminalProvider.js +107 -0
  38. package/lib/StringBufferTerminalProvider.js.map +1 -0
  39. package/lib/Terminal.d.ts +63 -0
  40. package/lib/Terminal.d.ts.map +1 -0
  41. package/lib/Terminal.js +348 -0
  42. package/lib/Terminal.js.map +1 -0
  43. package/lib/TerminalStreamWritable.d.ts +35 -0
  44. package/lib/TerminalStreamWritable.d.ts.map +1 -0
  45. package/lib/TerminalStreamWritable.js +53 -0
  46. package/lib/TerminalStreamWritable.js.map +1 -0
  47. package/lib/TerminalWritable.d.ts +1 -1
  48. package/lib/TerminalWritable.js +1 -1
  49. package/lib/TerminalWritable.js.map +1 -1
  50. package/lib/index.d.ts +24 -15
  51. package/lib/index.d.ts.map +1 -1
  52. package/lib/index.js +46 -29
  53. package/lib/index.js.map +1 -1
  54. package/package.json +7 -4
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Similar to many popular logging packages, terminal providers support a range of message
3
+ * severities. These severities have built-in formatting defaults in the Terminal object
4
+ * (warnings are yellow, errors are red, etc.).
5
+ *
6
+ * Terminal providers may choose to suppress certain messages based on their severity,
7
+ * or to route some messages to other providers or not based on severity.
8
+ *
9
+ * Severity | Purpose
10
+ * --------- | -------
11
+ * error | Build errors and fatal issues
12
+ * warning | Not necessarily fatal, but indicate a problem the user should fix
13
+ * log | Informational messages
14
+ * verbose | Additional information that may not always be necessary
15
+ * debug | Highest detail level, best used for troubleshooting information
16
+ *
17
+ * @beta
18
+ */
19
+ export declare enum TerminalProviderSeverity {
20
+ log = 0,
21
+ warning = 1,
22
+ error = 2,
23
+ verbose = 3,
24
+ debug = 4
25
+ }
26
+ /**
27
+ * Implement the interface to create a terminal provider. Terminal providers
28
+ * can be registered to a {@link Terminal} instance to receive messages.
29
+ *
30
+ * @beta
31
+ */
32
+ export interface ITerminalProvider {
33
+ /**
34
+ * This property should return true only if the terminal provider supports
35
+ * rendering console colors.
36
+ */
37
+ supportsColor: boolean;
38
+ /**
39
+ * This property should return the newline character the terminal provider
40
+ * expects.
41
+ */
42
+ eolCharacter: string;
43
+ /**
44
+ * This function gets called on every terminal provider upon every
45
+ * message function call on the terminal instance.
46
+ *
47
+ * @param data - The terminal message.
48
+ * @param severity - The message severity. Terminal providers can
49
+ * route different kinds of messages to different streams and may choose
50
+ * to ignore verbose or debug messages.
51
+ */
52
+ write(data: string, severity: TerminalProviderSeverity): void;
53
+ }
54
+ //# sourceMappingURL=ITerminalProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITerminalProvider.d.ts","sourceRoot":"","sources":["../src/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"}
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.TerminalProviderSeverity = void 0;
6
+ /**
7
+ * Similar to many popular logging packages, terminal providers support a range of message
8
+ * severities. These severities have built-in formatting defaults in the Terminal object
9
+ * (warnings are yellow, errors are red, etc.).
10
+ *
11
+ * Terminal providers may choose to suppress certain messages based on their severity,
12
+ * or to route some messages to other providers or not based on severity.
13
+ *
14
+ * Severity | Purpose
15
+ * --------- | -------
16
+ * error | Build errors and fatal issues
17
+ * warning | Not necessarily fatal, but indicate a problem the user should fix
18
+ * log | Informational messages
19
+ * verbose | Additional information that may not always be necessary
20
+ * debug | Highest detail level, best used for troubleshooting information
21
+ *
22
+ * @beta
23
+ */
24
+ var TerminalProviderSeverity;
25
+ (function (TerminalProviderSeverity) {
26
+ TerminalProviderSeverity[TerminalProviderSeverity["log"] = 0] = "log";
27
+ TerminalProviderSeverity[TerminalProviderSeverity["warning"] = 1] = "warning";
28
+ TerminalProviderSeverity[TerminalProviderSeverity["error"] = 2] = "error";
29
+ TerminalProviderSeverity[TerminalProviderSeverity["verbose"] = 3] = "verbose";
30
+ TerminalProviderSeverity[TerminalProviderSeverity["debug"] = 4] = "debug";
31
+ })(TerminalProviderSeverity || (exports.TerminalProviderSeverity = TerminalProviderSeverity = {}));
32
+ //# sourceMappingURL=ITerminalProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ITerminalProvider.js","sourceRoot":"","sources":["../src/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,wCAAxB,wBAAwB,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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"MockWritable.d.ts","sourceRoot":"","sources":["../src/MockWritable.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAGtD;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,SAAgB,MAAM,EAAE,cAAc,EAAE,CAAM;IAE9C,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAI5C,KAAK,IAAI,IAAI;IAIb,YAAY,IAAI,MAAM;IAItB,kBAAkB,IAAI,cAAc,EAAE;CAG9C"}
1
+ {"version":3,"file":"MockWritable.d.ts","sourceRoot":"","sources":["../src/MockWritable.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAEtD;;;;GAIG;AACH,qBAAa,YAAa,SAAQ,gBAAgB;IAChD,SAAgB,MAAM,EAAE,cAAc,EAAE,CAAM;IAE9C,SAAS,CAAC,YAAY,CAAC,KAAK,EAAE,cAAc,GAAG,IAAI;IAI5C,KAAK,IAAI,IAAI;IAIb,YAAY,IAAI,MAAM;IAItB,kBAAkB,IAAI,cAAc,EAAE;CAG9C"}
@@ -3,8 +3,8 @@
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.MockWritable = void 0;
6
+ const AnsiEscape_1 = require("./AnsiEscape");
6
7
  const TerminalWritable_1 = require("./TerminalWritable");
7
- const node_core_library_1 = require("@rushstack/node-core-library");
8
8
  /**
9
9
  * A {@link TerminalWritable} subclass for use by unit tests.
10
10
  *
@@ -22,10 +22,10 @@ class MockWritable extends TerminalWritable_1.TerminalWritable {
22
22
  this.chunks.length = 0;
23
23
  }
24
24
  getAllOutput() {
25
- return node_core_library_1.AnsiEscape.formatForTests(this.chunks.map((x) => x.text).join(''));
25
+ return AnsiEscape_1.AnsiEscape.formatForTests(this.chunks.map((x) => x.text).join(''));
26
26
  }
27
27
  getFormattedChunks() {
28
- return this.chunks.map((x) => (Object.assign(Object.assign({}, x), { text: node_core_library_1.AnsiEscape.formatForTests(x.text) })));
28
+ return this.chunks.map((x) => (Object.assign(Object.assign({}, x), { text: AnsiEscape_1.AnsiEscape.formatForTests(x.text) })));
29
29
  }
30
30
  }
31
31
  exports.MockWritable = MockWritable;
@@ -1 +1 @@
1
- {"version":3,"file":"MockWritable.js","sourceRoot":"","sources":["../src/MockWritable.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAG3D,yDAAsD;AACtD,oEAA0D;AAE1D;;;;GAIG;AACH,MAAa,YAAa,SAAQ,mCAAgB;IAAlD;;QACkB,WAAM,GAAqB,EAAE,CAAC;IAiBhD,CAAC;IAfW,YAAY,CAAC,KAAqB;QAC1C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IACzB,CAAC;IAEM,YAAY;QACjB,OAAO,8BAAU,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC;IAEM,kBAAkB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,gCAAK,CAAC,KAAE,IAAI,EAAE,8BAAU,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAqB,CAAA,CAAC,CAAC;IACvG,CAAC;CACF;AAlBD,oCAkBC","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 { ITerminalChunk } from './ITerminalChunk';\nimport { TerminalWritable } from './TerminalWritable';\nimport { AnsiEscape } from '@rushstack/node-core-library';\n\n/**\n * A {@link TerminalWritable} subclass for use by unit tests.\n *\n * @beta\n */\nexport class MockWritable extends TerminalWritable {\n public readonly chunks: ITerminalChunk[] = [];\n\n protected onWriteChunk(chunk: ITerminalChunk): void {\n this.chunks.push(chunk);\n }\n\n public reset(): void {\n this.chunks.length = 0;\n }\n\n public getAllOutput(): string {\n return AnsiEscape.formatForTests(this.chunks.map((x) => x.text).join(''));\n }\n\n public getFormattedChunks(): ITerminalChunk[] {\n return this.chunks.map((x) => ({ ...x, text: AnsiEscape.formatForTests(x.text) } as ITerminalChunk));\n }\n}\n"]}
1
+ {"version":3,"file":"MockWritable.js","sourceRoot":"","sources":["../src/MockWritable.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,6CAA0C;AAE1C,yDAAsD;AAEtD;;;;GAIG;AACH,MAAa,YAAa,SAAQ,mCAAgB;IAAlD;;QACkB,WAAM,GAAqB,EAAE,CAAC;IAiBhD,CAAC;IAfW,YAAY,CAAC,KAAqB;QAC1C,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC;IAEM,KAAK;QACV,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IACzB,CAAC;IAEM,YAAY;QACjB,OAAO,uBAAU,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5E,CAAC;IAEM,kBAAkB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,gCAAK,CAAC,KAAE,IAAI,EAAE,uBAAU,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,GAAqB,CAAA,CAAC,CAAC;IACvG,CAAC;CACF;AAlBD,oCAkBC","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 { AnsiEscape } from './AnsiEscape';\nimport type { ITerminalChunk } from './ITerminalChunk';\nimport { TerminalWritable } from './TerminalWritable';\n\n/**\n * A {@link TerminalWritable} subclass for use by unit tests.\n *\n * @beta\n */\nexport class MockWritable extends TerminalWritable {\n public readonly chunks: ITerminalChunk[] = [];\n\n protected onWriteChunk(chunk: ITerminalChunk): void {\n this.chunks.push(chunk);\n }\n\n public reset(): void {\n this.chunks.length = 0;\n }\n\n public getAllOutput(): string {\n return AnsiEscape.formatForTests(this.chunks.map((x) => x.text).join(''));\n }\n\n public getFormattedChunks(): ITerminalChunk[] {\n return this.chunks.map((x) => ({ ...x, text: AnsiEscape.formatForTests(x.text) } as ITerminalChunk));\n }\n}\n"]}
@@ -0,0 +1,57 @@
1
+ import type { ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';
2
+ /**
3
+ * @beta
4
+ */
5
+ export interface IPrefixProxyTerminalProviderOptionsBase {
6
+ /**
7
+ * The {@link ITerminalProvider} that will be wrapped.
8
+ */
9
+ terminalProvider: ITerminalProvider;
10
+ }
11
+ /**
12
+ * Options for {@link PrefixProxyTerminalProvider}, with a static prefix.
13
+ *
14
+ * @beta
15
+ */
16
+ export interface IStaticPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {
17
+ /**
18
+ * The prefix that should be added to each line of output.
19
+ */
20
+ prefix: string;
21
+ }
22
+ /**
23
+ * Options for {@link PrefixProxyTerminalProvider}.
24
+ *
25
+ * @beta
26
+ */
27
+ export interface IDynamicPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {
28
+ /**
29
+ * A function that returns the prefix that should be added to each line of output. This is useful
30
+ * for prefixing each line with a timestamp.
31
+ */
32
+ getPrefix: () => string;
33
+ }
34
+ /**
35
+ * @beta
36
+ */
37
+ export type IPrefixProxyTerminalProviderOptions = IStaticPrefixProxyTerminalProviderOptions | IDynamicPrefixProxyTerminalProviderOptions;
38
+ /**
39
+ * Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified
40
+ * prefix string.
41
+ *
42
+ * @beta
43
+ */
44
+ export declare class PrefixProxyTerminalProvider implements ITerminalProvider {
45
+ private readonly _parentTerminalProvider;
46
+ private readonly _getPrefix;
47
+ private readonly _newlineRegex;
48
+ private _isOnNewline;
49
+ constructor(options: IPrefixProxyTerminalProviderOptions);
50
+ /** @override */
51
+ get supportsColor(): boolean;
52
+ /** @override */
53
+ get eolCharacter(): string;
54
+ /** @override */
55
+ write(data: string, severity: TerminalProviderSeverity): void;
56
+ }
57
+ //# sourceMappingURL=PrefixProxyTerminalProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrefixProxyTerminalProvider.d.ts","sourceRoot":"","sources":["../src/PrefixProxyTerminalProvider.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAEvF;;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"}
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.PrefixProxyTerminalProvider = void 0;
6
+ const node_core_library_1 = require("@rushstack/node-core-library");
7
+ /**
8
+ * Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified
9
+ * prefix string.
10
+ *
11
+ * @beta
12
+ */
13
+ class PrefixProxyTerminalProvider {
14
+ constructor(options) {
15
+ const { terminalProvider } = options;
16
+ this._parentTerminalProvider = terminalProvider;
17
+ if (options.prefix !== undefined) {
18
+ const { prefix } = options;
19
+ this._getPrefix = () => prefix;
20
+ }
21
+ else {
22
+ const { getPrefix } = options;
23
+ this._getPrefix = getPrefix;
24
+ }
25
+ this._isOnNewline = true;
26
+ // eslint-disable-next-line @rushstack/security/no-unsafe-regexp
27
+ this._newlineRegex = new RegExp(`${node_core_library_1.Text.escapeRegExp(terminalProvider.eolCharacter)}|\\n`, 'g');
28
+ }
29
+ /** @override */
30
+ get supportsColor() {
31
+ return this._parentTerminalProvider.supportsColor;
32
+ }
33
+ /** @override */
34
+ get eolCharacter() {
35
+ return this._parentTerminalProvider.eolCharacter;
36
+ }
37
+ /** @override */
38
+ write(data, severity) {
39
+ // We need to track newlines to ensure that the prefix is added to each line
40
+ let currentIndex = 0;
41
+ // eslint-disable-next-line @rushstack/no-new-null
42
+ let newlineMatch;
43
+ while ((newlineMatch = this._newlineRegex.exec(data))) {
44
+ // Extract the line, add the prefix, and write it out with the newline
45
+ const newlineIndex = newlineMatch.index;
46
+ const newIndex = newlineIndex + newlineMatch[0].length;
47
+ const prefix = this._isOnNewline ? this._getPrefix() : '';
48
+ const dataToWrite = `${prefix}${data.substring(currentIndex, newIndex)}`;
49
+ this._parentTerminalProvider.write(dataToWrite, severity);
50
+ // Update the currentIndex to start the search from the char after the newline
51
+ currentIndex = newIndex;
52
+ this._isOnNewline = true;
53
+ }
54
+ // The remaining data is not postfixed by a newline, so write out the data and set _isNewline to false
55
+ const remainingData = data.substring(currentIndex);
56
+ if (remainingData.length) {
57
+ const prefix = this._isOnNewline ? this._getPrefix() : '';
58
+ this._parentTerminalProvider.write(`${prefix}${remainingData}`, severity);
59
+ this._isOnNewline = false;
60
+ }
61
+ }
62
+ }
63
+ exports.PrefixProxyTerminalProvider = PrefixProxyTerminalProvider;
64
+ //# sourceMappingURL=PrefixProxyTerminalProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PrefixProxyTerminalProvider.js","sourceRoot":"","sources":["../src/PrefixProxyTerminalProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,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AAC,CAAC,MAAM,CAAC;YAC/D,MAAM,MAAM,GAAW,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAClE,MAAM,WAAW,GAAW,GAAG,MAAM,GAAG,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,QAAQ,CAAC,EAAE,CAAC;YACjF,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;YAC1D,8EAA8E;YAC9E,YAAY,GAAG,QAAQ,CAAC;YACxB,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;QAED,sGAAsG;QACtG,MAAM,aAAa,GAAW,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QAC3D,IAAI,aAAa,CAAC,MAAM,EAAE,CAAC;YACzB,MAAM,MAAM,GAAW,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAClE,IAAI,CAAC,uBAAuB,CAAC,KAAK,CAAC,GAAG,MAAM,GAAG,aAAa,EAAE,EAAE,QAAQ,CAAC,CAAC;YAC1E,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC;QAC5B,CAAC;IACH,CAAC;CACF;AA9DD,kEA8DC","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 { Text } from '@rushstack/node-core-library';\nimport type { ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';\n\n/**\n * @beta\n */\nexport interface IPrefixProxyTerminalProviderOptionsBase {\n /**\n * The {@link ITerminalProvider} that will be wrapped.\n */\n terminalProvider: ITerminalProvider;\n}\n\n/**\n * Options for {@link PrefixProxyTerminalProvider}, with a static prefix.\n *\n * @beta\n */\nexport interface IStaticPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {\n /**\n * The prefix that should be added to each line of output.\n */\n prefix: string;\n}\n\n/**\n * Options for {@link PrefixProxyTerminalProvider}.\n *\n * @beta\n */\nexport interface IDynamicPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {\n /**\n * A function that returns the prefix that should be added to each line of output. This is useful\n * for prefixing each line with a timestamp.\n */\n getPrefix: () => string;\n}\n\n/**\n * @beta\n */\nexport type IPrefixProxyTerminalProviderOptions =\n | IStaticPrefixProxyTerminalProviderOptions\n | IDynamicPrefixProxyTerminalProviderOptions;\n\n/**\n * Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified\n * prefix string.\n *\n * @beta\n */\nexport class PrefixProxyTerminalProvider implements ITerminalProvider {\n private readonly _parentTerminalProvider: ITerminalProvider;\n private readonly _getPrefix: () => string;\n private readonly _newlineRegex: RegExp;\n private _isOnNewline: boolean;\n\n public constructor(options: IPrefixProxyTerminalProviderOptions) {\n const { terminalProvider } = options;\n\n this._parentTerminalProvider = terminalProvider;\n\n if ((options as IStaticPrefixProxyTerminalProviderOptions).prefix !== undefined) {\n const { prefix } = options as IStaticPrefixProxyTerminalProviderOptions;\n this._getPrefix = () => prefix;\n } else {\n const { getPrefix } = options as IDynamicPrefixProxyTerminalProviderOptions;\n this._getPrefix = getPrefix;\n }\n\n this._isOnNewline = true;\n\n // eslint-disable-next-line @rushstack/security/no-unsafe-regexp\n this._newlineRegex = new RegExp(`${Text.escapeRegExp(terminalProvider.eolCharacter)}|\\\\n`, 'g');\n }\n\n /** @override */\n public get supportsColor(): boolean {\n return this._parentTerminalProvider.supportsColor;\n }\n\n /** @override */\n public get eolCharacter(): string {\n return this._parentTerminalProvider.eolCharacter;\n }\n\n /** @override */\n public write(data: string, severity: TerminalProviderSeverity): void {\n // We need to track newlines to ensure that the prefix is added to each line\n let currentIndex: number = 0;\n // eslint-disable-next-line @rushstack/no-new-null\n let newlineMatch: RegExpExecArray | null;\n\n while ((newlineMatch = this._newlineRegex.exec(data))) {\n // Extract the line, add the prefix, and write it out with the newline\n const newlineIndex: number = newlineMatch.index;\n const newIndex: number = newlineIndex + newlineMatch[0].length;\n const prefix: string = this._isOnNewline ? this._getPrefix() : '';\n const dataToWrite: string = `${prefix}${data.substring(currentIndex, newIndex)}`;\n this._parentTerminalProvider.write(dataToWrite, severity);\n // Update the currentIndex to start the search from the char after the newline\n currentIndex = newIndex;\n this._isOnNewline = true;\n }\n\n // The remaining data is not postfixed by a newline, so write out the data and set _isNewline to false\n const remainingData: string = data.substring(currentIndex);\n if (remainingData.length) {\n const prefix: string = this._isOnNewline ? this._getPrefix() : '';\n this._parentTerminalProvider.write(`${prefix}${remainingData}`, severity);\n this._isOnNewline = false;\n }\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ITerminal } from '@rushstack/node-core-library';
1
+ import type { ITerminal } from './ITerminal';
2
2
  /**
3
3
  * A sensible fallback column width for consoles.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"PrintUtilities.d.ts","sourceRoot":"","sources":["../src/PrintUtilities.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAE9D;;;;GAIG;AACH,eAAO,MAAM,qBAAqB,EAAE,MAAW,CAAC;AAEhD;;;;GAIG;AACH,qBAAa,cAAc;IACzB;;OAEG;WACW,eAAe,IAAI,MAAM,GAAG,SAAS;IAInD;;;;;;OAMG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM;IACtF;;;;;;OAMG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM;IAC1F;;;;;;;OAOG;WACW,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,MAAM,EAAE,kBAAkB,CAAC,EAAE,MAAM,GA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ACnD,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAC/F,CAAC;YACD,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AAvMD,wCAuMC","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 '@rushstack/node-core-library';\n\n/**\n * A sensible fallback column width for consoles.\n *\n * @public\n */\nexport const DEFAULT_CONSOLE_WIDTH: number = 80;\n\n/**\n * A collection of utilities for printing messages to the console.\n *\n * @public\n */\nexport class PrintUtilities {\n /**\n * Returns the width of the console, measured in columns\n */\n public static getConsoleWidth(): number | undefined {\n return process.stdout?.columns;\n }\n\n /**\n * Applies word wrapping.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indent - The number of spaces to indent the wrapped lines, defaults to 0\n */\n public static wrapWords(text: string, maxLineLength?: number, indent?: number): string;\n /**\n * Applies word wrapping.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param linePrefix - The string to prefix each line with, defaults to ''\n */\n public static wrapWords(text: string, maxLineLength?: number, linePrefix?: string): string;\n /**\n * Applies word wrapping.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indentOrLinePrefix - The number of spaces to indent the wrapped lines or the string to prefix\n * each line with, defaults to no prefix\n */\n public static wrapWords(text: string, maxLineLength?: number, indentOrLinePrefix?: number | string): string;\n public static wrapWords(\n text: string,\n maxLineLength?: number,\n indentOrLinePrefix?: number | string\n ): string {\n const wrappedLines: string[] = PrintUtilities.wrapWordsToLines(\n text,\n maxLineLength,\n indentOrLinePrefix as string | undefined // TS is confused by the overloads\n );\n return wrappedLines.join('\\n');\n }\n\n /**\n * Applies word wrapping and returns an array of lines.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indent - The number of spaces to indent the wrapped lines, defaults to 0\n */\n public static wrapWordsToLines(text: string, maxLineLength?: number, indent?: number): string[];\n /**\n * Applies word wrapping and returns an array of lines.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param linePrefix - The string to prefix each line with, defaults to ''\n */\n public static wrapWordsToLines(text: string, maxLineLength?: number, linePrefix?: string): string[];\n /**\n * Applies word wrapping and returns an array of lines.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indentOrLinePrefix - The number of spaces to indent the wrapped lines or the string to prefix\n * each line with, defaults to no prefix\n */\n public static wrapWordsToLines(\n text: string,\n maxLineLength?: number,\n indentOrLinePrefix?: number | string\n ): string[];\n public static wrapWordsToLines(\n text: string,\n maxLineLength?: number,\n indentOrLinePrefix?: number | string\n ): string[] {\n let linePrefix: string;\n switch (typeof indentOrLinePrefix) {\n case 'number':\n linePrefix = ' '.repeat(indentOrLinePrefix);\n break;\n case 'string':\n linePrefix = indentOrLinePrefix;\n break;\n default:\n linePrefix = '';\n break;\n }\n\n const linePrefixLength: number = linePrefix.length;\n\n if (!maxLineLength) {\n maxLineLength = PrintUtilities.getConsoleWidth() || DEFAULT_CONSOLE_WIDTH;\n }\n\n // Apply word wrapping and the provided line prefix, while also respecting existing newlines\n // and prefix spaces that may exist in the text string already.\n const lines: string[] = text.split(/\\r?\\n/);\n\n const wrappedLines: string[] = [];\n for (const line of lines) {\n if (line.length + linePrefixLength <= maxLineLength) {\n wrappedLines.push(linePrefix + line);\n } else {\n const lineAdditionalPrefix: string = line.match(/^\\s*/)?.[0] || '';\n const whitespaceRegexp: RegExp = /\\s+/g;\n let currentWhitespaceMatch: RegExpExecArray | null = null;\n let previousWhitespaceMatch: RegExpExecArray | undefined;\n let currentLineStartIndex: number = lineAdditionalPrefix.length;\n let previousBreakRanOver: boolean = false;\n while ((currentWhitespaceMatch = whitespaceRegexp.exec(line)) !== null) {\n if (currentWhitespaceMatch.index + linePrefixLength - currentLineStartIndex > maxLineLength) {\n let whitespaceToSplitAt: RegExpExecArray | undefined;\n if (\n !previousWhitespaceMatch ||\n // Handle the case where there are two words longer than the maxLineLength in a row\n previousBreakRanOver\n ) {\n whitespaceToSplitAt = currentWhitespaceMatch;\n } else {\n whitespaceToSplitAt = previousWhitespaceMatch;\n }\n\n wrappedLines.push(\n linePrefix +\n lineAdditionalPrefix +\n line.substring(currentLineStartIndex, whitespaceToSplitAt.index)\n );\n previousBreakRanOver = whitespaceToSplitAt.index - currentLineStartIndex > maxLineLength;\n currentLineStartIndex = whitespaceToSplitAt.index + whitespaceToSplitAt[0].length;\n } else {\n previousBreakRanOver = false;\n }\n\n previousWhitespaceMatch = currentWhitespaceMatch;\n }\n\n if (currentLineStartIndex < line.length) {\n wrappedLines.push(linePrefix + lineAdditionalPrefix + line.substring(currentLineStartIndex));\n }\n }\n }\n\n return wrappedLines;\n }\n\n /**\n * Displays a message in the console wrapped in a box UI.\n *\n * @param message - The message to display.\n * @param terminal - The terminal to write the message to.\n * @param boxWidth - The width of the box, defaults to half of the console width.\n */\n public static printMessageInBox(message: string, terminal: ITerminal, boxWidth?: number): void {\n if (!boxWidth) {\n const consoleWidth: number = PrintUtilities.getConsoleWidth() || DEFAULT_CONSOLE_WIDTH;\n boxWidth = Math.floor(consoleWidth / 2);\n }\n\n const maxLineLength: number = boxWidth - 10;\n const wrappedMessageLines: string[] = PrintUtilities.wrapWordsToLines(message, maxLineLength);\n let longestLineLength: number = 0;\n const trimmedLines: string[] = [];\n for (const line of wrappedMessageLines) {\n const trimmedLine: string = line.trim();\n trimmedLines.push(trimmedLine);\n longestLineLength = Math.max(longestLineLength, trimmedLine.length);\n }\n\n if (longestLineLength > boxWidth - 2) {\n // If the longest line is longer than the box, print bars above and below the message\n // ═════════════\n // Message\n // ═════════════\n const headerAndFooter: string = ` ${'═'.repeat(boxWidth)}`;\n terminal.writeLine(headerAndFooter);\n for (const line of wrappedMessageLines) {\n terminal.writeLine(` ${line}`);\n }\n\n terminal.writeLine(headerAndFooter);\n } else {\n // ╔═══════════╗\n // ║ Message ║\n // ╚═══════════╝\n terminal.writeLine(` ╔${'═'.repeat(boxWidth - 2)}╗`);\n for (const trimmedLine of trimmedLines) {\n const padding: number = boxWidth - trimmedLine.length - 2;\n const leftPadding: number = Math.floor(padding / 2);\n const rightPadding: number = padding - leftPadding;\n terminal.writeLine(` ║${' '.repeat(leftPadding)}${trimmedLine}${' '.repeat(rightPadding)}║`);\n }\n terminal.writeLine(` ╚${'═'.repeat(boxWidth - 2)}╝`);\n }\n }\n}\n"]}
1
+ {"version":3,"file":"PrintUtilities.js","sourceRoot":"","sources":["../src/PrintUtilities.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAI3D;;;;GAIG;AACU,QAAA,qBAAqB,GAAW,EAAE,CAAC;AAEhD;;;;GAIG;AACH,MAAa,cAAc;IACzB;;OAEG;IACI,MAAM,CAAC,eAAe;;QAC3B,OAAO,MAAA,OAAO,CAAC,MAAM,0CAAE,OAAO,CAAC;IACjC,CAAC;IA2BM,MAAM,CAAC,SAAS,CACrB,IAAY,EACZ,aAAsB,EACtB,kBAAoC;QAEpC,MAAM,YAAY,GAAa,cAAc,CAAC,gBAAgB,CAC5D,IAAI,EACJ,aAAa,EACb,kBAAwC,CAAC,kCAAkC;SAC5E,CAAC;QACF,OAAO,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACjC,CAAC;IA+BM,MAAM,CAAC,gBAAgB,CAC5B,IAAY,EACZ,aAAsB,EACtB,kBAAoC;;QAEpC,IAAI,UAAkB,CAAC;QACvB,QAAQ,OAAO,kBAAkB,EAAE,CAAC;YAClC,KAAK,QAAQ;gBACX,UAAU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AAW,CAAC,GAAG,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;YAC/F,CAAC;YACD,QAAQ,CAAC,SAAS,CAAC,KAAK,GAAG,CAAC,MAAM,CAAC,QAAQ,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACvD,CAAC;IACH,CAAC;CACF;AAvMD,wCAuMC","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';\n\n/**\n * A sensible fallback column width for consoles.\n *\n * @public\n */\nexport const DEFAULT_CONSOLE_WIDTH: number = 80;\n\n/**\n * A collection of utilities for printing messages to the console.\n *\n * @public\n */\nexport class PrintUtilities {\n /**\n * Returns the width of the console, measured in columns\n */\n public static getConsoleWidth(): number | undefined {\n return process.stdout?.columns;\n }\n\n /**\n * Applies word wrapping.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indent - The number of spaces to indent the wrapped lines, defaults to 0\n */\n public static wrapWords(text: string, maxLineLength?: number, indent?: number): string;\n /**\n * Applies word wrapping.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param linePrefix - The string to prefix each line with, defaults to ''\n */\n public static wrapWords(text: string, maxLineLength?: number, linePrefix?: string): string;\n /**\n * Applies word wrapping.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indentOrLinePrefix - The number of spaces to indent the wrapped lines or the string to prefix\n * each line with, defaults to no prefix\n */\n public static wrapWords(text: string, maxLineLength?: number, indentOrLinePrefix?: number | string): string;\n public static wrapWords(\n text: string,\n maxLineLength?: number,\n indentOrLinePrefix?: number | string\n ): string {\n const wrappedLines: string[] = PrintUtilities.wrapWordsToLines(\n text,\n maxLineLength,\n indentOrLinePrefix as string | undefined // TS is confused by the overloads\n );\n return wrappedLines.join('\\n');\n }\n\n /**\n * Applies word wrapping and returns an array of lines.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indent - The number of spaces to indent the wrapped lines, defaults to 0\n */\n public static wrapWordsToLines(text: string, maxLineLength?: number, indent?: number): string[];\n /**\n * Applies word wrapping and returns an array of lines.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param linePrefix - The string to prefix each line with, defaults to ''\n */\n public static wrapWordsToLines(text: string, maxLineLength?: number, linePrefix?: string): string[];\n /**\n * Applies word wrapping and returns an array of lines.\n *\n * @param text - The text to wrap\n * @param maxLineLength - The maximum length of a line, defaults to the console width\n * @param indentOrLinePrefix - The number of spaces to indent the wrapped lines or the string to prefix\n * each line with, defaults to no prefix\n */\n public static wrapWordsToLines(\n text: string,\n maxLineLength?: number,\n indentOrLinePrefix?: number | string\n ): string[];\n public static wrapWordsToLines(\n text: string,\n maxLineLength?: number,\n indentOrLinePrefix?: number | string\n ): string[] {\n let linePrefix: string;\n switch (typeof indentOrLinePrefix) {\n case 'number':\n linePrefix = ' '.repeat(indentOrLinePrefix);\n break;\n case 'string':\n linePrefix = indentOrLinePrefix;\n break;\n default:\n linePrefix = '';\n break;\n }\n\n const linePrefixLength: number = linePrefix.length;\n\n if (!maxLineLength) {\n maxLineLength = PrintUtilities.getConsoleWidth() || DEFAULT_CONSOLE_WIDTH;\n }\n\n // Apply word wrapping and the provided line prefix, while also respecting existing newlines\n // and prefix spaces that may exist in the text string already.\n const lines: string[] = text.split(/\\r?\\n/);\n\n const wrappedLines: string[] = [];\n for (const line of lines) {\n if (line.length + linePrefixLength <= maxLineLength) {\n wrappedLines.push(linePrefix + line);\n } else {\n const lineAdditionalPrefix: string = line.match(/^\\s*/)?.[0] || '';\n const whitespaceRegexp: RegExp = /\\s+/g;\n let currentWhitespaceMatch: RegExpExecArray | null = null;\n let previousWhitespaceMatch: RegExpExecArray | undefined;\n let currentLineStartIndex: number = lineAdditionalPrefix.length;\n let previousBreakRanOver: boolean = false;\n while ((currentWhitespaceMatch = whitespaceRegexp.exec(line)) !== null) {\n if (currentWhitespaceMatch.index + linePrefixLength - currentLineStartIndex > maxLineLength) {\n let whitespaceToSplitAt: RegExpExecArray | undefined;\n if (\n !previousWhitespaceMatch ||\n // Handle the case where there are two words longer than the maxLineLength in a row\n previousBreakRanOver\n ) {\n whitespaceToSplitAt = currentWhitespaceMatch;\n } else {\n whitespaceToSplitAt = previousWhitespaceMatch;\n }\n\n wrappedLines.push(\n linePrefix +\n lineAdditionalPrefix +\n line.substring(currentLineStartIndex, whitespaceToSplitAt.index)\n );\n previousBreakRanOver = whitespaceToSplitAt.index - currentLineStartIndex > maxLineLength;\n currentLineStartIndex = whitespaceToSplitAt.index + whitespaceToSplitAt[0].length;\n } else {\n previousBreakRanOver = false;\n }\n\n previousWhitespaceMatch = currentWhitespaceMatch;\n }\n\n if (currentLineStartIndex < line.length) {\n wrappedLines.push(linePrefix + lineAdditionalPrefix + line.substring(currentLineStartIndex));\n }\n }\n }\n\n return wrappedLines;\n }\n\n /**\n * Displays a message in the console wrapped in a box UI.\n *\n * @param message - The message to display.\n * @param terminal - The terminal to write the message to.\n * @param boxWidth - The width of the box, defaults to half of the console width.\n */\n public static printMessageInBox(message: string, terminal: ITerminal, boxWidth?: number): void {\n if (!boxWidth) {\n const consoleWidth: number = PrintUtilities.getConsoleWidth() || DEFAULT_CONSOLE_WIDTH;\n boxWidth = Math.floor(consoleWidth / 2);\n }\n\n const maxLineLength: number = boxWidth - 10;\n const wrappedMessageLines: string[] = PrintUtilities.wrapWordsToLines(message, maxLineLength);\n let longestLineLength: number = 0;\n const trimmedLines: string[] = [];\n for (const line of wrappedMessageLines) {\n const trimmedLine: string = line.trim();\n trimmedLines.push(trimmedLine);\n longestLineLength = Math.max(longestLineLength, trimmedLine.length);\n }\n\n if (longestLineLength > boxWidth - 2) {\n // If the longest line is longer than the box, print bars above and below the message\n // ═════════════\n // Message\n // ═════════════\n const headerAndFooter: string = ` ${'═'.repeat(boxWidth)}`;\n terminal.writeLine(headerAndFooter);\n for (const line of wrappedMessageLines) {\n terminal.writeLine(` ${line}`);\n }\n\n terminal.writeLine(headerAndFooter);\n } else {\n // ╔═══════════╗\n // ║ Message ║\n // ╚═══════════╝\n terminal.writeLine(` ╔${'═'.repeat(boxWidth - 2)}╗`);\n for (const trimmedLine of trimmedLines) {\n const padding: number = boxWidth - trimmedLine.length - 2;\n const leftPadding: number = Math.floor(padding / 2);\n const rightPadding: number = padding - leftPadding;\n terminal.writeLine(` ║${' '.repeat(leftPadding)}${trimmedLine}${' '.repeat(rightPadding)}║`);\n }\n terminal.writeLine(` ╚${'═'.repeat(boxWidth - 2)}╝`);\n }\n }\n}\n"]}
@@ -3,7 +3,7 @@
3
3
  // See LICENSE in the project root for license information.
4
4
  Object.defineProperty(exports, "__esModule", { value: true });
5
5
  exports.RemoveColorsTextRewriter = void 0;
6
- const node_core_library_1 = require("@rushstack/node-core-library");
6
+ const AnsiEscape_1 = require("./AnsiEscape");
7
7
  const TextRewriter_1 = require("./TextRewriter");
8
8
  var State;
9
9
  (function (State) {
@@ -75,7 +75,7 @@ class RemoveColorsTextRewriter extends TextRewriter_1.TextRewriter {
75
75
  // Stop when we reach any character that is not [\x30-\x3f] or [\x20-\x2f]
76
76
  const code = c.charCodeAt(0);
77
77
  if (code < 0x20 || code > 0x3f) {
78
- result += node_core_library_1.AnsiEscape.removeCodes(state.buffer);
78
+ result += AnsiEscape_1.AnsiEscape.removeCodes(state.buffer);
79
79
  state.buffer = '';
80
80
  state.parseState = State.Start;
81
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"RemoveColorsTextRewriter.js","sourceRoot":"","sources":["../src/RemoveColorsTextRewriter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAA0D;AAC1D,iDAAsE;AAEtE,IAAK,KAOJ;AAPD,WAAK,KAAK;IACR,2DAA2D;IAC3D,mCAAK,CAAA;IACL,sCAA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9B,EAAE,KAAK,CAAC;gBACR,KAAK,CAAC,MAAM,IAAI,CAAC,CAAC;gBAElB,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,eAAe,EAAE,CAAC;oBAC/C,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;wBACd,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,YAAY,CAAC;oBACxC,CAAC;yBAAM,CAAC;wBACN,uDAAuD;wBACvD,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;wBACvB,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;wBAClB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;oBACjC,CAAC;gBACH,CAAC;qBAAM,CAAC;oBACN,qCAAqC;oBAErC,0EAA0E;oBAC1E,MAAM,IAAI,GAAW,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;oBACrC,IAAI,IAAI,GAAG,IAAI,IAAI,IAAI,GAAG,IAAI,EAAE,CAAC;wBAC/B,MAAM,IAAI,8BAAU,CAAC,WAAW,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;wBAC/C,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;wBAClB,KAAK,CAAC,UAAU,GAAG,KAAK,CAAC,KAAK,CAAC;oBACjC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,YAA+B;QAC1C,MAAM,KAAK,GAAmC,YAA8C,CAAC;QAE7F,MAAM,MAAM,GAAW,KAAK,CAAC,MAAM,CAAC;QACpC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5ED,4DA4EC","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 { AnsiEscape } from '@rushstack/node-core-library';\nimport { TextRewriter, type TextRewriterState } from './TextRewriter';\n\nenum State {\n // Buffer is empty, and we're looking for the ESC character\n Start,\n // We're looking for the '[' character\n AwaitingBracket,\n // We're reading the codes after the '[' character\n ReadingCodes\n}\n\ninterface IRemoveColorsTextRewriterState extends TextRewriterState {\n buffer: string;\n parseState: State;\n}\n\n/**\n * For use with {@link TextRewriterTransform}, this rewriter removes ANSI escape codes\n * including colored text.\n *\n * @remarks\n * The implementation also removes other ANSI escape codes such as cursor positioning.\n * The specific set of affected codes may be adjusted in the future.\n *\n * @public\n */\nexport class RemoveColorsTextRewriter extends TextRewriter {\n public initialize(): TextRewriterState {\n return { buffer: '', parseState: State.Start } as IRemoveColorsTextRewriterState;\n }\n\n public process(unknownState: TextRewriterState, text: string): string {\n const state: IRemoveColorsTextRewriterState = unknownState as IRemoveColorsTextRewriterState;\n\n // We will be matching AnsiEscape._csiRegExp:\n //\n // /\\x1b\\[([\\x30-\\x3f]*[\\x20-\\x2f]*[\\x40-\\x7e])/gu\n //\n const ESC: string = '\\x1b';\n\n let result: string = '';\n let index: number = 0;\n\n while (index < text.length) {\n if (state.parseState === State.Start) {\n // The buffer is empty, which means we haven't found anything yet\n\n const csiIndex: number = text.indexOf(ESC, index);\n if (csiIndex < 0) {\n // We reached the end of \"text\" without finding another CSI prefix\n result += text.substring(index);\n break;\n }\n\n // Append everything up to the CSI prefix\n result += text.substring(index, csiIndex);\n\n // Save the partial match in the buffer\n state.buffer = ESC;\n index = csiIndex + 1;\n state.parseState = State.AwaitingBracket;\n } else {\n // The buffer has characters, which means we started matching a partial sequence\n\n // Read another character into the buffer\n const c: string = text[index];\n ++index;\n state.buffer += c;\n\n if (state.parseState === State.AwaitingBracket) {\n if (c === '[') {\n state.parseState = State.ReadingCodes;\n } else {\n // Failed to match, so append the buffer and start over\n result += state.buffer;\n state.buffer = '';\n state.parseState = State.Start;\n }\n } else {\n // state.state === State.ReadingCodes\n\n // Stop when we reach any character that is not [\\x30-\\x3f] or [\\x20-\\x2f]\n const code: number = c.charCodeAt(0);\n if (code < 0x20 || code > 0x3f) {\n result += AnsiEscape.removeCodes(state.buffer);\n state.buffer = '';\n state.parseState = State.Start;\n }\n }\n }\n }\n\n return result;\n }\n\n public close(unknownState: TextRewriterState): string {\n const state: IRemoveColorsTextRewriterState = unknownState as IRemoveColorsTextRewriterState;\n\n const result: string = state.buffer;\n state.buffer = '';\n return result;\n }\n}\n"]}
1
+ {"version":3,"file":"RemoveColorsTextRewriter.js","sourceRoot":"","sources":["../src/RemoveColorsTextRewriter.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,6CAA0C;AAC1C,iDAAsE;AAEtE,IAAK,KAOJ;AAPD,WAAK,KAAK;IACR,2DAA2D;IAC3D,mCAAK,CAAA;IACL,sCAAsC;IACtC,uDAAe,CAAA;IACf,kDAAkD;IAClD,iDAAY,CAAA;AACd,CAAC,EAPI,KAAK,KAAL,KAAK,QAOT;AAOD;;;;;;;;;GASG;AACH,MAAa,wBAAyB,SAAQ,2BAAY;IACjD,UAAU;QACf,OAAO,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,KAAK,CAAC,KAAK,EAAoC,CAAC;IACnF,CAAC;IAEM,OAAO,CAAC,YAA+B,EAAE,IAAY;QAC1D,MAAM,KAAK,GAAmC,YAA8C,CAAC;QAE7F,6CAA6C;QAC7C,EAAE;QACF,mDAAmD;QACnD,EAAE;QACF,MAAM,GAAG,GAAW,MAAM,CAAC;QAE3B,IAAI,MAAM,GAAW,EAAE,CAAC;QACxB,IAAI,KAAK,GAAW,CAAC,CAAC;QAEtB,OAAO,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;YAC3B,IAAI,KAAK,CAAC,UAAU,KAAK,KAAK,CAAC,KAAK,EAAE,CAAC;gBACrC,iEAAiE;gBAEjE,MAAM,QAAQ,GAAW,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;gBAClD,IAAI,QAAQ,GAAG,CAAC,EAAE,CAAC;oBACj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,KAAK,CAAC,KAAK,CAAC;oBACjC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAEM,KAAK,CAAC,YAA+B;QAC1C,MAAM,KAAK,GAAmC,YAA8C,CAAC;QAE7F,MAAM,MAAM,GAAW,KAAK,CAAC,MAAM,CAAC;QACpC,KAAK,CAAC,MAAM,GAAG,EAAE,CAAC;QAClB,OAAO,MAAM,CAAC;IAChB,CAAC;CACF;AA5ED,4DA4EC","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 { AnsiEscape } from './AnsiEscape';\nimport { TextRewriter, type TextRewriterState } from './TextRewriter';\n\nenum State {\n // Buffer is empty, and we're looking for the ESC character\n Start,\n // We're looking for the '[' character\n AwaitingBracket,\n // We're reading the codes after the '[' character\n ReadingCodes\n}\n\ninterface IRemoveColorsTextRewriterState extends TextRewriterState {\n buffer: string;\n parseState: State;\n}\n\n/**\n * For use with {@link TextRewriterTransform}, this rewriter removes ANSI escape codes\n * including colored text.\n *\n * @remarks\n * The implementation also removes other ANSI escape codes such as cursor positioning.\n * The specific set of affected codes may be adjusted in the future.\n *\n * @public\n */\nexport class RemoveColorsTextRewriter extends TextRewriter {\n public initialize(): TextRewriterState {\n return { buffer: '', parseState: State.Start } as IRemoveColorsTextRewriterState;\n }\n\n public process(unknownState: TextRewriterState, text: string): string {\n const state: IRemoveColorsTextRewriterState = unknownState as IRemoveColorsTextRewriterState;\n\n // We will be matching AnsiEscape._csiRegExp:\n //\n // /\\x1b\\[([\\x30-\\x3f]*[\\x20-\\x2f]*[\\x40-\\x7e])/gu\n //\n const ESC: string = '\\x1b';\n\n let result: string = '';\n let index: number = 0;\n\n while (index < text.length) {\n if (state.parseState === State.Start) {\n // The buffer is empty, which means we haven't found anything yet\n\n const csiIndex: number = text.indexOf(ESC, index);\n if (csiIndex < 0) {\n // We reached the end of \"text\" without finding another CSI prefix\n result += text.substring(index);\n break;\n }\n\n // Append everything up to the CSI prefix\n result += text.substring(index, csiIndex);\n\n // Save the partial match in the buffer\n state.buffer = ESC;\n index = csiIndex + 1;\n state.parseState = State.AwaitingBracket;\n } else {\n // The buffer has characters, which means we started matching a partial sequence\n\n // Read another character into the buffer\n const c: string = text[index];\n ++index;\n state.buffer += c;\n\n if (state.parseState === State.AwaitingBracket) {\n if (c === '[') {\n state.parseState = State.ReadingCodes;\n } else {\n // Failed to match, so append the buffer and start over\n result += state.buffer;\n state.buffer = '';\n state.parseState = State.Start;\n }\n } else {\n // state.state === State.ReadingCodes\n\n // Stop when we reach any character that is not [\\x30-\\x3f] or [\\x20-\\x2f]\n const code: number = c.charCodeAt(0);\n if (code < 0x20 || code > 0x3f) {\n result += AnsiEscape.removeCodes(state.buffer);\n state.buffer = '';\n state.parseState = State.Start;\n }\n }\n }\n }\n\n return result;\n }\n\n public close(unknownState: TextRewriterState): string {\n const state: IRemoveColorsTextRewriterState = unknownState as IRemoveColorsTextRewriterState;\n\n const result: string = state.buffer;\n state.buffer = '';\n return result;\n }\n}\n"]}
@@ -0,0 +1,63 @@
1
+ import { type ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';
2
+ /**
3
+ * @beta
4
+ */
5
+ export interface IStringBufferOutputOptions {
6
+ /**
7
+ * If set to true, special characters like \\n, \\r, and the \\u001b character
8
+ * in color control tokens will get normalized to [-n-], [-r-], and [-x-] respectively
9
+ *
10
+ * This option defaults to `true`
11
+ */
12
+ normalizeSpecialCharacters: boolean;
13
+ }
14
+ /**
15
+ * Terminal provider that stores written data in buffers separated by severity.
16
+ * This terminal provider is designed to be used when code that prints to a terminal
17
+ * is being unit tested.
18
+ *
19
+ * @beta
20
+ */
21
+ export declare class StringBufferTerminalProvider implements ITerminalProvider {
22
+ private _standardBuffer;
23
+ private _verboseBuffer;
24
+ private _debugBuffer;
25
+ private _warningBuffer;
26
+ private _errorBuffer;
27
+ private _supportsColor;
28
+ constructor(supportsColor?: boolean);
29
+ /**
30
+ * {@inheritDoc ITerminalProvider.write}
31
+ */
32
+ write(data: string, severity: TerminalProviderSeverity): void;
33
+ /**
34
+ * {@inheritDoc ITerminalProvider.eolCharacter}
35
+ */
36
+ get eolCharacter(): string;
37
+ /**
38
+ * {@inheritDoc ITerminalProvider.supportsColor}
39
+ */
40
+ get supportsColor(): boolean;
41
+ /**
42
+ * Get everything that has been written at log-level severity.
43
+ */
44
+ getOutput(options?: IStringBufferOutputOptions): string;
45
+ /**
46
+ * Get everything that has been written at verbose-level severity.
47
+ */
48
+ getVerbose(options?: IStringBufferOutputOptions): string;
49
+ /**
50
+ * Get everything that has been written at debug-level severity.
51
+ */
52
+ getDebugOutput(options?: IStringBufferOutputOptions): string;
53
+ /**
54
+ * Get everything that has been written at error-level severity.
55
+ */
56
+ getErrorOutput(options?: IStringBufferOutputOptions): string;
57
+ /**
58
+ * Get everything that has been written at warning-level severity.
59
+ */
60
+ getWarningOutput(options?: IStringBufferOutputOptions): string;
61
+ private _normalizeOutput;
62
+ }
63
+ //# sourceMappingURL=StringBufferTerminalProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StringBufferTerminalProvider.d.ts","sourceRoot":"","sources":["../src/StringBufferTerminalProvider.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAGvF;;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"}
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ // Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
3
+ // See LICENSE in the project root for license information.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.StringBufferTerminalProvider = void 0;
6
+ const node_core_library_1 = require("@rushstack/node-core-library");
7
+ const ITerminalProvider_1 = require("./ITerminalProvider");
8
+ const AnsiEscape_1 = require("./AnsiEscape");
9
+ /**
10
+ * Terminal provider that stores written data in buffers separated by severity.
11
+ * This terminal provider is designed to be used when code that prints to a terminal
12
+ * is being unit tested.
13
+ *
14
+ * @beta
15
+ */
16
+ class StringBufferTerminalProvider {
17
+ constructor(supportsColor = false) {
18
+ this._standardBuffer = new node_core_library_1.StringBuilder();
19
+ this._verboseBuffer = new node_core_library_1.StringBuilder();
20
+ this._debugBuffer = new node_core_library_1.StringBuilder();
21
+ this._warningBuffer = new node_core_library_1.StringBuilder();
22
+ this._errorBuffer = new node_core_library_1.StringBuilder();
23
+ this._supportsColor = supportsColor;
24
+ }
25
+ /**
26
+ * {@inheritDoc ITerminalProvider.write}
27
+ */
28
+ write(data, severity) {
29
+ switch (severity) {
30
+ case ITerminalProvider_1.TerminalProviderSeverity.warning: {
31
+ this._warningBuffer.append(data);
32
+ break;
33
+ }
34
+ case ITerminalProvider_1.TerminalProviderSeverity.error: {
35
+ this._errorBuffer.append(data);
36
+ break;
37
+ }
38
+ case ITerminalProvider_1.TerminalProviderSeverity.verbose: {
39
+ this._verboseBuffer.append(data);
40
+ break;
41
+ }
42
+ case ITerminalProvider_1.TerminalProviderSeverity.debug: {
43
+ this._debugBuffer.append(data);
44
+ break;
45
+ }
46
+ case ITerminalProvider_1.TerminalProviderSeverity.log:
47
+ default: {
48
+ this._standardBuffer.append(data);
49
+ break;
50
+ }
51
+ }
52
+ }
53
+ /**
54
+ * {@inheritDoc ITerminalProvider.eolCharacter}
55
+ */
56
+ get eolCharacter() {
57
+ return '[n]';
58
+ }
59
+ /**
60
+ * {@inheritDoc ITerminalProvider.supportsColor}
61
+ */
62
+ get supportsColor() {
63
+ return this._supportsColor;
64
+ }
65
+ /**
66
+ * Get everything that has been written at log-level severity.
67
+ */
68
+ getOutput(options) {
69
+ return this._normalizeOutput(this._standardBuffer.toString(), options);
70
+ }
71
+ /**
72
+ * Get everything that has been written at verbose-level severity.
73
+ */
74
+ getVerbose(options) {
75
+ return this._normalizeOutput(this._verboseBuffer.toString(), options);
76
+ }
77
+ /**
78
+ * Get everything that has been written at debug-level severity.
79
+ */
80
+ getDebugOutput(options) {
81
+ return this._normalizeOutput(this._debugBuffer.toString(), options);
82
+ }
83
+ /**
84
+ * Get everything that has been written at error-level severity.
85
+ */
86
+ getErrorOutput(options) {
87
+ return this._normalizeOutput(this._errorBuffer.toString(), options);
88
+ }
89
+ /**
90
+ * Get everything that has been written at warning-level severity.
91
+ */
92
+ getWarningOutput(options) {
93
+ return this._normalizeOutput(this._warningBuffer.toString(), options);
94
+ }
95
+ _normalizeOutput(s, options) {
96
+ options = Object.assign({ normalizeSpecialCharacters: true }, (options || {}));
97
+ s = node_core_library_1.Text.convertToLf(s);
98
+ if (options.normalizeSpecialCharacters) {
99
+ return AnsiEscape_1.AnsiEscape.formatForTests(s, { encodeNewlines: true });
100
+ }
101
+ else {
102
+ return s;
103
+ }
104
+ }
105
+ }
106
+ exports.StringBufferTerminalProvider = StringBufferTerminalProvider;
107
+ //# sourceMappingURL=StringBufferTerminalProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StringBufferTerminalProvider.js","sourceRoot":"","sources":["../src/StringBufferTerminalProvider.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;AAE3D,oEAAmE;AACnE,2DAAuF;AACvF,6CAA0C;AAe1C;;;;;;GAMG;AACH,MAAa,4BAA4B;IASvC,YAAmB,gBAAyB,KAAK;QARzC,oBAAe,GAAkB,IAAI,iCAAa,EAAE,CAAC;QACrD,mBAAc,GAAkB,IAAI,iCAAa,EAAE,CAAC;QACpD,iBAAY,GAAkB,IAAI,iCAAa,EAAE,CAAC;QAClD,mBAAc,GAAkB,IAAI,iCAAa,EAAE,CAAC;QACpD,iBAAY,GAAkB,IAAI,iCAAa,EAAE,CAAC;QAKxD,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;IACtC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAY,EAAE,QAAkC;QAC3D,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,4CAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;gBACtC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBACjC,MAAM;YACR,CAAC;YAED,KAAK,4CAAwB,CAAC,KAAK,CAAC,CAAC,CAAC;gBACpC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;gBAC/B,MAAM;YACR,CAAC;YAED,KAAK,4CAAwB,CAAC,OAAO,CAAC,CAAC,CAAC;gBACtC,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC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gBAAgB,CAAC,CAAS,EAAE,OAA+C;QACjF,OAAO,mBACL,0BAA0B,EAAE,IAAI,IAE7B,CAAC,OAAO,IAAI,EAAE,CAAC,CACnB,CAAC;QAEF,CAAC,GAAG,wBAAI,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC;QAExB,IAAI,OAAO,CAAC,0BAA0B,EAAE,CAAC;YACvC,OAAO,uBAAU,CAAC,cAAc,CAAC,CAAC,EAAE,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;QAChE,CAAC;aAAM,CAAC;YACN,OAAO,CAAC,CAAC;QACX,CAAC;IACH,CAAC;CACF;AA9GD,oEA8GC","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 { StringBuilder, Text } from '@rushstack/node-core-library';\nimport { type ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider';\nimport { AnsiEscape } from './AnsiEscape';\n\n/**\n * @beta\n */\nexport interface IStringBufferOutputOptions {\n /**\n * If set to true, special characters like \\\\n, \\\\r, and the \\\\u001b character\n * in color control tokens will get normalized to [-n-], [-r-], and [-x-] respectively\n *\n * This option defaults to `true`\n */\n normalizeSpecialCharacters: boolean;\n}\n\n/**\n * Terminal provider that stores written data in buffers separated by severity.\n * This terminal provider is designed to be used when code that prints to a terminal\n * is being unit tested.\n *\n * @beta\n */\nexport class StringBufferTerminalProvider implements ITerminalProvider {\n private _standardBuffer: StringBuilder = new StringBuilder();\n private _verboseBuffer: StringBuilder = new StringBuilder();\n private _debugBuffer: StringBuilder = new StringBuilder();\n private _warningBuffer: StringBuilder = new StringBuilder();\n private _errorBuffer: StringBuilder = new StringBuilder();\n\n private _supportsColor: boolean;\n\n public constructor(supportsColor: boolean = false) {\n this._supportsColor = supportsColor;\n }\n\n /**\n * {@inheritDoc ITerminalProvider.write}\n */\n public write(data: string, severity: TerminalProviderSeverity): void {\n switch (severity) {\n case TerminalProviderSeverity.warning: {\n this._warningBuffer.append(data);\n break;\n }\n\n case TerminalProviderSeverity.error: {\n this._errorBuffer.append(data);\n break;\n }\n\n case TerminalProviderSeverity.verbose: {\n this._verboseBuffer.append(data);\n break;\n }\n\n case TerminalProviderSeverity.debug: {\n this._debugBuffer.append(data);\n break;\n }\n\n case TerminalProviderSeverity.log:\n default: {\n this._standardBuffer.append(data);\n break;\n }\n }\n }\n\n /**\n * {@inheritDoc ITerminalProvider.eolCharacter}\n */\n public get eolCharacter(): string {\n return '[n]';\n }\n\n /**\n * {@inheritDoc ITerminalProvider.supportsColor}\n */\n public get supportsColor(): boolean {\n return this._supportsColor;\n }\n\n /**\n * Get everything that has been written at log-level severity.\n */\n public getOutput(options?: IStringBufferOutputOptions): string {\n return this._normalizeOutput(this._standardBuffer.toString(), options);\n }\n\n /**\n * Get everything that has been written at verbose-level severity.\n */\n public getVerbose(options?: IStringBufferOutputOptions): string {\n return this._normalizeOutput(this._verboseBuffer.toString(), options);\n }\n\n /**\n * Get everything that has been written at debug-level severity.\n */\n public getDebugOutput(options?: IStringBufferOutputOptions): string {\n return this._normalizeOutput(this._debugBuffer.toString(), options);\n }\n\n /**\n * Get everything that has been written at error-level severity.\n */\n public getErrorOutput(options?: IStringBufferOutputOptions): string {\n return this._normalizeOutput(this._errorBuffer.toString(), options);\n }\n\n /**\n * Get everything that has been written at warning-level severity.\n */\n public getWarningOutput(options?: IStringBufferOutputOptions): string {\n return this._normalizeOutput(this._warningBuffer.toString(), options);\n }\n\n private _normalizeOutput(s: string, options: IStringBufferOutputOptions | undefined): string {\n options = {\n normalizeSpecialCharacters: true,\n\n ...(options || {})\n };\n\n s = Text.convertToLf(s);\n\n if (options.normalizeSpecialCharacters) {\n return AnsiEscape.formatForTests(s, { encodeNewlines: true });\n } else {\n return s;\n }\n }\n}\n"]}