Просмотр исходного кода

fix(windows): restore /editor support on Windows (#17146)

AbigailJixiangyuyu 1 месяц назад
Родитель
Сommit
e9a17e4480

+ 16 - 12
packages/opencode/src/cli/cmd/tui/util/editor.ts

@@ -17,17 +17,21 @@ export namespace Editor {
     await Filesystem.write(filepath, opts.value)
     opts.renderer.suspend()
     opts.renderer.currentRenderBuffer.clear()
-    const parts = editor.split(" ")
-    const proc = Process.spawn([...parts, filepath], {
-      stdin: "inherit",
-      stdout: "inherit",
-      stderr: "inherit",
-    })
-    await proc.exited
-    const content = await Filesystem.readText(filepath)
-    opts.renderer.currentRenderBuffer.clear()
-    opts.renderer.resume()
-    opts.renderer.requestRender()
-    return content || undefined
+    try {
+      const parts = editor.split(" ")
+      const proc = Process.spawn([...parts, filepath], {
+        stdin: "inherit",
+        stdout: "inherit",
+        stderr: "inherit",
+        shell: process.platform === "win32",
+      })
+      await proc.exited
+      const content = await Filesystem.readText(filepath)
+      return content || undefined
+    } finally {
+      opts.renderer.currentRenderBuffer.clear()
+      opts.renderer.resume()
+      opts.renderer.requestRender()
+    }
   }
 }

+ 3 - 0
packages/opencode/src/util/process.ts

@@ -3,6 +3,7 @@ import { buffer } from "node:stream/consumers"
 
 export namespace Process {
   export type Stdio = "inherit" | "pipe" | "ignore"
+  export type Shell = boolean | string
 
   export interface Options {
     cwd?: string
@@ -10,6 +11,7 @@ export namespace Process {
     stdin?: Stdio
     stdout?: Stdio
     stderr?: Stdio
+    shell?: Shell
     abort?: AbortSignal
     kill?: NodeJS.Signals | number
     timeout?: number
@@ -60,6 +62,7 @@ export namespace Process {
       cwd: opts.cwd,
       env: opts.env === null ? {} : opts.env ? { ...process.env, ...opts.env } : undefined,
       stdio: [opts.stdin ?? "ignore", opts.stdout ?? "ignore", opts.stderr ?? "ignore"],
+      shell: opts.shell,
       windowsHide: process.platform === "win32",
     })