Rush StackShopBlogEvents
Skip to main content

Home > @rushstack/terminal

terminal package

This library implements a system for processing human readable text that will be output by console applications.

Remarks

See the TerminalWritable documentation for an overview of the major concepts.

Classes

Class

Description

AnsiEscape

Operations for working with text strings that contain ANSI escape codes. The most commonly used escape codes set the foreground/background color for console output.

CallbackWritable

This class enables very basic TerminalWritable.onWriteChunk() operations to be implemented as a callback function, avoiding the need to define a subclass of TerminalWritable.

Colorize

The static functions on this class are used to produce colored text for use with a terminal that supports ANSI escape codes.

Note that this API always generates color codes, regardless of whether the process's stdout is a TTY. The reason is that, in a complex program, the code that is generating strings often does not know were those strings will end up. In some cases, the same log message may get printed both to a shell that supports color AND to a log file that does not.

ConsoleTerminalProvider

(BETA) Terminal provider that prints to STDOUT (for log- and verbose-level messages) and STDERR (for warning- and error-level messages).

DiscardStdoutTransform

(BETA) DiscardStdoutTransform discards stdout chunks while fixing up malformed stderr lines.

MockWritable

(BETA) A TerminalWritable subclass for use by unit tests.

NoOpTerminalProvider

(BETA) Terminal provider that stores written data in buffers separated by severity. This terminal provider is designed to be used when code that prints to a terminal is being unit tested.

NormalizeNewlinesTextRewriter

For use with TextRewriterTransform, this rewriter converts all newlines to a standard format.

PrefixProxyTerminalProvider

(BETA) Wraps an existing ITerminalProvider that prefixes each line of output with a specified prefix string.

PrintUtilities

A collection of utilities for printing messages to the console.

ProblemCollector

(BETA) A TerminalWritable that consumes line-oriented terminal output and extracts structured problems using one or more IProblemMatcher instances.

RemoveColorsTextRewriter

For use with TextRewriterTransform, this rewriter removes ANSI escape codes including colored text.

SplitterTransform

Use this instead of TerminalTransform if you need to output ITerminalChunk data to more than one destination.

StderrLineTransform

(BETA) StderrLineTransform normalizes lines that mix characters from stdout and stderr, so that each output line is routed entirely to stdout or stderr.

StdioSummarizer

(BETA) Summarizes the results of a failed build task by returning a subset of stderr output not to exceed a specified maximum number of lines.

StdioWritable

A TerminalWritable subclass that writes its output directly to the process stdout and stderr streams.

StringBufferTerminalProvider

(BETA) Terminal provider that stores written data in buffers separated by severity. This terminal provider is designed to be used when code that prints to a terminal is being unit tested.

Terminal

(BETA) This class facilitates writing to a console.

TerminalStreamWritable

(BETA) A adapter to allow writing to a provided terminal using Writable streams.

TextRewriterTransform

A TerminalTransform subclass that performs one or more TextRewriter operations. The most common operations are NormalizeNewlinesTextRewriter and RemoveColorsTextRewriter.

Abstract Classes

Abstract Class

Description

TerminalTransform

The abstract base class for TerminalWritable objects that receive an input, transform it somehow, and then write the output to another TerminalWritable.

TerminalWritable

The abstract base class for objects that can present, route, or process text output for a console application. This output is typically prepared using the Terminal API.

TextRewriter

The abstract base class for operations that can be applied by TextRewriterTransform.

Enumerations

Enumeration

Description

TerminalChunkKind

Specifies the kind of data represented by a ITerminalChunk object.

TerminalProviderSeverity

(BETA) Similar to many popular logging packages, terminal providers support a range of message severities. These severities have built-in formatting defaults in the Terminal object (warnings are yellow, errors are red, etc.).

Terminal providers may choose to suppress certain messages based on their severity, or to route some messages to other providers or not based on severity.

Severity | Purpose --------- | ------- error | Build errors and fatal issues warning | Not necessarily fatal, but indicate a problem the user should fix log | Informational messages verbose | Additional information that may not always be necessary debug | Highest detail level, best used for troubleshooting information

Interfaces

Interface

Description

IAllStringBufferOutput

(BETA)

IAnsiEscapeConvertForTestsOptions

Options for AnsiEscape.formatForTests().

ICallbackWritableOptions

Constructor options for CallbackWritable.

IConsoleTerminalProviderOptions

(BETA) Options to be provided to a ConsoleTerminalProvider

IDiscardStdoutTransformOptions

(BETA) Constructor options for DiscardStdoutTransform

IDynamicPrefixProxyTerminalProviderOptions

(BETA) Options for PrefixProxyTerminalProvider.

INormalizeNewlinesTextRewriterOptions

Constructor options for NormalizeNewlinesTextRewriter

IOutputChunk

(BETA)

IPrefixProxyTerminalProviderOptionsBase

(BETA)

IProblemCollector

(BETA) Collects problems (errors/warnings/info) encountered during an operation.

IProblemCollectorOptions

(BETA) Constructor options for ProblemCollector.

ISplitterTransformOptions

Constructor options for SplitterTransform.

IStaticPrefixProxyTerminalProviderOptions

(BETA) Options for PrefixProxyTerminalProvider, with a static prefix.

IStdioLineTransformOptions

(BETA) Constructor options for StderrLineTransform

IStdioSummarizerOptions

(BETA) Constructor options for StdioSummarizer.

IStringBufferOutputChunksOptions

(BETA)

IStringBufferOutputOptions

(BETA)

ITerminal

(BETA)

ITerminalChunk

Represents a chunk of output that will ultimately be written to a TerminalWritable.

ITerminalProvider

(BETA) Implement the interface to create a terminal provider. Terminal providers can be registered to a Terminal instance to receive messages.

ITerminalStreamWritableOptions

(BETA) Options for TerminalStreamWritable.

ITerminalTransformOptions

Constructor options for TerminalTransform.

ITerminalWritableOptions

Constructor options for TerminalWritable

ITerminalWriteOptions

(BETA)

ITextRewriterTransformOptions

Constructor options for TextRewriterTransform.

Variables

Variable

Description

DEFAULT_CONSOLE_WIDTH

A sensible fallback column width for consoles.

Type Aliases

Type Alias

Description

IPrefixProxyTerminalProviderOptions

(BETA)

TerminalProviderSeverityName

(BETA)

TerminalWriteParameters

(BETA)

TextRewriterState

Represents the internal state of a TextRewriter subclass.