2022-06-29 19:31:55 -04:00
|
|
|
|
|
|
|
var ws;
|
2022-07-07 19:55:04 -04:00
|
|
|
var input = document.getElementById("input");
|
2022-07-08 19:57:19 -04:00
|
|
|
input.value = "";
|
2022-07-07 19:55:04 -04:00
|
|
|
var title = document.querySelector("title");
|
2022-07-08 19:57:19 -04:00
|
|
|
var log = document.getElementById("log");
|
2022-07-07 19:55:04 -04:00
|
|
|
|
|
|
|
function set_enabled(enabled) {
|
|
|
|
input.disabled = !enabled;
|
|
|
|
var buttons = document.querySelectorAll("button");
|
|
|
|
for (button of buttons) {
|
|
|
|
button.disabled = !enabled;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
set_enabled(false);
|
2022-06-29 19:31:55 -04:00
|
|
|
|
|
|
|
function onSubmit() {
|
2022-07-08 19:57:19 -04:00
|
|
|
ws.send("\r");
|
|
|
|
input.value = "";
|
|
|
|
input.focus();
|
2022-06-29 19:31:55 -04:00
|
|
|
}
|
|
|
|
|
2022-07-08 19:57:19 -04:00
|
|
|
ws = new WebSocket("ws://" + window.location.host + "/cp/serial/");
|
2022-06-29 19:31:55 -04:00
|
|
|
|
|
|
|
ws.onopen = function() {
|
2022-07-07 19:55:04 -04:00
|
|
|
set_enabled(true);
|
2022-06-29 19:31:55 -04:00
|
|
|
};
|
|
|
|
|
2022-07-07 19:55:04 -04:00
|
|
|
var setting_title = false;
|
2022-07-08 19:57:19 -04:00
|
|
|
var encoder = new TextEncoder();
|
|
|
|
var left_count = 0;
|
2022-06-29 19:31:55 -04:00
|
|
|
ws.onmessage = function(e) {
|
2022-07-07 19:55:04 -04:00
|
|
|
if (e.data == "\x1b]0;") {
|
|
|
|
setting_title = true;
|
|
|
|
title.textContent = "";
|
|
|
|
} else if (e.data == "\x1b\\") {
|
|
|
|
setting_title = false;
|
|
|
|
} else if (setting_title) {
|
|
|
|
title.textContent += e.data;
|
2022-07-08 19:57:19 -04:00
|
|
|
} else if (e.data == "\b") {
|
|
|
|
left_count += 1;
|
|
|
|
} else if (e.data == "\x1b[K") { // Clear line
|
|
|
|
log.textContent = log.textContent.slice(0, -left_count);
|
|
|
|
left_count = 0;
|
2022-07-07 19:55:04 -04:00
|
|
|
} else {
|
2022-07-08 19:57:19 -04:00
|
|
|
log.textContent += e.data;
|
2022-07-07 19:55:04 -04:00
|
|
|
}
|
2022-07-08 19:57:19 -04:00
|
|
|
document.querySelector("span").scrollIntoView();
|
2022-06-29 19:31:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
ws.onclose = function() {
|
2022-07-07 19:55:04 -04:00
|
|
|
set_enabled(false);
|
2022-06-29 19:31:55 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
ws.onerror = function(e) {
|
2022-07-07 19:55:04 -04:00
|
|
|
set_enabled(false);
|
2022-06-29 19:31:55 -04:00
|
|
|
};
|
2022-07-07 19:55:04 -04:00
|
|
|
|
2022-07-12 17:12:39 -04:00
|
|
|
input.addEventListener("beforeinput", function(e) {
|
2022-07-08 19:57:19 -04:00
|
|
|
if (e.inputType == "insertLineBreak") {
|
|
|
|
ws.send("\r");
|
|
|
|
input.value = "";
|
|
|
|
input.focus();
|
|
|
|
e.preventDefault();
|
|
|
|
} else if (e.inputType == "insertText") {
|
|
|
|
ws.send(e.data);
|
|
|
|
} else if (e.inputType == "deleteContentBackward") {
|
|
|
|
ws.send("\b");
|
|
|
|
}
|
2022-07-12 17:12:39 -04:00
|
|
|
});
|
2022-07-08 19:57:19 -04:00
|
|
|
|
|
|
|
let ctrl_c = document.querySelector("#c");
|
|
|
|
ctrl_c.onclick = function() {
|
|
|
|
ws.send("\x03");
|
|
|
|
}
|
|
|
|
|
|
|
|
let ctrl_d = document.querySelector("#d");
|
|
|
|
ctrl_d.onclick = function() {
|
|
|
|
ws.send("\x04");
|
2022-07-07 19:55:04 -04:00
|
|
|
}
|