@rushstack/terminal 0.7.24 → 0.8.1

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 +8 -5
@@ -8,9 +8,37 @@
8
8
  * @packageDocumentation
9
9
  */
10
10
 
11
+ /// <reference types="node" />
12
+
11
13
  import type { Brand } from '@rushstack/node-core-library';
12
- import type { ITerminal } from '@rushstack/node-core-library';
13
14
  import { NewlineKind } from '@rushstack/node-core-library';
15
+ import { Writable } from 'stream';
16
+ import { WritableOptions } from 'stream';
17
+
18
+ /**
19
+ * Operations for working with text strings that contain
20
+ * {@link https://en.wikipedia.org/wiki/ANSI_escape_code | ANSI escape codes}.
21
+ * The most commonly used escape codes set the foreground/background color for console output.
22
+ * @public
23
+ */
24
+ export declare class AnsiEscape {
25
+ private static readonly _csiRegExp;
26
+ private static readonly _sgrRegExp;
27
+ private static readonly _backslashNRegExp;
28
+ private static readonly _backslashRRegExp;
29
+ static getEscapeSequenceForAnsiCode(code: number): string;
30
+ /**
31
+ * Returns the input text with all ANSI escape codes removed. For example, this is useful when saving
32
+ * colorized console output to a log file.
33
+ */
34
+ static removeCodes(text: string): string;
35
+ /**
36
+ * Replaces ANSI escape codes with human-readable tokens. This is useful for unit tests
37
+ * that compare text strings in test assertions or snapshot files.
38
+ */
39
+ static formatForTests(text: string, options?: IAnsiEscapeConvertForTestsOptions): string;
40
+ private static _tryGetSgrFriendlyName;
41
+ }
14
42
 
