eo-typewriterjs / StringRenderer
Class: StringRenderer
Defined in: renderers/string/string-renderer.ts:18
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
new StringRenderer(): StringRenderer;Returns
StringRenderer
Methods
mount()
mount(state): void;Defined in: renderers/string/string-renderer.ts:27
Parameters
| Parameter | Type | Description |
|---|---|---|
state | TTypewriterState | The initial typewriter state |
Returns
void
Description
Capture the initial state on mount
Implementation of
render()
render(state): void;Defined in: renderers/string/string-renderer.ts:37
Parameters
| Parameter | Type | Description |
|---|---|---|
state | TTypewriterState | The current typewriter state |
Returns
void
Description
Store the latest typewriter state
Implementation of
toString()
toString(): string;Defined in: renderers/string/string-renderer.ts:47
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()
toAnsiString(): string;Defined in: renderers/string/string-renderer.ts:60
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. 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.