refactor(tui): early-return simulation renderer in app.tsx
This commit is contained in:
parent
3dc36ec38b
commit
8b5f7af1b9
2 changed files with 30 additions and 21 deletions
|
|
@ -185,25 +185,24 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
|||
const renderer = yield* Effect.acquireRelease(
|
||||
Effect.tryPromise({
|
||||
try: async () => {
|
||||
const createVisibleRenderer = () =>
|
||||
createCliRenderer({
|
||||
externalOutputMode: "passthrough",
|
||||
targetFps: 60,
|
||||
gatherStats: false,
|
||||
exitOnCtrlC: false,
|
||||
useKittyKeyboard: {},
|
||||
autoFocus: false,
|
||||
openConsoleOnError: false,
|
||||
useMouse: !Flag.OPENCODE_DISABLE_MOUSE && input.config.mouse,
|
||||
consoleOptions: {
|
||||
keyBindings: [{ name: "y", ctrl: true, action: "copy-selection" }],
|
||||
},
|
||||
})
|
||||
if (process.env.OPENCODE_SIMULATION === "1" || process.env.OPENCODE_SIMULATION === "true") {
|
||||
const { Simulation } = await import("./simulation/simulation")
|
||||
return Simulation.createSimulation(createVisibleRenderer)
|
||||
return Simulation.createSimulation()
|
||||
}
|
||||
return createVisibleRenderer()
|
||||
|
||||
return createCliRenderer({
|
||||
externalOutputMode: "passthrough",
|
||||
targetFps: 60,
|
||||
gatherStats: false,
|
||||
exitOnCtrlC: false,
|
||||
useKittyKeyboard: {},
|
||||
autoFocus: false,
|
||||
openConsoleOnError: false,
|
||||
useMouse: !Flag.OPENCODE_DISABLE_MOUSE && input.config.mouse,
|
||||
consoleOptions: {
|
||||
keyBindings: [{ name: "y", ctrl: true, action: "copy-selection" }],
|
||||
},
|
||||
})
|
||||
},
|
||||
catch: (error) => (error instanceof Error ? error : new Error(String(error))),
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import type { CliRenderer } from "@opentui/core"
|
||||
import { createCliRenderer, type CliRenderer } from "@opentui/core"
|
||||
import { SimulationActions } from "./actions"
|
||||
import { SimulationRenderer } from "./renderer"
|
||||
import { SimulationServer } from "./server"
|
||||
|
|
@ -6,14 +6,24 @@ import { SimulationServer } from "./server"
|
|||
/**
|
||||
* Simulation-mode renderer entry point.
|
||||
*
|
||||
* Creates the renderer (fake when OPENCODE_SIMULATION_RENDERER=fake, the
|
||||
* normal visible renderer otherwise) and starts the simulation control
|
||||
* Creates the renderer (fake when OPENCODE_SIMULATION_RENDERER=fake, a
|
||||
* visible terminal renderer otherwise) and starts the simulation control
|
||||
* server against it. The server stops when the renderer is destroyed, so the
|
||||
* caller only manages the renderer lifecycle.
|
||||
*/
|
||||
export async function createSimulation(createVisibleRenderer: () => Promise<CliRenderer>): Promise<CliRenderer> {
|
||||
export async function createSimulation(): Promise<CliRenderer> {
|
||||
const renderer =
|
||||
process.env.OPENCODE_SIMULATION_RENDERER === "fake" ? await SimulationRenderer.create() : await createVisibleRenderer()
|
||||
process.env.OPENCODE_SIMULATION_RENDERER === "fake"
|
||||
? await SimulationRenderer.create()
|
||||
: await createCliRenderer({
|
||||
externalOutputMode: "passthrough",
|
||||
targetFps: 60,
|
||||
gatherStats: false,
|
||||
exitOnCtrlC: false,
|
||||
useKittyKeyboard: {},
|
||||
autoFocus: false,
|
||||
openConsoleOnError: false,
|
||||
})
|
||||
const server = SimulationServer.start(SimulationActions.createHarness(renderer))
|
||||
if (server) {
|
||||
process.stderr.write(`opencode simulation websocket: ${server.url}\n`)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue