Skip to content

gh-136251: Improvements to WASM demo REPL #136252

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jul 21, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
af4aa0d
EMSCRIPTEN BUILD: export HEAPU32 from emscripten build so that python…
adqm Jul 2, 2025
394815e
WASM REPL: fix loading xterm.js (broken in 2f1cee8477)
adqm Jul 2, 2025
aab9ccc
WASM REPL: basic navigation in REPL (arrow keys, home/end, etc)
adqm Jul 2, 2025
bd52abe
WASM REPL: reset the python worker after a program exits so that we c…
adqm Jul 2, 2025
77cc952
WASM REPL: handle a few more special keys (tab, ctrl+c)
adqm Jul 2, 2025
4cfa3f1
WASM REPL: use ace editor instead of a plain textbox for code snippet
adqm Jul 2, 2025
b688663
WASM REPL: some organization, refactoring, fixes for history
adqm Jul 2, 2025
43a47dc
WASM REPL: put demo at index.html and change text of the 'Run Code' b…
adqm Jul 3, 2025
6d5f698
WASM REPL: update README.md to account for demo location moving
adqm Jul 3, 2025
16cfea2
WASM REPL: add HEAPU32 to exports in configure.ac
adqm Jul 3, 2025
faf2ba4
WASM REPL: fix for ACE setup in Chromium
adqm Jul 3, 2025
70d4a17
WASM REPL: run prettier on index.html
adqm Jul 3, 2025
ce5ebca
WASM REPL: lower-case 'code' on 'Run code' button
adqm Jul 3, 2025
66cf49d
WASM REPL: remove trailing slashes from void tags in index.html
adqm Jul 5, 2025
8fe92d6
add short news blurb
adqm Jul 5, 2025
25fd7fc
change text of news blurb
adqm Jul 16, 2025
9a26d70
WASM REPL: better implementation of ctrl+c behavior
adqm Jul 16, 2025
c477e30
WASM REPL: show error message when SharedArrayBuffer is not available
adqm Jul 16, 2025
4dcc6fb
WASM REPL: maintain history during browsing session
adqm Jul 16, 2025
e06a7b2
WASM REPL: make the magic ctrl+c string vary with each run
adqm Jul 17, 2025
3e76313
Merge branch 'main' into wasm_repl
hoodmane Jul 21, 2025
26ddd07
Fix emscripten in browser
hoodmane Jul 21, 2025
7d33525
Merge branch 'main' into wasm_repl
hoodmane Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
WASM REPL: handle a few more special keys (tab, ctrl+c)
  • Loading branch information
adqm committed Jul 2, 2025
commit 77cc952fd66f5a438f283eef840c6fded2c01b5c
33 changes: 33 additions & 0 deletions Tools/wasm/emscripten/web_example/python.html
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,20 @@
this.input + this.writeLine("\n"),
);
this.input = "";
this.cursorPosition = 0;
this.activeInput = false;
break;
case "\x03": // CTRL+C
this.input = "";
this.xterm.write("\n")
// this is a real hack. the hard-coded 4... :\
this.xterm.write('\x1b[' + (this.cursorPosition + 4) + 'D');
this.cursorPosition = 0;
this.resolveInput("" + '\n');
break;
case "\x09": // TAB
this.handleTab();
break;
case "\x7F": // BACKSPACE
case "\x08": // CTRL+H
this.handleCursorErase(true);
Expand All @@ -245,6 +257,7 @@
// Send empty input
if (this.input === "") {
this.resolveInput("");
this.cursorPosition = 0;
this.activeInput = false;
}
}
Expand Down Expand Up @@ -376,6 +389,26 @@
}
}

handleTab() {
// handle tabs: from the current position, add spaces until
// this.cursorPosition is a multiple of 4.
const prefix = this.input.slice(0, this.cursorPosition);
const suffix = this.input.slice(this.cursorPosition);
const count = 4 - (this.cursorPosition % 4);
const toAdd = " ".repeat(count);
this.input = prefix + toAdd + suffix;
if (this.cursorPosition > 0){
this.xterm.write('\x1b[' + (this.cursorPosition) + 'D');
}
// clear the line
this.xterm.write('\x1b[K')
this.xterm.write(this.input);
if (suffix){
this.xterm.write('\x1b[' + suffix.length + 'D');
}
this.cursorPosition += count;
}

prompt = async () => {
this.activeInput = true;
// Hack to allow stdout/stderr to finish before we figure out where input starts
Expand Down