Only activate stdin reader when stdin is a TTY

This commit is contained in:
Cadence Ember 2023-10-12 22:17:15 +13:00
parent 6b605b393d
commit 90579cea28
1 changed files with 13 additions and 9 deletions

View File

@ -21,15 +21,19 @@ const guildID = "112760669178241024"
const extraContext = {} const extraContext = {}
setImmediate(() => { // assign after since old extraContext data will get removed if (process.stdin.isTTY) {
if (!passthrough.repl) { setImmediate(() => { // assign after since old extraContext data will get removed
const cli = repl.start({ prompt: "", eval: customEval, writer: s => s }) if (!passthrough.repl) {
Object.assign(cli.context, extraContext, passthrough) const cli = repl.start({ prompt: "", eval: customEval, writer: s => s })
passthrough.repl = cli Object.assign(cli.context, extraContext, passthrough)
} else Object.assign(passthrough.repl.context, extraContext) passthrough.repl = cli
// @ts-expect-error Says exit isn't assignable to a string } else {
sync.addTemporaryListener(passthrough.repl, "exit", () => process.exit()) Object.assign(passthrough.repl.context, extraContext)
}) }
// @ts-expect-error Says exit isn't assignable to a string
sync.addTemporaryListener(passthrough.repl, "exit", () => process.exit())
})
}
/** /**
* @param {string} input * @param {string} input