feat(opencode): add interactive split-footer mode to run (#23557)
This commit is contained in:
parent
15784aa036
commit
7f2b5ee8c2
60 changed files with 21843 additions and 340 deletions
37
packages/opencode/src/cli/cmd/run/runtime.stdin.ts
Normal file
37
packages/opencode/src/cli/cmd/run/runtime.stdin.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import fs from "fs"
|
||||
import * as tty from "node:tty"
|
||||
|
||||
export const INTERACTIVE_INPUT_ERROR = "--interactive requires a controlling terminal for input"
|
||||
|
||||
type InteractiveStdin = {
|
||||
stdin: NodeJS.ReadStream
|
||||
cleanup?: () => void
|
||||
}
|
||||
|
||||
function openTerminalStdin(path: string): NodeJS.ReadStream {
|
||||
return new tty.ReadStream(fs.openSync(path, "r"))
|
||||
}
|
||||
|
||||
export function resolveInteractiveStdin(
|
||||
stdin: NodeJS.ReadStream = process.stdin,
|
||||
open: (path: string) => NodeJS.ReadStream = openTerminalStdin,
|
||||
platform = process.platform,
|
||||
): InteractiveStdin {
|
||||
if (stdin.isTTY) {
|
||||
return { stdin }
|
||||
}
|
||||
|
||||
const file = platform === "win32" ? "CONIN$" : "/dev/tty"
|
||||
|
||||
try {
|
||||
const stream = open(file)
|
||||
return {
|
||||
stdin: stream,
|
||||
cleanup: () => {
|
||||
stream.destroy()
|
||||
},
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(INTERACTIVE_INPUT_ERROR, { cause: error })
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue