mirror of
https://github.com/CyberL1/dlinux-dashboard.git
synced 2025-02-23 03:49:18 -05:00
fix(WebTerminal): work
This commit is contained in:
parent
3cd59266c2
commit
85d70aa393
@ -16,10 +16,10 @@ export default function WebTerminal() {
|
|||||||
document.title = `Terminal: ${container.name}`;
|
document.title = `Terminal: ${container.name}`;
|
||||||
|
|
||||||
if (terminalRef.current) {
|
if (terminalRef.current) {
|
||||||
const terminal = new Terminal({ rows: 67 });
|
const terminal = new Terminal({ rows: 67, convertEol: true });
|
||||||
|
|
||||||
const socket = new WebSocket(
|
const socket = new WebSocket(
|
||||||
`ws://127.0.0.1:3000/containers/${container.id}/terminal`, // TODO: Replace this with dlinux ssh connector
|
`wss://session.ssh.surf?token=${localStorage.getItem("key")?.toString()}`,
|
||||||
);
|
);
|
||||||
|
|
||||||
const fitAddon = new FitAddon();
|
const fitAddon = new FitAddon();
|
||||||
@ -31,20 +31,50 @@ export default function WebTerminal() {
|
|||||||
terminal.write("Connecting to the container\r\n");
|
terminal.write("Connecting to the container\r\n");
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
const attachAddon = new AttachAddon(socket);
|
const attachAddon = new AttachAddon(socket, { bidirectional: false });
|
||||||
terminal.loadAddon(attachAddon);
|
terminal.loadAddon(attachAddon);
|
||||||
|
|
||||||
terminal.clear();
|
terminal.clear();
|
||||||
terminal.focus();
|
terminal.focus();
|
||||||
|
|
||||||
socket.send(
|
|
||||||
JSON.stringify({
|
|
||||||
rows: terminal.rows,
|
|
||||||
cols: terminal.cols,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let line = "";
|
||||||
|
let cursor = 0;
|
||||||
|
let busy = false;
|
||||||
|
|
||||||
|
terminal.onData((data) => {
|
||||||
|
if (socket.readyState === WebSocket.OPEN) {
|
||||||
|
if (busy) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (data) {
|
||||||
|
case "\r": // Enter
|
||||||
|
socket.send(line);
|
||||||
|
|
||||||
|
cursor = 0;
|
||||||
|
line = "";
|
||||||
|
break;
|
||||||
|
case "\x7f": // Backspace
|
||||||
|
if (cursor > 0) {
|
||||||
|
terminal.write("\b \b");
|
||||||
|
if (line.length > 0) {
|
||||||
|
line = line.substring(0, line.length - 1);
|
||||||
|
}
|
||||||
|
cursor--;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// Check if character is printable
|
||||||
|
if (data.charCodeAt(0) >= 32 && data.charCodeAt(0) <= 127) {
|
||||||
|
cursor++;
|
||||||
|
line += data;
|
||||||
|
terminal.write(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
window.addEventListener("resize", () => {
|
window.addEventListener("resize", () => {
|
||||||
fitAddon.fit();
|
fitAddon.fit();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user