MCPcopy
hub / github.com/anomalyco/opencode / openEditor

Function openEditor

packages/tui/src/editor.ts:26–54  ·  view source on GitHub ↗
(input: { value: string; renderer: CliRenderer; cwd?: string; stdin?: EditorStdio })

Source from the content-addressed store, hash-verified

24}
25
26export async function openEditor(input: { value: string; renderer: CliRenderer; cwd?: string; stdin?: EditorStdio }) {
27 const editor = process.env.VISUAL || process.env.EDITOR
28 if (!editor) return
29 const file = path.join(os.tmpdir(), `${Date.now()}.md`)
30 await writeFile(file, input.value)
31 input.renderer.suspend()
32 input.renderer.currentRenderBuffer.clear()
33 try {
34 await new Promise<void>((resolve, reject) => {
35 const parts = editor.split(" ")
36 const child = spawn(parts[0]!, [...parts.slice(1), file], {
37 cwd: input.cwd && existsSync(input.cwd) ? input.cwd : process.cwd(),
38 stdio: [input.stdin ?? "inherit", "inherit", "inherit"],
39 shell: process.platform === "win32",
40 })
41 child.on("error", reject)
42 child.on("exit", (code, signal) => {
43 if (code === 0) return resolve()
44 reject(new Error(`Editor exited with ${signal ? `signal ${signal}` : `code ${code}`}`))
45 })
46 })
47 return (await readFile(file, "utf8")) || undefined
48 } finally {
49 await rm(file, { force: true }).catch(() => {})
50 input.renderer.currentRenderBuffer.clear()
51 input.renderer.resume()
52 input.renderer.requestRender()
53 }
54}
55
56export function discoverEditorConnection(directory: string) {
57 const root = path.join(os.homedir(), ".claude", "ide")

Callers 4

editor.test.tsFile · 0.90
PromptFunction · 0.90
SessionFunction · 0.90
createRuntimeLifecycleFunction · 0.90

Calls 8

readFileFunction · 0.85
onMethod · 0.80
cwdMethod · 0.65
spawnFunction · 0.50
resolveFunction · 0.50
rejectFunction · 0.50
rmFunction · 0.50
clearMethod · 0.45

Tested by

no test coverage detected