8000 use a better approach for pyodide · pyscript/pyscript@778d37e · GitHub
[go: up one dir, main page]

Skip to content

Commit 778d37e

Browse files
committed
use a better approach for pyodide
1 parent e333813 commit 778d37e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

pyscript.core/src/plugins/pyterminal.js

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,17 @@ hooks.onInterpreterReady.add(function override(pyScript) {
5151
console.log("<py-terminal> not found, nothing to do");
5252
return;
5353
}
54-
const { stdout, stderr } = pyScript.io;
55-
56-
pyScript.io.stdout = (s, ...rest) => {
57-
// XXX: the + "\n" is conceptually wrong.
58-
// We probably need to configure pyodide's stdout as "raw mode"
59-
// instead of "batched mode":
60-
// https://pyodide.org/en/stable/usage/streams.html#a-raw-handler
61-
t.write(s + "\n");
62-
stdout(s, ...rest);
63-
}
64-
65-
pyScript.io.stderr = (s, ...rest) => {
66-
t.write(s + "\n"); // see above for the "\n"
67-
stderr(s, ...rest);
54+
// XXX: we should investigate pyodide "write handler", it should be more
55+
// efficient:
56+
// https://pyodide.org/en/stable/usage/streams.html#a-write-handler
57+
//
58+
// Also: should the stdout/stderr go ALSO to the JS console?
59+
function myStdout(byte) {
60+
t.write(String.fromCharCode(byte));
6861
}
62+
const pyodide = pyScript.interpreter;
63+
pyodide.setStdout({ raw: myStdout });
64+
pyodide.setStderr({ raw: myStdout });
6965
});
7066

7167

0 commit comments

Comments
 (0)
0