MCPcopy
hub / github.com/codeaashu/claude-code / renderToScreen

Function renderToScreen

src/ink/render-to-screen.ts:59–139  ·  view source on GitHub ↗
(
  el: ReactElement,
  width: number,
)

Source from the content-addressed store, hash-verified

57 *
58 * Unmounts between calls. Root/container/pools persist for reuse. */
59export function renderToScreen(
60 el: ReactElement,
61 width: number,
62): { screen: Screen; height: number } {
63 if (!root) {
64 root = createNode('ink-root')
65 root.focusManager = new FocusManager(() => false)
66 stylePool = new StylePool()
67 charPool = new CharPool()
68 hyperlinkPool = new HyperlinkPool()
69 // @ts-expect-error react-reconciler 0.33 takes 10 args; @types says 11
70 container = reconciler.createContainer(
71 root,
72 LegacyRoot,
73 null,
74 false,
75 null,
76 'search-render',
77 noop,
78 noop,
79 noop,
80 noop,
81 )
82 }
83
84 const t0 = performance.now()
85 // @ts-expect-error updateContainerSync exists but not in @types
86 reconciler.updateContainerSync(el, container, null, noop)
87 // @ts-expect-error flushSyncWork exists but not in @types
88 reconciler.flushSyncWork()
89 const t1 = performance.now()
90
91 // Yoga layout. Root might not have a yogaNode if the tree is empty.
92 root.yogaNode?.setWidth(width)
93 root.yogaNode?.calculateLayout(width)
94 const height = Math.ceil(root.yogaNode?.getComputedHeight() ?? 0)
95 const t2 = performance.now()
96
97 // Paint to a fresh Screen. Width = given, height = yoga's natural.
98 // No alt-screen, no prevScreen (every call is fresh).
99 const screen = createScreen(
100 width,
101 Math.max(1, height), // avoid 0-height Screen (createScreen may choke)
102 stylePool!,
103 charPool!,
104 hyperlinkPool!,
105 )
106 if (!output) {
107 output = new Output({ width, height, stylePool: stylePool!, screen })
108 } else {
109 output.reset(width, height, screen)
110 }
111 resetLayoutShifted()
112 renderNodeToOutput(root, output, { prevScreen: undefined })
113 // renderNodeToOutput queues writes into Output; .get() flushes the
114 // queue into the Screen's cell arrays. Without this the screen is
115 // blank (constructor-zero).
116 const rendered = output.get()

Callers

nothing calls this directly

Calls 11

createNodeFunction · 0.85
createScreenFunction · 0.85
resetLayoutShiftedFunction · 0.85
renderNodeToOutputFunction · 0.85
logForDebuggingFunction · 0.85
maxMethod · 0.80
resetMethod · 0.65
getMethod · 0.65
setWidthMethod · 0.45
calculateLayoutMethod · 0.45
getComputedHeightMethod · 0.45

Tested by

no test coverage detected