From 90579cea2843a14491977c82304ca091de991e63 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Thu, 12 Oct 2023 22:17:15 +1300 Subject: [PATCH] Only activate stdin reader when stdin is a TTY --- stdin.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/stdin.js b/stdin.js index c99a68b..587b176 100644 --- a/stdin.js +++ b/stdin.js @@ -21,15 +21,19 @@ const guildID = "112760669178241024" const extraContext = {} -setImmediate(() => { // assign after since old extraContext data will get removed - if (!passthrough.repl) { - const cli = repl.start({ prompt: "", eval: customEval, writer: s => s }) - Object.assign(cli.context, extraContext, passthrough) - passthrough.repl = cli - } else Object.assign(passthrough.repl.context, extraContext) - // @ts-expect-error Says exit isn't assignable to a string - sync.addTemporaryListener(passthrough.repl, "exit", () => process.exit()) -}) +if (process.stdin.isTTY) { + setImmediate(() => { // assign after since old extraContext data will get removed + if (!passthrough.repl) { + const cli = repl.start({ prompt: "", eval: customEval, writer: s => s }) + Object.assign(cli.context, extraContext, passthrough) + passthrough.repl = cli + } else { + 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