Skip to content

Commit 4dcc6fb

Browse files
committed
WASM REPL: maintain history during browsing session
1 parent c477e30 commit 4dcc6fb

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

Tools/wasm/emscripten/web_example/index.html

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,13 @@
145145

146146
class WasmTerminal {
147147
constructor() {
148+
try {
149+
this.history = JSON.parse(sessionStorage.getItem('__python_wasm_repl.history'));
150+
this.historyBuffer = this.history.slice();
151+
} catch(e) {
152+
this.history = [];
153+
this.historyBuffer = [];
154+
}
148155
this.reset();
149156

150157
this.xterm = new Terminal({
@@ -172,8 +179,6 @@
172179
this.inputStartCursor = null;
173180

174181
this.cursorPosition = 0;
175-
this.history = [];
176-
this.historyBuffer = [];
177182
this.historyIndex = -1;
178183
this.beforeHistoryNav = "";
179184
}
@@ -319,7 +324,7 @@
319324
this.xterm.write("\x1b[" + suffix.length + "D");
320325
}
321326
this.cursorPosition += count;
322-
this.updateHistory(false);
327+
this.updateHistory();
323328
}
324329

325330
handleCursorErase() {
@@ -477,6 +482,10 @@
477482
this.historyBuffer.push(value.slice(0, -1));
478483
this.historyIndex = -1;
479484
this.cursorPosition = 0;
485+
try {
486+
sessionStorage.setItem('__python_wasm_repl.history', JSON.stringify(this.history));
487+
} catch(e) {
488+
}
480489
}
481490
resolve(value);
482491
};

0 commit comments

Comments
 (0)