Updated console to use xterm and enabled autologin
This commit is contained in:
14
index.html
14
index.html
@ -5,16 +5,26 @@
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<script src="assets/libv86.js"></script>
|
||||
<script src="index.js"></script>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
<title>WebTerm</title>
|
||||
<!-- Xterm -->
|
||||
<link rel="stylesheet" href="xterm/xterm.css" />
|
||||
<script src="xterm/xterm.js"></script>
|
||||
<script src="xterm/xterm-addon-fit.js"></script>
|
||||
<!-- V86 -->
|
||||
<script src="assets/libv86.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="screen_container">
|
||||
<!-- v86 screen if debug is enabled -->
|
||||
<div id="screen">
|
||||
<div style="white-space: pre; font: 14px monospace; line-height: 14px"></div>
|
||||
<canvas style="display: none"></canvas>
|
||||
</div>
|
||||
<!-- Xterm -->
|
||||
<div id="terminal">
|
||||
</div>
|
||||
</body>
|
||||
|
||||
</html>
|
74
index.js
74
index.js
@ -1,9 +1,22 @@
|
||||
var term;
|
||||
var termfit;
|
||||
var emulator;
|
||||
|
||||
var booted = false;
|
||||
|
||||
document.addEventListener("DOMContentLoaded", () => {
|
||||
var emulator = new V86Starter({
|
||||
// Debug
|
||||
var v86_display = undefined;
|
||||
if(window.location.hash == "#debug") {
|
||||
v86_display = document.getElementById("screen");
|
||||
}
|
||||
|
||||
// Initialize the v86 emulator
|
||||
emulator = new V86Starter({
|
||||
wasm_path: "assets/v86.wasm",
|
||||
memory_size: 512 * 1024 * 1024,
|
||||
vga_memory_size: 100 * 1024 * 1024,
|
||||
screen_container: document.getElementById("screen_container"),
|
||||
screen_container: v86_display,
|
||||
bios: {
|
||||
url: "images/seabios.bin",
|
||||
},
|
||||
@ -15,4 +28,61 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
},
|
||||
autostart: true,
|
||||
});
|
||||
|
||||
// Initialize xterm.js
|
||||
term = new Terminal({
|
||||
rendererType: 'dom',
|
||||
});
|
||||
termcontainer = document.getElementById('terminal');
|
||||
term.open(termcontainer);
|
||||
// Fit xterm to the size of the container
|
||||
termfit = new FitAddon.FitAddon();
|
||||
term.loadAddon(termfit);
|
||||
termfit.fit()
|
||||
// Write a "Booting WebTerm ..." message
|
||||
term.write('\033[1;34mDownloading\033[0m OS images ...\r\n')
|
||||
|
||||
// Forward keystrokes from xterm to v86
|
||||
term.onKey(key => onConsoleInput(key));
|
||||
// Forward output from v86 to xterm and other functions
|
||||
emulator.add_listener("serial0-output-char", (char) => onConsoleOutput(char));
|
||||
emulator.add_listener("serial0-output-line", (line) => onConsoleLine(line));
|
||||
|
||||
// Wait for the emulator to get ready
|
||||
emulator.add_listener("emulator-ready", () => {
|
||||
term.write('Booting \x1B[1;3;31mWebTerm\x1B[0m ...\r\n')
|
||||
})
|
||||
})
|
||||
|
||||
function onConsoleOutput(char) {
|
||||
// Only write to the xterm if the system is fully booted
|
||||
if(booted) {
|
||||
term.write(char);
|
||||
}
|
||||
// If the char is the shell prompt after the login message start
|
||||
// the welcome script and set bootet to true
|
||||
if(char == "#" && previous_line.includes("buildroot login: root")) {
|
||||
emulator.serial0_send("/etc/init.d/S99welcome\n")
|
||||
booted = true;
|
||||
}
|
||||
}
|
||||
|
||||
function onConsoleInput(key) {
|
||||
// Send keys from xterm to v86
|
||||
emulator.serial0_send(key.key)
|
||||
}
|
||||
|
||||
var previous_line = "";
|
||||
function onConsoleLine(line) {
|
||||
// Enter username on the login prompt
|
||||
if (line.startsWith("Welcome to WebTerm")) {
|
||||
emulator.serial0_send("root\n")
|
||||
}
|
||||
// Save the line
|
||||
previous_line = line;
|
||||
}
|
||||
|
||||
// Fit xterm to the container on window resize
|
||||
window.addEventListener("resize", () => {
|
||||
termfit.fit()
|
||||
})
|
Reference in New Issue
Block a user