@rushstack/terminal
Advanced tools
+15
-1
| # Change Log - @rushstack/terminal | ||
| This log was last generated on Sat, 06 Dec 2025 01:12:29 GMT and should not be manually modified. | ||
| This log was last generated on Wed, 07 Jan 2026 01:12:24 GMT and should not be manually modified. | ||
| ## 0.21.0 | ||
| Wed, 07 Jan 2026 01:12:24 GMT | ||
| ### Minor changes | ||
| - Add a `getAllOutputAsChunks` function to `StringBufferTerminalProvider` that returns an array of chunks that were written to the terminal provider. | ||
| ## 0.20.0 | ||
| Mon, 05 Jan 2026 16:12:49 GMT | ||
| ### Minor changes | ||
| - Add a `getAllOutput` function to `StringBufferTerminalProvider` that returns an object containing all output severities. | ||
| ## 0.19.5 | ||
@@ -6,0 +20,0 @@ Sat, 06 Dec 2025 01:12:29 GMT |
+55
-8
@@ -199,2 +199,13 @@ /** | ||
| /** | ||
| * @beta | ||
| */ | ||
| export declare interface IAllStringBufferOutput { | ||
| log: string; | ||
| warning: string; | ||
| error: string; | ||
| verbose: string; | ||
| debug: string; | ||
| } | ||
| /** | ||
| * Options for {@link AnsiEscape.formatForTests}. | ||
@@ -281,2 +292,10 @@ * @public | ||
| */ | ||
| export declare interface IOutputChunk { | ||
| text: string; | ||
| severity: TerminalProviderSeverityName; | ||
| } | ||
| /** | ||
| * @beta | ||
| */ | ||
| export declare type IPrefixProxyTerminalProviderOptions = IStaticPrefixProxyTerminalProviderOptions | IDynamicPrefixProxyTerminalProviderOptions; | ||
@@ -381,2 +400,12 @@ | ||
| */ | ||
| export declare interface IStringBufferOutputChunksOptions extends IStringBufferOutputOptions { | ||
| /** | ||
| * If true, the output will be returned as an array of lines prefixed with severity tokens. | ||
| */ | ||
| asLines?: boolean; | ||
| } | ||
| /** | ||
| * @beta | ||
| */ | ||
| export declare interface IStringBufferOutputOptions { | ||
@@ -389,3 +418,3 @@ /** | ||
| */ | ||
| normalizeSpecialCharacters: boolean; | ||
| normalizeSpecialCharacters?: boolean; | ||
| } | ||
@@ -990,3 +1019,7 @@ | ||
| private _errorBuffer; | ||
| private _supportsColor; | ||
| private _allOutputChunks; | ||
| /** | ||
| * {@inheritDoc ITerminalProvider.supportsColor} | ||
| */ | ||
| readonly supportsColor: boolean; | ||
| constructor(supportsColor?: boolean); | ||
@@ -996,3 +1029,3 @@ /** | ||
| */ | ||
| write(data: string, severity: TerminalProviderSeverity): void; | ||
| write(text: string, severity: TerminalProviderSeverity): void; | ||
| /** | ||
@@ -1003,6 +1036,2 @@ * {@inheritDoc ITerminalProvider.eolCharacter} | ||
| /** | ||
| * {@inheritDoc ITerminalProvider.supportsColor} | ||
| */ | ||
| get supportsColor(): boolean; | ||
| /** | ||
| * Get everything that has been written at log-level severity. | ||
@@ -1031,3 +1060,16 @@ */ | ||
| getWarningOutput(options?: IStringBufferOutputOptions): string; | ||
| private _normalizeOutput; | ||
| /** | ||
| * Get everything that has been written at all severity levels. | ||
| */ | ||
| getAllOutput(sparse?: false, options?: IStringBufferOutputOptions): IAllStringBufferOutput; | ||
| getAllOutput(sparse: true, options?: IStringBufferOutputOptions): Partial<IAllStringBufferOutput>; | ||
| /** | ||
| * Get everything that has been written as an array of output chunks, preserving order. | ||
| */ | ||
| getAllOutputAsChunks(options?: IStringBufferOutputChunksOptions & { | ||
| asLines?: false; | ||
| }): IOutputChunk[]; | ||
| getAllOutputAsChunks(options: IStringBufferOutputChunksOptions & { | ||
| asLines: true; | ||
| }): `[${string}] ${string}`[]; | ||
| } | ||
@@ -1137,2 +1179,7 @@ | ||
| /** | ||
| * @beta | ||
| */ | ||
| export declare type TerminalProviderSeverityName = keyof typeof TerminalProviderSeverity; | ||
| /** | ||
| * A adapter to allow writing to a provided terminal using Writable streams. | ||
@@ -1139,0 +1186,0 @@ * |
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
| "packageName": "@microsoft/api-extractor", | ||
| "packageVersion": "7.54.0" | ||
| "packageVersion": "7.55.2" | ||
| } | ||
| ] | ||
| } |
+1
-1
@@ -32,3 +32,3 @@ /// <reference types="node" preserve="true" /> | ||
| export { ConsoleTerminalProvider, type IConsoleTerminalProviderOptions } from './ConsoleTerminalProvider'; | ||
| export { StringBufferTerminalProvider, type IStringBufferOutputOptions } from './StringBufferTerminalProvider'; | ||
| export { StringBufferTerminalProvider, type IStringBufferOutputOptions, type IAllStringBufferOutput, type IOutputChunk, type IStringBufferOutputChunksOptions, type TerminalProviderSeverityName } from './StringBufferTerminalProvider'; | ||
| export { PrefixProxyTerminalProvider, type IPrefixProxyTerminalProviderOptions, type IDynamicPrefixProxyTerminalProviderOptions, type IPrefixProxyTerminalProviderOptionsBase, type IStaticPrefixProxyTerminalProviderOptions } from './PrefixProxyTerminalProvider'; | ||
@@ -35,0 +35,0 @@ export { NoOpTerminalProvider } from './NoOpTerminalProvider'; |
@@ -12,5 +12,35 @@ import { type ITerminalProvider, TerminalProviderSeverity } from './ITerminalProvider'; | ||
| */ | ||
| normalizeSpecialCharacters: boolean; | ||
| normalizeSpecialCharacters?: boolean; | ||
| } | ||
| /** | ||
| * @beta | ||
| */ | ||
| export interface IStringBufferOutputChunksOptions extends IStringBufferOutputOptions { | ||
| /** | ||
| * If true, the output will be returned as an array of lines prefixed with severity tokens. | ||
| */ | ||
| asLines?: boolean; | ||
| } | ||
| /** | ||
| * @beta | ||
| */ | ||
| export interface IAllStringBufferOutput { | ||
| log: string; | ||
| warning: string; | ||
| error: string; | ||
| verbose: string; | ||
| debug: string; | ||
| } | ||
| /** | ||
| * @beta | ||
| */ | ||
| export type TerminalProviderSeverityName = keyof typeof TerminalProviderSeverity; | ||
| /** | ||
| * @beta | ||
| */ | ||
| export interface IOutputChunk { | ||
| text: string; | ||
| severity: TerminalProviderSeverityName; | ||
| } | ||
| /** | ||
| * Terminal provider that stores written data in buffers separated by severity. | ||
@@ -28,3 +58,7 @@ * This terminal provider is designed to be used when code that prints to a terminal | ||
| private _errorBuffer; | ||
| private _supportsColor; | ||
| private _allOutputChunks; | ||
| /** | ||
| * {@inheritDoc ITerminalProvider.supportsColor} | ||
| */ | ||
| readonly supportsColor: boolean; | ||
| constructor(supportsColor?: boolean); | ||
@@ -34,3 +68,3 @@ /** | ||
| */ | ||
| write(data: string, severity: TerminalProviderSeverity): void; | ||
| write(text: string, severity: TerminalProviderSeverity): void; | ||
| /** | ||
@@ -41,6 +75,2 @@ * {@inheritDoc ITerminalProvider.eolCharacter} | ||
| /** | ||
| * {@inheritDoc ITerminalProvider.supportsColor} | ||
| */ | ||
| get supportsColor(): boolean; | ||
| /** | ||
| * Get everything that has been written at log-level severity. | ||
@@ -69,4 +99,17 @@ */ | ||
| getWarningOutput(options?: IStringBufferOutputOptions): string; | ||
| private _normalizeOutput; | ||
| /** | ||
| * Get everything that has been written at all severity levels. | ||
| */ | ||
| getAllOutput(sparse?: false, options?: IStringBufferOutputOptions): IAllStringBufferOutput; | ||
| getAllOutput(sparse: true, options?: IStringBufferOutputOptions): Partial<IAllStringBufferOutput>; | ||
| /** | ||
| * Get everything that has been written as an array of output chunks, preserving order. | ||
| */ | ||
| getAllOutputAsChunks(options?: IStringBufferOutputChunksOptions & { | ||
| asLines?: false; | ||
| }): IOutputChunk[]; | ||
| getAllOutputAsChunks(options: IStringBufferOutputChunksOptions & { | ||
| asLines: true; | ||
| }): `[${string}] ${string}`[]; | ||
| } | ||
| //# sourceMappingURL=StringBufferTerminalProvider.d.ts.map |
@@ -9,2 +9,22 @@ "use strict"; | ||
| const AnsiEscape_1 = require("./AnsiEscape"); | ||
| function _normalizeOptions(options) { | ||
| return { | ||
| normalizeSpecialCharacters: true, | ||
| ...options | ||
| }; | ||
| } | ||
| function _normalizeOutput(s, options) { | ||
| const { normalizeSpecialCharacters } = _normalizeOptions(options !== null && options !== void 0 ? options : {}); | ||
| return _normalizeOutputInner(s, normalizeSpecialCharacters); | ||
| } | ||
| function _normalizeOutputInner(s, normalizeSpecialCharacters) { | ||
| s = node_core_library_1.Text.convertToLf(s); | ||
| if (normalizeSpecialCharacters) { | ||
| return AnsiEscape_1.AnsiEscape.formatForTests(s, { encodeNewlines: true }); | ||
| } | ||
| else { | ||
| return s; | ||
| } | ||
| } | ||
| const LONGEST_SEVERITY_NAME_LENGTH = Object.keys(ITerminalProvider_1.TerminalProviderSeverity).reduce((max, k) => Math.max(max, k.length), 0); | ||
| /** | ||
@@ -24,3 +44,4 @@ * Terminal provider that stores written data in buffers separated by severity. | ||
| this._errorBuffer = new node_core_library_1.StringBuilder(); | ||
| this._supportsColor = supportsColor; | ||
| this._allOutputChunks = []; | ||
| this.supportsColor = supportsColor; | ||
| } | ||
@@ -30,18 +51,29 @@ /** | ||
| */ | ||
| write(data, severity) { | ||
| write(text, severity) { | ||
| const severityName = ITerminalProvider_1.TerminalProviderSeverity[severity]; | ||
| const lastChunk = this._allOutputChunks[this._allOutputChunks.length - 1]; | ||
| if (lastChunk && lastChunk.severity === severityName) { | ||
| lastChunk.text += text; | ||
| } | ||
| else { | ||
| this._allOutputChunks.push({ | ||
| text, | ||
| severity: severityName | ||
| }); | ||
| } | ||
| switch (severity) { | ||
| case ITerminalProvider_1.TerminalProviderSeverity.warning: { | ||
| this._warningBuffer.append(data); | ||
| this._warningBuffer.append(text); | ||
| break; | ||
| } | ||
| case ITerminalProvider_1.TerminalProviderSeverity.error: { | ||
| this._errorBuffer.append(data); | ||
| this._errorBuffer.append(text); | ||
| break; | ||
| } | ||
| case ITerminalProvider_1.TerminalProviderSeverity.verbose: { | ||
| this._verboseBuffer.append(data); | ||
| this._verboseBuffer.append(text); | ||
| break; | ||
| } | ||
| case ITerminalProvider_1.TerminalProviderSeverity.debug: { | ||
| this._debugBuffer.append(data); | ||
| this._debugBuffer.append(text); | ||
| break; | ||
@@ -51,3 +83,3 @@ } | ||
| default: { | ||
| this._standardBuffer.append(data); | ||
| this._standardBuffer.append(text); | ||
| break; | ||
@@ -64,12 +96,6 @@ } | ||
| /** | ||
| * {@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); | ||
| return _normalizeOutput(this._standardBuffer.toString(), options); | ||
| } | ||
@@ -86,3 +112,3 @@ /** | ||
| getVerboseOutput(options) { | ||
| return this._normalizeOutput(this._verboseBuffer.toString(), options); | ||
| return _normalizeOutput(this._verboseBuffer.toString(), options); | ||
| } | ||
@@ -93,3 +119,3 @@ /** | ||
| getDebugOutput(options) { | ||
| return this._normalizeOutput(this._debugBuffer.toString(), options); | ||
| return _normalizeOutput(this._debugBuffer.toString(), options); | ||
| } | ||
@@ -100,3 +126,3 @@ /** | ||
| getErrorOutput(options) { | ||
| return this._normalizeOutput(this._errorBuffer.toString(), options); | ||
| return _normalizeOutput(this._errorBuffer.toString(), options); | ||
| } | ||
@@ -107,15 +133,62 @@ /** | ||
| getWarningOutput(options) { | ||
| return this._normalizeOutput(this._warningBuffer.toString(), options); | ||
| return _normalizeOutput(this._warningBuffer.toString(), options); | ||
| } | ||
| _normalizeOutput(s, options) { | ||
| options = { | ||
| normalizeSpecialCharacters: true, | ||
| ...(options || {}) | ||
| }; | ||
| s = node_core_library_1.Text.convertToLf(s); | ||
| if (options.normalizeSpecialCharacters) { | ||
| return AnsiEscape_1.AnsiEscape.formatForTests(s, { encodeNewlines: true }); | ||
| getAllOutput(sparse, options) { | ||
| const result = {}; | ||
| const log = this.getOutput(options); | ||
| if (!sparse || log) { | ||
| result.log = log; | ||
| } | ||
| const warning = this.getWarningOutput(options); | ||
| if (!sparse || warning) { | ||
| result.warning = warning; | ||
| } | ||
| const error = this.getErrorOutput(options); | ||
| if (!sparse || error) { | ||
| result.error = error; | ||
| } | ||
| const verbose = this.getVerboseOutput(options); | ||
| if (!sparse || verbose) { | ||
| result.verbose = verbose; | ||
| } | ||
| const debug = this.getDebugOutput(options); | ||
| if (!sparse || debug) { | ||
| result.debug = debug; | ||
| } | ||
| return result; | ||
| } | ||
| getAllOutputAsChunks(options = {}) { | ||
| const { asLines, normalizeSpecialCharacters } = _normalizeOptions(options); | ||
| if (asLines) { | ||
| const lines = []; | ||
| for (const { text: rawText, severity: rawSeverity } of this._allOutputChunks) { | ||
| const severity = rawSeverity.padStart(LONGEST_SEVERITY_NAME_LENGTH, ' '); | ||
| const lfText = node_core_library_1.Text.convertToLf(rawText); | ||
| const rawLines = lfText.split('\n'); | ||
| // Emit one entry per logical line. | ||
| for (let i = 0; i < rawLines.length; i++) { | ||
| const isLast = i === rawLines.length - 1; | ||
| const isFinalTrailingEmpty = isLast && rawLines[i] === ''; | ||
| if (isFinalTrailingEmpty) { | ||
| continue; | ||
| } | ||
| const hasNewlineAfter = i < rawLines.length - 1; | ||
| // If the original output had a newline after this line, preserve it as the special token | ||
| // (e.g. "[n]") when normalization is enabled. | ||
| const shouldIncludeNewlineToken = normalizeSpecialCharacters && hasNewlineAfter; | ||
| const lineText = shouldIncludeNewlineToken ? `${rawLines[i]}\n` : rawLines[i]; | ||
| const text = _normalizeOutputInner(lineText, normalizeSpecialCharacters); | ||
| lines.push(`[${severity}] ${text}`); | ||
| } | ||
| } | ||
| return lines; | ||
| } | ||
| else { | ||
| return s; | ||
| return this._allOutputChunks.map(({ text: rawText, severity }) => { | ||
| const text = _normalizeOutputInner(rawText, normalizeSpecialCharacters); | ||
| return { | ||
| text, | ||
| severity | ||
| }; | ||
| }); | ||
| } | ||
@@ -122,0 +195,0 @@ } |
+2
-2
| { | ||
| "name": "@rushstack/terminal", | ||
| "version": "0.19.5", | ||
| "version": "0.21.0", | ||
| "description": "User interface primitives for console applications", | ||
@@ -19,3 +19,3 @@ "main": "lib/index.js", | ||
| "devDependencies": { | ||
| "@rushstack/heft": "1.1.4", | ||
| "@rushstack/heft": "1.1.7", | ||
| "@types/supports-color": "8.1.3", | ||
@@ -22,0 +22,0 @@ "eslint": "~9.37.0", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
552562
2.93%10211
1.82%