Fix #2246 - Override builtins.input to avoid duplicating it (#2254)

This commit is contained in:
Andrea Giammarchi
2024-11-25 14:17:30 +01:00
committed by GitHub
parent 0a1d3bb678
commit 796373cfa6
6 changed files with 28 additions and 4 deletions

View File

@@ -137,6 +137,18 @@ export default async (element) => {
// setup remote thread JS/Python code for whenever the
// worker is ready to become a terminal
hooks.worker.onReady.add(workerReady);
// @see https://github.com/pyscript/pyscript/issues/2246
const patchInput = [
"import builtins as _b",
"from pyscript import sync as _s",
"_b.input = _s.pyterminal_read",
"del _b",
"del _s",
].join("\n");
hooks.worker.codeBeforeRun.add(patchInput);
hooks.worker.codeBeforeRunAsync.add(patchInput);
} else {
// in the main case, just bootstrap XTerm without
// allowing any input as that's not possible / awkward