8000 WIP: I don't understand why onWorkerReady is not called · pyscript/pyscript@89c2124 · GitHub
[go: up one dir, main page]

Skip to content

Commit 89c2124

Browse files
committed
WIP: I don't understand why onWorkerReady is not called
1 parent 70e9611 commit 89c2124

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

pyscript.core/src/plugins/py-terminal.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import { hooks } from "../core.js";
44
// XXX TODO:
55
// 1. these imports should be lazy?
66
// 2. would be nice to automatically add xterm.css on demand
7-
import { Terminal } from 'https://cdn.jsdelivr.net/npm/xterm@5.3.0/+esm'
8-
import { Readline } from 'https://cdn.jsdelivr.net/npm/xterm-readline@1.1.1/+esm'
7+
import { Terminal } from "https://cdn.jsdelivr.net/npm/xterm@5.3.0/+esm";
8+
import { Readline } from "https://cdn.jsdelivr.net/npm/xterm-readline@1.1.1/+esm";
99
const makePyTerminal = () => {
10-
const element = document.querySelector('py-terminal');
10+
const element = document.querySelector("py-terminal");
1111
if (element === null) {
1212
return false;
1313
}
@@ -19,7 +19,7 @@ const makePyTerminal = () => {
1919
},
2020
cursorBlink: true,
2121
cursorStyle: "block",
22-
rows: 50
22+
rows: 50,
2323
});
2424

2525
const rl = new Readline();
@@ -40,7 +40,7 @@ const makePyTerminal = () => {
4040

4141
console.log("PyTerminal made?");
4242
return { term, readline, write };
43-
}
43+
};
4444

4545
// this is ONLY for non-workers, correct?
4646
// TODO: how to make it working for workers?
@@ -64,6 +64,15 @@ hooks.onInterpreterReady.add(function override(pyScript) {
6464
pyodide.setStderr({ raw: myStdout });
6565
});
6666

67+
hooks.onWorkerReady.add(function override(pyScript) {
68+
console.log("hello onWorkerReady");
69+
const t = makePyTerminal();
70+
if (!t) {
71+
console.log("<py-terminal> not found, nothing to do");
72+
return;
73+
}
74+
console.log(pyScript);
75+
});
6776

6877
// this is mostly pseudo-code for what it *should* happen for the workers case
6978
/*

pyscript.core/test/pyterminal.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
</head>
1616
<body>
17-
<script type="py">
17+
<script type="py" worker>
1818
import sys
1919
from pyscript import display
2020
display("Hello", "PyScript Next", append=False)

0 commit comments

Comments
 (0)
0