Skip to content

Commit

Permalink
Replace xtermjs with a simple ansi to html solution; Compress with gz…
Browse files Browse the repository at this point in the history
…ip -1 for faster decompression (size is marginally larger);
  • Loading branch information
LyonSyonII committed Jun 15, 2024
1 parent d6ba218 commit 46de671
Show file tree
Hide file tree
Showing 31 changed files with 35 additions and 31 deletions.
5 changes: 3 additions & 2 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
"astro": "astro"
},
"dependencies": {
"ansi_up": "^6.0.2"
},
"devDependencies": {
"@astrojs/check": "^0.7.0",
"@xterm/addon-fit": "^0.10.0",
"@xterm/xterm": "^5.5.0",
"astro": "^4.10.2",
"astro-compress": "^2.2.28",
"astro-compressor": "^0.4.1",
Expand Down
22 changes: 22 additions & 0 deletions example/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified example/public/wasm-rustc/bin/miri.opt.1718474653.wasm.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
39 changes: 10 additions & 29 deletions example/src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@
font-size: x-large;
resize: none;
}
#terminal {}
#terminal {
white-space: pre-wrap;
}
#live-edit, #live-edit-wrapper {
user-select: none;
}
Expand All @@ -62,34 +64,15 @@

<script>
import { Interpreter } from "../interpreter";
import "@xterm/xterm/css/xterm.css";
import { Terminal } from "@xterm/xterm";
import { FitAddon } from "@xterm/addon-fit";

import { AnsiUp } from "ansi_up";

const input = document.body.querySelector<HTMLTextAreaElement>("textarea#input")!;
const button = document.body.querySelector<HTMLButtonElement>("button")!;
const liveEdit = document.body.querySelector<HTMLInputElement>("#live-edit")!;

// Terminal Initialization (not needed)
const termElement = document.getElementById("terminal")!;
const terminal = new Terminal({
convertEol: true,
disableStdin: true,
fontFamily: "monospace",
fontSize: 18,
rows: 17
});
const fitAddon = new FitAddon();
terminal.loadAddon(fitAddon);
terminal.open(termElement);
// @ts-ignore
termElement.firstChild.style.padding = "1rem";
// @ts-ignore
termElement.firstChild.firstChild.style.borderRadius = "0.25rem";
fitAddon.fit();

//
input.value = "Downloading:";

const ansiUp = new AnsiUp();
input.value = "Downloading (Can take a while):";
input.placeholder = "Write your code...";
input.readOnly = true;

Expand All @@ -109,14 +92,12 @@
// When Interpreter is running disable the "Run" button
interpreter.onRun(() => {
button.disabled = true;
terminal.reset();
terminal.write("Running...");
termElement.innerHTML = "Running...";
});

// When result is received from a running Interpreter write it to the terminal
interpreter.onResult(result => {
terminal.reset();
terminal.write(result);
termElement.innerHTML = ansiUp.ansi_to_html(result.replaceAll("\n", "\r"));
button.disabled = false;
});

Expand Down

0 comments on commit 46de671

Please sign in to comment.