Allow MicroPython input("...") to work beside the code.interact() (#2017)

This commit is contained in:
Andrea Giammarchi
2024-04-04 18:13:00 +02:00
committed by GitHub
parent 2f1b764251
commit 65954a627e
3 changed files with 9 additions and 9 deletions

View File

@@ -1,12 +1,12 @@
{
"name": "@pyscript/core",
"version": "0.4.15",
"version": "0.4.16",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "@pyscript/core",
"version": "0.4.15",
"version": "0.4.16",
"license": "APACHE-2.0",
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",

View File

@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.4.15",
"version": "0.4.16",
"type": "module",
"description": "PyScript",
"module": "./index.js",

View File

@@ -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)));