MCPcopy Create free account
hub / github.com/AnukarOP/claude-code-leaked / renderToAnsiString

Function renderToAnsiString

source code/utils/staticRender.tsx:76–109  ·  view source on GitHub ↗
(node: React.ReactNode, columns?: number)

Source from the content-addressed store, hash-verified

74 * Renders a React node to a string with ANSI escape codes (for terminal output).
75 */
76export function renderToAnsiString(node: React.ReactNode, columns?: number): Promise<string> {
77 return new Promise(async resolve => {
78 let output = '';
79
80 // Capture all writes. Set .columns so Ink (ink.tsx:~165) picks up a
81 // chosen width instead of PassThrough's undefined → 80 fallback —
82 // useful for rendering at terminal width for file dumps that should
83 // match what the user sees on screen.
84 const stream = new PassThrough();
85 if (columns !== undefined) {
86 ;
87 (stream as unknown as {
88 columns: number;
89 }).columns = columns;
90 }
91 stream.on('data', chunk => {
92 output += chunk.toString();
93 });
94
95 // Render the component wrapped in RenderOnceAndExit
96 // Non-TTY stdout (PassThrough) gives full-frame output instead of diffs
97 const instance = await render(<RenderOnceAndExit>{node}</RenderOnceAndExit>, {
98 stdout: stream as unknown as NodeJS.WriteStream,
99 patchConsole: false
100 });
101
102 // Wait for the component to exit naturally
103 await instance.waitUntilExit();
104
105 // Extract only the first frame's content to avoid duplication
106 // (Ink outputs multiple frames in non-TTY mode)
107 await resolve(extractFirstFrame(output));
108 });
109}
110
111/**
112 * Renders a React node to a plain text string (ANSI codes stripped).

Callers 3

renderToStringFunction · 0.85
renderChunkFunction · 0.85
callFunction · 0.85

Calls 5

renderFunction · 0.85
extractFirstFrameFunction · 0.85
waitUntilExitMethod · 0.80
resolveFunction · 0.70
toStringMethod · 0.65

Tested by

no test coverage detected