From aaa2159e352aee68bee5d5298ad074aad8930483 Mon Sep 17 00:00:00 2001 From: Trey Hunner Date: Sat, 23 Apr 2022 14:37:48 -0700 Subject: [PATCH] Support unicode in stdout and stderr --- browser-ui/wasm-terminal.js | 9 ++++++--- browser-ui/worker/worker.js | 8 ++------ 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/browser-ui/wasm-terminal.js b/browser-ui/wasm-terminal.js index 220988c..d270613 100644 --- a/browser-ui/wasm-terminal.js +++ b/browser-ui/wasm-terminal.js @@ -91,8 +91,11 @@ export class WasmTerminal { this.xterm.clear(); } - print(message) { - const normInput = message.replace(/[\r\n]+/g, "\n").replace(/\n/g, "\r\n"); - this.xterm.write(normInput); + print(charCode) { + let array = [charCode]; + if (charCode == 10) { + array = [13, 10]; // Replace \n with \r\n + } + this.xterm.write(new Uint8Array(array)); } } diff --git a/browser-ui/worker/worker.js b/browser-ui/worker/worker.js index c3a8bdf..1b79460 100644 --- a/browser-ui/worker/worker.js +++ b/browser-ui/worker/worker.js @@ -35,15 +35,11 @@ class StdinBuffer { } } -const stdoutBufSize = 128; -const stdoutBuf = new Int32Array() -let index = 0; - const stdout = (charCode) => { if (charCode) { postMessage({ type: 'stdout', - stdout: String.fromCharCode(charCode), + stdout: charCode, }) } else { console.log(typeof charCode, charCode) @@ -54,7 +50,7 @@ const stderr = (charCode) => { if (charCode) { postMessage({ type: 'stderr', - stderr: String.fromCharCode(charCode), + stderr: charCode, }) } else { console.log(typeof charCode, charCode)