use a better approach for pyodide

This commit is contained in:
Antonio Cuni
2023-09-29 13:05:53 +02:00
parent e333813fa1
commit 778d37ef6c

View File

@@ -51,21 +51,17 @@ hooks.onInterpreterReady.add(function override(pyScript) {
console.log("<py-terminal> not found, nothing to do");
return;
}
const { stdout, stderr } = pyScript.io;
pyScript.io.stdout = (s, ...rest) => {
// XXX: the + "\n" is conceptually wrong.
// We probably need to configure pyodide's stdout as "raw mode"
// instead of "batched mode":
// https://pyodide.org/en/stable/usage/streams.html#a-raw-handler
t.write(s + "\n");
stdout(s, ...rest);
}
pyScript.io.stderr = (s, ...rest) => {
t.write(s + "\n"); // see above for the "\n"
stderr(s, ...rest);
// XXX: we should investigate pyodide "write handler", it should be more
// efficient:
// https://pyodide.org/en/stable/usage/streams.html#a-write-handler
//
// Also: should the stdout/stderr go ALSO to the JS console?
function myStdout(byte) {
t.write(String.fromCharCode(byte));
}
const pyodide = pyScript.interpreter;
pyodide.setStdout({ raw: myStdout });
pyodide.setStderr({ raw: myStdout });
});