15
43
  /**
16
44
  * This class enables very basic {@link TerminalWritable.onWriteChunk} operations to be implemented
@@ -32,6 +60,82 @@ export declare class CallbackWritable extends TerminalWritable {
32
60
  protected onWriteChunk(chunk: ITerminalChunk): void;
33
61
  }
34
62
 
63
+ /**
64
+ * The static functions on this class are used to produce colored text
65
+ * for use with a terminal that supports ANSI escape codes.
66
+ *
67
+ * Note that this API always generates color codes, regardless of whether
68
+ * the process's stdout is a TTY. The reason is that, in a complex program, the
69
+ * code that is generating strings often does not know were those strings will end
70
+ * up. In some cases, the same log message may get printed both to a shell
71
+ * that supports color AND to a log file that does not.
72
+ *
73
+ * @example
74
+ * ```ts
75
+ * console.log(Colorize.red('Red Text!'))
76
+ * terminal.writeLine(Colorize.green('Green Text!'), ' ', Colorize.blue('Blue Text!'));
77
+ *```
78
+ *
79
+ * @public
80
+ */
81
+ export declare class Colorize {
82
+ static black(text: string): string;
83
+ static red(text: string): string;
84
+ static green(text: string): string;
85
+ static yellow(text: string): string;
86
+ static blue(text: string): string;
87
+ static magenta(text: string): string;
88
+ static cyan(text: string): string;
89
+ static white(text: string): string;
90
+ static gray(text: string): string;
91
+ static blackBackground(text: string): string;
92
+ static redBackground(text: string): string;
93
+ static greenBackground(text: string): string;
94
+ static yellowBackground(text: string): string;
95
+ static blueBackground(text: string): string;
96
+ static magentaBackground(text: string): string;
97
+ static cyanBackground(text: string): string;
98
+ static whiteBackground(text: string): string;
99
+ static grayBackground(text: string): string;
100
+ static bold(text: string): string;
101
+ static dim(text: string): string;
102
+ static underline(text: string): string;
103
+ static blink(text: string): string;
104
+ static invertColor(text: string): string;
105
+ static hidden(text: string): string;
106
+ private static _wrapTextInAnsiEscapeCodes;
107
+ }
108
+
109
+ /**
110
+ * Terminal provider that prints to STDOUT (for log- and verbose-level messages) and
111
+ * STDERR (for warning- and error-level messsages).
112
+ *
113
+ * @beta
114
+ */
115
+ export declare class ConsoleTerminalProvider implements ITerminalProvider {
116
+ /**
117
+ * If true, verbose-level messages should be written to the console.
118
+ */
119
+ verboseEnabled: boolean;
120
+ /**
121
+ * If true, debug-level messages should be written to the console.
122
+ */
123
+ debugEnabled: boolean;
124
+ constructor(options?: Partial<IConsoleTerminalProviderOptions>);
125
+ /**
126
+ * {@inheritDoc ITerminalProvider.write}
127
+ */
128
+ write(data: string, severity: TerminalProviderSeverity): void;
129
+ /**
130
+ * {@inheritDoc ITerminalProvider.eolCharacter}
131
+ */
132
+ get eolCharacter(): string;
133
+ /**
134
+ * {@inheritDoc ITerminalProvider.supportsColor}
135
+ */
136
+ get supportsColor(): boolean;
137
+ }
138
+
35
139
  /**
36
140
  * A sensible fallback column width for consoles.
37
141
  *
@@ -85,6 +189,17 @@ export declare class DiscardStdoutTransform extends TerminalTransform {
85
189
  protected onWriteChunk(chunk: ITerminalChunk): void;
86
190
  }
87
191
 
192
+ /**
193
+ * Options for {@link AnsiEscape.formatForTests}.
194
+ * @public
195
+ */
196
+ export declare interface IAnsiEscapeConvertForTestsOptions {
197
+ /**
198
+ * If true then `\n` will be replaced by `[n]`, and `\r` will be replaced by `[r]`.
199
+ */
200
+ encodeNewlines?: boolean;
201
+ }
202
+
88
203
  /**
89
204
  * Constructor options for {@link CallbackWritable}.
90
205
  * @public
@@ -93,6 +208,24 @@ export declare interface ICallbackWritableOptions {
93
208
  onWriteChunk: (chunk: ITerminalChunk) => void;
94
209
  }
95
210
 
211
+ /**
212
+ * Options to be provided to a {@link ConsoleTerminalProvider}
213
+ *
214
+ * @beta
215
+ */
216
+ export declare interface IConsoleTerminalProviderOptions {
217
+ /**
218
+ * If true, print verbose logging messages.
219
+ */
220
+ verboseEnabled: boolean;
221
+ /**
222
+ * If true, print debug logging messages. Note that "verbose" and "debug" are considered
223
+ * separate message filters; if you want debug to imply verbose, it is up to your
224
+ * application code to enforce that.
225
+ */
226
+ debugEnabled: boolean;
227
+ }
228
+
96
229
  /**
97
230
  * Constructor options for {@link DiscardStdoutTransform}
98
231
  *
@@ -101,6 +234,19 @@ export declare interface ICallbackWritableOptions {
101
234
  export declare interface IDiscardStdoutTransformOptions extends ITerminalTransformOptions {
102
235
  }
103
236
 
237
+ /**
238
+ * Options for {@link PrefixProxyTerminalProvider}.
239
+ *
240
+ * @beta
241
+ */
242
+ export declare interface IDynamicPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {
243
+ /**
244
+ * A function that returns the prefix that should be added to each line of output. This is useful
245
+ * for prefixing each line with a timestamp.
246
+ */
247
+ getPrefix: () => string;
248
+ }
249
+
104
250
  /**
105
251
  * Constructor options for {@link NormalizeNewlinesTextRewriter}
106
252
  *
@@ -122,6 +268,21 @@ export declare interface INormalizeNewlinesTextRewriterOptions {
122
268
  ensureNewlineAtEnd?: boolean;
123
269
  }
124
270
 
271
+ /**
272
+ * @beta
273
+ */
274
+ export declare type IPrefixProxyTerminalProviderOptions = IStaticPrefixProxyTerminalProviderOptions | IDynamicPrefixProxyTerminalProviderOptions;
275
+
276
+ /**
277
+ * @beta
278
+ */
279
+ export declare interface IPrefixProxyTerminalProviderOptionsBase {
280
+ /**
281
+ * The {@link ITerminalProvider} that will be wrapped.
282
+ */
283
+ terminalProvider: ITerminalProvider;
284
+ }
285
+
125
286
  /**
126
287
  * Constructor options for {@link SplitterTransform}.
127
288
  *
@@ -134,6 +295,18 @@ export declare interface ISplitterTransformOptions extends ITerminalWritableOpti
134
295
  destinations: TerminalWritable[];
135
296
  }
136
297
 
298
+ /**
299
+ * Options for {@link PrefixProxyTerminalProvider}, with a static prefix.
300
+ *
301
+ * @beta
302
+ */
303
+ export declare interface IStaticPrefixProxyTerminalProviderOptions extends IPrefixProxyTerminalProviderOptionsBase {
304
+ /**
305
+ * The prefix that should be added to each line of output.
306
+ */
307
+ prefix: string;
308
+ }
309
+
137
310
  /**
138
311
  * Constructor options for {@link StderrLineTransform}
139
312
  * @beta
@@ -162,6 +335,85 @@ export declare interface IStdioSummarizerOptions {
162
335
  trailingLines?: number;
163
336
  }
164
337
 
338
+ /**
339
+ * @beta
340
+ */
341
+ export declare interface IStringBufferOutputOptions {
342
+ /**
343
+ * If set to true, special characters like \\n, \\r, and the \\u001b character
344
+ * in color control tokens will get normalized to [-n-], [-r-], and [-x-] respectively
345
+ *
346
+ * This option defaults to `true`
347
+ */
348
+ normalizeSpecialCharacters: boolean;
349
+ }
350
+
351
+ /**
352
+ * @beta
353
+ */
354
+ export declare interface ITerminal {
355
+ /**
356
+ * Subscribe a new terminal provider.
357
+ */
358
+ registerProvider(provider: ITerminalProvider): void;
359
+ /**
360
+ * Unsubscribe a terminal provider. If the provider isn't subscribed, this function does nothing.
361
+ */
362
+ unregisterProvider(provider: ITerminalProvider): void;
363
+ /**
364
+ * Write a generic message to the terminal
365
+ */
366
+ write(...messageParts: TerminalWriteParameters): void;
367
+ /**
368
+ * Write a generic message to the terminal, followed by a newline
369
+ */
370
+ writeLine(...messageParts: TerminalWriteParameters): void;
371
+ /**
372
+ * Write a warning message to the console with yellow text.
373
+ *
374
+ * @remarks
375
+ * The yellow color takes precedence over any other foreground colors set.
376
+ */
377
+ writeWarning(...messageParts: TerminalWriteParameters): void;
378
+ /**
379
+ * Write a warning message to the console with yellow text, followed by a newline.
380
+ *
381
+ * @remarks
382
+ * The yellow color takes precedence over any other foreground colors set.
383
+ */
384
+ writeWarningLine(...messageParts: TerminalWriteParameters): void;
385
+ /**
386
+ * Write an error message to the console with red text.
387
+ *
388
+ * @remarks
389
+ * The red color takes precedence over any other foreground colors set.
390
+ */
391
+ writeError(...messageParts: TerminalWriteParameters): void;
392
+ /**
393
+ * Write an error message to the console with red text, followed by a newline.
394
+ *
395
+ * @remarks
396
+ * The red color takes precedence over any other foreground colors set.
397
+ */
398
+ writeErrorLine(...messageParts: TerminalWriteParameters): void;
399
+ /**
400
+ * Write a verbose-level message.
401
+ */
402
+ writeVerbose(...messageParts: TerminalWriteParameters): void;
403
+ /**
404
+ * Write a verbose-level message followed by a newline.
405
+ */
406
+ writeVerboseLine(...messageParts: TerminalWriteParameters): void;
407
+ /**
408
+ * Write a debug-level message.
409
+ */
410
+ writeDebug(...messageParts: TerminalWriteParameters): void;
411
+ /**
412
+ * Write a debug-level message followed by a newline.
413
+ */
414
+ writeDebugLine(...messageParts: TerminalWriteParameters): void;
415
+ }
416
+
165
417
  /**
166
418
  * Represents a chunk of output that will ultimately be written to a {@link TerminalWritable}.
167
419
  *
@@ -193,6 +445,55 @@ export declare interface ITerminalChunk {
193
445
  text: string;
194
446
  }
195
447
 
448
+ /**
449
+ * Implement the interface to create a terminal provider. Terminal providers
450
+ * can be registered to a {@link Terminal} instance to receive messages.
451
+ *
452
+ * @beta
453
+ */
454
+ export declare interface ITerminalProvider {
455
+ /**
456
+ * This property should return true only if the terminal provider supports
457
+ * rendering console colors.
458
+ */
459
+ supportsColor: boolean;
460
+ /**
461
+ * This property should return the newline character the terminal provider
462
+ * expects.
463
+ */
464
+ eolCharacter: string;
465
+ /**
466
+ * This function gets called on every terminal provider upon every
467
+ * message function call on the terminal instance.
468
+ *
469
+ * @param data - The terminal message.
470
+ * @param severity - The message severity. Terminal providers can
471
+ * route different kinds of messages to different streams and may choose
472
+ * to ignore verbose or debug messages.
473
+ */
474
+ write(data: string, severity: TerminalProviderSeverity): void;
475
+ }
476
+
477
+ /**
478
+ * Options for {@link TerminalStreamWritable}.
479
+ *
480
+ * @beta
481
+ */
482
+ export declare interface ITerminalStreamWritableOptions {
483
+ /**
484
+ * The {@link ITerminal} that the Writable will write to.
485
+ */
486
+ terminal: ITerminal;
487
+ /**
488
+ * The severity of the messages that will be written to the {@link ITerminal}.
489
+ */
490
+ severity: TerminalProviderSeverity;
491
+ /**
492
+ * Options for the underlying Writable.
493
+ */
494
+ writableOptions?: WritableOptions;
495
+ }
496
+
196
497
  /**
197
498
  * Constructor options for {@link TerminalTransform}.
198
499
  *
@@ -237,6 +538,17 @@ export declare interface ITerminalWritableOptions {
237
538
  preventAutoclose?: boolean;
238
539
  }
239
540
 
541
+ /**
542
+ * @beta
543
+ */
544
+ export declare interface ITerminalWriteOptions {
545
+ /**
546
+ * If set to true, SGR parameters will not be replaced by the terminal
547
+ * standard (i.e. - red for errors, yellow for warnings).
548
+ */
549
+ doNotOverrideSgrCodes?: boolean;
550
+ }
551
+
240
552
  /**
241
553
  * Constructor options for {@link TextRewriterTransform}.
242
554
  *
@@ -307,6 +619,26 @@ export declare class NormalizeNewlinesTextRewriter extends TextRewriter {
307
619
  close(unknownState: TextRewriterState): string;
308
620
  }
309
621
 
622
+ /**
623
+ * Wraps an existing {@link ITerminalProvider} that prefixes each line of output with a specified
624
+ * prefix string.
625
+ *
626
+ * @beta
627
+ */
628
+ export declare class PrefixProxyTerminalProvider implements ITerminalProvider {
629
+ private readonly _parentTerminalProvider;
630
+ private readonly _getPrefix;
631
+ private readonly _newlineRegex;
632
+ private _isOnNewline;
633
+ constructor(options: IPrefixProxyTerminalProviderOptions);
634
+ /** @override */
635
+ get supportsColor(): boolean;
636
+ /** @override */
637
+ get eolCharacter(): string;
638
+ /** @override */
639
+ write(data: string, severity: TerminalProviderSeverity): void;
640
+ }
641
+
310
642
  /**
311
643
  * A collection of utilities for printing messages to the console.
312
644
  *
@@ -531,6 +863,117 @@ export declare class StdioWritable extends TerminalWritable {
531
863
  protected onWriteChunk(chunk: ITerminalChunk): void;
532
864
  }
533
865
 
866
+ /**
867
+ * Terminal provider that stores written data in buffers separated by severity.
868
+ * This terminal provider is designed to be used when code that prints to a terminal
869
+ * is being unit tested.
870
+ *
871
+ * @beta
872
+ */
873
+ export declare class StringBufferTerminalProvider implements ITerminalProvider {
874
+ private _standardBuffer;
875
+ private _verboseBuffer;
876
+ private _debugBuffer;
877
+ private _warningBuffer;
878
+ private _errorBuffer;
879
+ private _supportsColor;
880
+ constructor(supportsColor?: boolean);
881
+ /**
882
+ * {@inheritDoc ITerminalProvider.write}
883
+ */
884
+ write(data: string, severity: TerminalProviderSeverity): void;
885
+ /**
886
+ * {@inheritDoc ITerminalProvider.eolCharacter}
887
+ */
888
+ get eolCharacter(): string;
889
+ /**
890
+ * {@inheritDoc ITerminalProvider.supportsColor}
891
+ */
892
+ get supportsColor(): boolean;
893
+ /**
894
+ * Get everything that has been written at log-level severity.
895
+ */
896
+ getOutput(options?: IStringBufferOutputOptions): string;
897
+ /**
898
+ * Get everything that has been written at verbose-level severity.
899
+ */
900
+ getVerbose(options?: IStringBufferOutputOptions): string;
901
+ /**
902
+ * Get everything that has been written at debug-level severity.
903
+ */
904
+ getDebugOutput(options?: IStringBufferOutputOptions): string;
905
+ /**
906
+ * Get everything that has been written at error-level severity.
907
+ */
908
+ getErrorOutput(options?: IStringBufferOutputOptions): string;
909
+ /**
910
+ * Get everything that has been written at warning-level severity.
911
+ */
912
+ getWarningOutput(options?: IStringBufferOutputOptions): string;
913
+ private _normalizeOutput;
914
+ }
915
+
916
+ /**
917
+ * This class facilitates writing to a console.
918
+ *
919
+ * @beta
920
+ */
921
+ export declare class Terminal implements ITerminal {
922
+ private _providers;
923
+ constructor(provider: ITerminalProvider);
924
+ /**
925
+ * {@inheritdoc ITerminal.registerProvider}
926
+ */
927
+ registerProvider(provider: ITerminalProvider): void;
928
+ /**
929
+ * {@inheritdoc ITerminal.unregisterProvider}
930
+ */
931
+ unregisterProvider(provider: ITerminalProvider): void;
932
+ /**
933
+ * {@inheritdoc ITerminal.write}
934
+ */
935
+ write(...messageParts: TerminalWriteParameters): void;
936
+ /**
937
+ * {@inheritdoc ITerminal.writeLine}
938
+ */
939
+ writeLine(...messageParts: TerminalWriteParameters): void;
940
+ /**
941
+ * {@inheritdoc ITerminal.writeWarning}
942
+ */
943
+ writeWarning(...messageParts: TerminalWriteParameters): void;
944
+ /**
945
+ * {@inheritdoc ITerminal.writeWarningLine}
946
+ */
947
+ writeWarningLine(...messageParts: TerminalWriteParameters): void;
948
+ /**
949
+ * {@inheritdoc ITerminal.writeError}
950
+ */
951
+ writeError(...messageParts: TerminalWriteParameters): void;
952
+ /**
953
+ * {@inheritdoc ITerminal.writeErrorLine}
954
+ */
955
+ writeErrorLine(...messageParts: TerminalWriteParameters): void;
956
+ /**
957
+ * {@inheritdoc ITerminal.writeVerbose}
958
+ */
959
+ writeVerbose(...messageParts: TerminalWriteParameters): void;
960
+ /**
961
+ * {@inheritdoc ITerminal.writeVerboseLine}
962
+ */
963
+ writeVerboseLine(...messageParts: TerminalWriteParameters): void;
964
+ /**
965
+ * {@inheritdoc ITerminal.writeDebug}
966
+ */
967
+ writeDebug(...messageParts: TerminalWriteParameters): void;
968
+ /**
969
+ * {@inheritdoc ITerminal.writeDebugLine}
970
+ */
971
+ writeDebugLine(...messageParts: TerminalWriteParameters): void;
972
+ private _writeSegmentsToProviders;
973
+ private _serializeLegacyColorableSequence;
974
+ private _normalizeWriteParameters;
975
+ }
976
+
534
977
  /**
535
978
  * Specifies the kind of data represented by a {@link ITerminalChunk} object.
536
979
  * @public
@@ -546,6 +989,43 @@ export declare const enum TerminalChunkKind {
546
989
  Stderr = "E"
547
990
  }
548
991
 
992
+ /**
993
+ * Similar to many popular logging packages, terminal providers support a range of message
994
+ * severities. These severities have built-in formatting defaults in the Terminal object
995
+ * (warnings are yellow, errors are red, etc.).
996
+ *
997
+ * Terminal providers may choose to suppress certain messages based on their severity,
998
+ * or to route some messages to other providers or not based on severity.
999
+ *
1000
+ * Severity | Purpose
1001
+ * --------- | -------
1002
+ * error | Build errors and fatal issues
1003
+ * warning | Not necessarily fatal, but indicate a problem the user should fix
1004
+ * log | Informational messages
1005
+ * verbose | Additional information that may not always be necessary
1006
+ * debug | Highest detail level, best used for troubleshooting information
1007
+ *
1008
+ * @beta
1009
+ */
1010
+ export declare enum TerminalProviderSeverity {
1011
+ log = 0,
1012
+ warning = 1,
1013
+ error = 2,
1014
+ verbose = 3,
1015
+ debug = 4
1016
+ }
1017
+
1018
+ /**
1019
+ * A adapter to allow writing to a provided terminal using Writable streams.
1020
+ *
1021
+ * @beta
1022
+ */
1023
+ export declare class TerminalStreamWritable extends Writable {
1024
+ private _writeMethod;
1025
+ constructor(options: ITerminalStreamWritableOptions);
1026
+ _write(chunk: string | Buffer | Uint8Array, encoding: string, callback: (error?: Error | null) => void): void;
1027
+ }
1028
+
549
1029
  /**
550
1030
  * The abstract base class for {@link TerminalWritable} objects that receive an input,
551
1031
  * transform it somehow, and then write the output to another `TerminalWritable`.
@@ -593,7 +1073,7 @@ export declare abstract class TerminalTransform extends TerminalWritable {
593
1073
  /**
594
1074
  * The abstract base class for objects that can present, route, or process text output for
595
1075
  * a console application. This output is typically prepared using
596
- * the {@link @rushstack/node-core-library#Terminal} API.
1076
+ * the {@link Terminal} API.
597
1077
  *
598
1078
  * @remarks
599
1079
  *
@@ -695,6 +1175,11 @@ export declare abstract class TerminalWritable {
695
1175
  protected onClose(): void;
696
1176
  }
697
1177
 
1178
+ /**
1179
+ * @beta
1180
+ */
1181
+ export declare type TerminalWriteParameters = string[] | [...string[], ITerminalWriteOptions];
1182
+
698
1183
  /**
699
1184
  * The abstract base class for operations that can be applied by {@link TextRewriterTransform}.
700
1185
  *
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.40.1"
8
+ "packageVersion": "7.39.1"
9
9
  }
10
10
  ]
11
11
  }
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Options for {@link AnsiEscape.formatForTests}.
3
+ * @public
4
+ */
5
+ export interface IAnsiEscapeConvertForTestsOptions {
6
+ /**
7
+ * If true then `\n` will be replaced by `[n]`, and `\r` will be replaced by `[r]`.
8
+ */
9
+ encodeNewlines?: boolean;
10
+ }
11
+ /**
12
+ * Operations for working with text strings that contain
13
+ * {@link https://en.wikipedia.org/wiki/ANSI_escape_code | ANSI escape codes}.
14
+ * The most commonly used escape codes set the foreground/background color for console output.
15
+ * @public
16
+ */
17
+ export declare class AnsiEscape {
18
+ private static readonly _csiRegExp;
19
+ private static readonly _sgrRegExp;
20
+ private static readonly _backslashNRegExp;
21
+ private static readonly _backslashRRegExp;
22
+ static getEscapeSequenceForAnsiCode(code: number): string;
23
+ /**
24
+ * Returns the input text with all ANSI escape codes removed. For example, this is useful when saving
25
+ * colorized console output to a log file.
26
+ */
27
+ static removeCodes(text: string): string;
28
+ /**
29
+ * Replaces ANSI escape codes with human-readable tokens. This is useful for unit tests
30
+ * that compare text strings in test assertions or snapshot files.
31
+ */
32
+ static formatForTests(text: string, options?: IAnsiEscapeConvertForTestsOptions): string;
33
+ private static _tryGetSgrFriendlyName;
34
+ }
35
+ //# sourceMappingURL=AnsiEscape.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AnsiEscape.d.ts","sourceRoot":"","sources":["../src/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;WAE5C,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIhE;;;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"}