mini migrate to v2 (#35526)
This commit is contained in:
parent
fb75ea2cf6
commit
32cf36de9d
93 changed files with 2244 additions and 2333 deletions
|
|
@ -1,37 +0,0 @@
|
|||
import fs from "fs"
|
||||
import * as tty from "node:tty"
|
||||
|
||||
export const INTERACTIVE_INPUT_ERROR = "opencode mini 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