| 128 | * Like react-dom's createRoot — call root.render() to mount a tree. |
| 129 | */ |
| 130 | export async function createRoot({ |
| 131 | stdout = process.stdout, |
| 132 | stdin = process.stdin, |
| 133 | stderr = process.stderr, |
| 134 | exitOnCtrlC = true, |
| 135 | patchConsole = true, |
| 136 | onFrame, |
| 137 | }: RenderOptions = {}): Promise<Root> { |
| 138 | // See wrappedRender — preserve microtask boundary from the old WASM await. |
| 139 | await Promise.resolve() |
| 140 | const instance = new Ink({ |
| 141 | stdout, |
| 142 | stdin, |
| 143 | stderr, |
| 144 | exitOnCtrlC, |
| 145 | patchConsole, |
| 146 | onFrame, |
| 147 | }) |
| 148 | |
| 149 | // Register in the instances map so that code that looks up the Ink |
| 150 | // instance by stdout (e.g. external editor pause/resume) can find it. |
| 151 | instances.set(stdout, instance) |
| 152 | |
| 153 | return { |
| 154 | render: node => instance.render(node), |
| 155 | unmount: () => instance.unmount(), |
| 156 | waitUntilExit: () => instance.waitUntilExit(), |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | const getOptions = ( |
| 161 | stdout: NodeJS.WriteStream | RenderOptions | undefined = {}, |