Skip to content

eo-typewriterjs


eo-typewriterjs / StringRenderer

Class: StringRenderer ​

Defined in: renderers/string/string-renderer.ts:32

Description ​

A headless renderer that stores the latest typewriter state in memory. Useful for testing, server-side rendering, and string snapshot assertions.

toString() returns the plain text content (styles ignored). toAnsiString() applies ANSI escape sequences from text styles that provide an ansi map.

Implements ​

Constructors ​

Constructor ​

ts
new StringRenderer(): StringRenderer;

Returns ​

StringRenderer

Methods ​

mount() ​

ts
mount(state): void;

Defined in: renderers/string/string-renderer.ts:41

Parameters ​

ParameterTypeDescription
stateTTypewriterStateThe initial typewriter state

Returns ​

void

Description ​

Capture the initial state on mount

Implementation of ​

IRenderer.mount


render() ​

ts
render(state): void;

Defined in: renderers/string/string-renderer.ts:51

Parameters ​

ParameterTypeDescription
stateTTypewriterStateThe current typewriter state

Returns ​

void

Description ​

Store the latest typewriter state

Implementation of ​

IRenderer.render


toString() ​

ts
toString(): string;

Defined in: renderers/string/string-renderer.ts:61

Returns ​

string

The current document text, or an empty string if nothing has been rendered

Description ​

Return the plain text content of the current document state


toAnsiString() ​

ts
toAnsiString(): string;

Defined in: renderers/string/string-renderer.ts:76

Returns ​

string

A string with ANSI escape codes applied, or plain text if no ANSI styles are present

Description ​

Return the document text with ANSI escape sequences applied from text styles. Only styles that include an ansi map contribute escape sequences, and only values that are valid SGR parameter lists (digits separated by ;) are used. Control characters in the text itself are removed so they cannot inject escapes. Segments without any ANSI styles are emitted as plain text. The string is always terminated with the ANSI reset sequence when any styling was applied.

Released under the MIT License.