mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-20 18:55:29 -05:00
Allow MicroPython input("...") to work beside the code.interact() (#2017)
This commit is contained in:
committed by
GitHub
parent
2f1b764251
commit
65954a627e
@@ -53,6 +53,12 @@ const workerReady = ({ interpreter, io, run, type }, { sync }) => {
|
||||
// This part patches it in a way that simulates
|
||||
// the code.interact() module in Pyodide.
|
||||
if (type === "mpy") {
|
||||
// monkey patch global input otherwise broken in MicroPython
|
||||
interpreter.registerJsModule("_pyscript_input", {
|
||||
input: pyterminal_read,
|
||||
});
|
||||
run("from _pyscript_input import input");
|
||||
|
||||
io.stdout = generic.write;
|
||||
// tiny shim of the code module with only interact
|
||||
// to bootstrap a REPL like environment
|
||||
@@ -74,12 +80,6 @@ const workerReady = ({ interpreter, io, run, type }, { sync }) => {
|
||||
|
||||
interpreter.replInit();
|
||||
|
||||
// monkey patch global input otherwise broken in MicroPython
|
||||
interpreter.registerJsModule("_pyscript_input", {
|
||||
input: pyterminal_read,
|
||||
});
|
||||
run("from _pyscript_input import input");
|
||||
|
||||
// loop forever waiting for user inputs
|
||||
(function repl() {
|
||||
const out = decoder.decode(new Uint8Array(acc.splice(0)));
|
||||
|
||||
Reference in New Issue
Block a user