mirror of
https://github.com/python/cpython.git
synced 2025-07-27 21:24:32 +00:00
gh-97747: Improvements to WASM browser REPL. (#97665)
Improvements to WASM browser REPL. Adds a text box to write and run code outside the REPL, a stop button, and handling of Ctrl-D for EOF.
This commit is contained in:
parent
0d07182821
commit
010aaa32fb
2 changed files with 69 additions and 8 deletions
|
@ -19,18 +19,18 @@ class StdinBuffer {
|
|||
}
|
||||
|
||||
stdin = () => {
|
||||
if (this.numberOfCharacters + 1 === this.readIndex) {
|
||||
while (this.numberOfCharacters + 1 === this.readIndex) {
|
||||
if (!this.sentNull) {
|
||||
// Must return null once to indicate we're done for now.
|
||||
this.sentNull = true
|
||||
return null
|
||||
}
|
||||
this.sentNull = false
|
||||
// Prompt will reset this.readIndex to 1
|
||||
this.prompt()
|
||||
}
|
||||
const char = this.buffer[this.readIndex]
|
||||
this.readIndex += 1
|
||||
// How do I send an EOF??
|
||||
return char
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,11 @@ var Module = {
|
|||
|
||||
onmessage = (event) => {
|
||||
if (event.data.type === 'run') {
|
||||
// TODO: Set up files from event.data.files
|
||||
if (event.data.files) {
|
||||
for (const [filename, contents] of Object.entries(event.data.files)) {
|
||||
Module.FS.writeFile(filename, contents)
|
||||
}
|
||||
}
|
||||
const ret = callMain(event.data.args)
|
||||
postMessage({
|
||||
type: 'finished',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue