MCPcopy Create free account
hub / github.com/Noumena-Network/code / mountHighlightedCode

Function mountHighlightedCode

src/ink/highlightedCodePerfHarness.tsx:91–135  ·  view source on GitHub ↗
(
  code: string,
  filePath: string,
  width?: number,
)

Source from the content-addressed store, hash-verified

89}
90
91async function mountHighlightedCode(
92 code: string,
93 filePath: string,
94 width?: number,
95): Promise<MountedHighlightedCode> {
96 installReplPerfEnvironment()
97
98 const { App } = await import('../components/App.js')
99 const { HighlightedCode } = await import('../components/HighlightedCode.js')
100
101 const terminal = createFakeTerminal(140, 32)
102 const frames: FrameEvent[] = []
103 const root = await createRoot({
104 stdout: terminal.stdout,
105 stdin: terminal.stdin,
106 stderr: terminal.stderr,
107 exitOnCtrlC: false,
108 patchConsole: false,
109 onFrame: event => {
110 frames.push(event)
111 },
112 })
113
114 root.render(
115 <App getFpsMetrics={() => undefined} initialState={getDefaultAppState()}>
116 <Box width={width + 2} flexDirection="column">
117 {width === undefined ? <HighlightedCode code={code} filePath={filePath} /> : <HighlightedCode code={code} filePath={filePath} width={width} />}
118 </Box>
119 </App>,
120 )
121
122 await waitFor(
123 () => frames.length > 0,
124 'HighlightedCode never rendered a frame',
125 )
126 await waitFor(() => {
127 const ink = getMountedInkProbe(terminal)
128 return ink
129 ? readScreenText(ink.frontFrame.screen).includes('export const value_')
130 : false
131 }, 'HighlightedCode never painted the rendered file preview')
132 await Bun.sleep(120)
133
134 return { root, terminal, frames }
135}
136
137async function withPerfEnv<T>(fn: () => Promise<T>): Promise<T> {
138 const prevNoFlicker = process.env.CLAUDE_CODE_NO_FLICKER

Callers 1

Calls 9

getDefaultAppStateFunction · 0.85
getMountedInkProbeFunction · 0.85
readScreenTextFunction · 0.85
sleepMethod · 0.80
createFakeTerminalFunction · 0.70
createRootFunction · 0.70
waitForFunction · 0.70
renderMethod · 0.45

Tested by

no test coverage detected