MCPcopy Create free account
hub / github.com/arctic-cli/interface / open

Function open

packages/arctic/src/cli/cmd/tui/util/editor.ts:8–31  ·  view source on GitHub ↗
(opts: { value: string; renderer: CliRenderer })

Source from the content-addressed store, hash-verified

6
7export namespace Editor {
8 export async function open(opts: { value: string; renderer: CliRenderer }): Promise<string | undefined> {
9 const editor = process.env["VISUAL"] || process.env["EDITOR"]
10 if (!editor) return
11
12 const filepath = join(tmpdir(), `${Date.now()}.md`)
13 await using _ = defer(async () => rm(filepath, { force: true }))
14
15 await Bun.write(filepath, opts.value)
16 opts.renderer.suspend()
17 opts.renderer.currentRenderBuffer.clear()
18 const parts = editor.split(" ")
19 const proc = Bun.spawn({
20 cmd: [...parts, filepath],
21 stdin: "inherit",
22 stdout: "inherit",
23 stderr: "inherit",
24 })
25 await proc.exited
26 const content = await Bun.file(filepath).text()
27 opts.renderer.currentRenderBuffer.clear()
28 opts.renderer.resume()
29 opts.renderer.requestRender()
30 return content || undefined
31 }
32}

Callers 3

AppFunction · 0.50
FeedbackDialogFunction · 0.50
HomeFunction · 0.50

Calls 5

deferFunction · 0.90
tmpdirFunction · 0.85
spawnMethod · 0.80
textMethod · 0.65
clearMethod · 0.45

Tested by

no test coverage detected