refactor(tui): move fake renderer swap into single simulation block
This commit is contained in:
parent
7a76efc4f8
commit
bab30226b9
1 changed files with 36 additions and 28 deletions
|
|
@ -183,24 +183,22 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
const simulationEnabled = process.env.OPENCODE_SIMULATION === "1" || process.env.OPENCODE_SIMULATION === "true"
|
const simulationEnabled = process.env.OPENCODE_SIMULATION === "1" || process.env.OPENCODE_SIMULATION === "true"
|
||||||
const result = yield* Effect.scoped(
|
const result = yield* Effect.scoped(
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const renderer = yield* Effect.acquireRelease(
|
let renderer = yield* Effect.acquireRelease(
|
||||||
Effect.tryPromise({
|
Effect.tryPromise({
|
||||||
try: () =>
|
try: () =>
|
||||||
simulationEnabled && process.env.OPENCODE_SIMULATION_RENDERER === "fake"
|
createCliRenderer({
|
||||||
? import("./simulation/renderer").then(({ SimulationRenderer }) => SimulationRenderer.create())
|
externalOutputMode: "passthrough",
|
||||||
: createCliRenderer({
|
targetFps: 60,
|
||||||
externalOutputMode: "passthrough",
|
gatherStats: false,
|
||||||
targetFps: 60,
|
exitOnCtrlC: false,
|
||||||
gatherStats: false,
|
useKittyKeyboard: {},
|
||||||
exitOnCtrlC: false,
|
autoFocus: false,
|
||||||
useKittyKeyboard: {},
|
openConsoleOnError: false,
|
||||||
autoFocus: false,
|
useMouse: !Flag.OPENCODE_DISABLE_MOUSE && input.config.mouse,
|
||||||
openConsoleOnError: false,
|
consoleOptions: {
|
||||||
useMouse: !Flag.OPENCODE_DISABLE_MOUSE && input.config.mouse,
|
keyBindings: [{ name: "y", ctrl: true, action: "copy-selection" }],
|
||||||
consoleOptions: {
|
},
|
||||||
keyBindings: [{ name: "y", ctrl: true, action: "copy-selection" }],
|
}),
|
||||||
},
|
|
||||||
}),
|
|
||||||
catch: (error) => (error instanceof Error ? error : new Error(String(error))),
|
catch: (error) => (error instanceof Error ? error : new Error(String(error))),
|
||||||
}),
|
}),
|
||||||
(renderer) =>
|
(renderer) =>
|
||||||
|
|
@ -208,6 +206,28 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
destroyRenderer(renderer)
|
destroyRenderer(renderer)
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (simulationEnabled) {
|
||||||
|
if (process.env.OPENCODE_SIMULATION_RENDERER === "fake") {
|
||||||
|
const { SimulationRenderer } = yield* Effect.promise(() => import("./simulation/renderer"))
|
||||||
|
destroyRenderer(renderer)
|
||||||
|
renderer = yield* Effect.acquireRelease(
|
||||||
|
Effect.promise(() => SimulationRenderer.create()),
|
||||||
|
(fake) => Effect.sync(() => destroyRenderer(fake)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
const target = renderer
|
||||||
|
const simulation = yield* Effect.promise(async () => {
|
||||||
|
const { SimulationActions } = await import("./simulation/actions")
|
||||||
|
const { SimulationServer } = await import("./simulation/server")
|
||||||
|
return SimulationServer.start(SimulationActions.createHarness(target))
|
||||||
|
})
|
||||||
|
if (simulation) {
|
||||||
|
process.stderr.write(`opencode simulation websocket: ${simulation.url}\n`)
|
||||||
|
yield* Effect.addFinalizer(() => Effect.sync(() => simulation.stop()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
win32DisableProcessedInput()
|
win32DisableProcessedInput()
|
||||||
const keymap = createDefaultOpenTuiKeymap(renderer)
|
const keymap = createDefaultOpenTuiKeymap(renderer)
|
||||||
yield* Effect.acquireRelease(
|
yield* Effect.acquireRelease(
|
||||||
|
|
@ -233,18 +253,6 @@ export const run = Effect.fn("Tui.run")(function* (input: TuiInput) {
|
||||||
renderer.once("destroy", () => Deferred.doneUnsafe(shutdown, Effect.void))
|
renderer.once("destroy", () => Deferred.doneUnsafe(shutdown, Effect.void))
|
||||||
const pluginRuntime = createPluginRuntime()
|
const pluginRuntime = createPluginRuntime()
|
||||||
|
|
||||||
if (simulationEnabled) {
|
|
||||||
const simulation = yield* Effect.promise(async () => {
|
|
||||||
const { SimulationActions } = await import("./simulation/actions")
|
|
||||||
const { SimulationServer } = await import("./simulation/server")
|
|
||||||
return SimulationServer.start(SimulationActions.createHarness(renderer))
|
|
||||||
})
|
|
||||||
if (simulation) {
|
|
||||||
process.stderr.write(`opencode simulation websocket: ${simulation.url}\n`)
|
|
||||||
yield* Effect.addFinalizer(() => Effect.sync(() => simulation.stop()))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
yield* Effect.tryPromise(async () => {
|
yield* Effect.tryPromise(async () => {
|
||||||
// Prewarm palette before ThemeProvider mounts so `system` theme avoids a first-paint fallback flash.
|
// Prewarm palette before ThemeProvider mounts so `system` theme avoids a first-paint fallback flash.
|
||||||
void renderer.getPalette({ size: 16 }).catch(() => undefined)
|
void renderer.getPalette({ size: 16 }).catch(() => undefined)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue