Compare commits

..

No commits in common. "7f31876ed7d845d44ac3f3a578083781ead42daa" and "3cd59266c23f34158e4ef1aa2c4922d568a74a11" have entirely different histories.

View File

@ -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, convertEol: true }); const terminal = new Terminal({ rows: 67 });
const socket = new WebSocket( const socket = new WebSocket(
`wss://session.ssh.surf?token=${localStorage.getItem("key")?.toString()}`, `ws://127.0.0.1:3000/containers/${container.id}/terminal`, // TODO: Replace this with dlinux ssh connector
); );
const fitAddon = new FitAddon(); const fitAddon = new FitAddon();
@ -31,57 +31,27 @@ 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, { bidirectional: false }); const attachAddon = new AttachAddon(socket);
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 = ""; window.addEventListener("resize", () => {
let cursor = 0; fitAddon.fit();
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", () => { terminal.onResize(({ rows, cols }) => {
// fitAddon.fit(); socket.send(JSON.stringify({ rows, cols }));
// }); });
// terminal.onResize(({ rows, cols }) => {
// socket.send(JSON.stringify({ rows, cols }));
// });
return () => { return () => {
socket.close(); socket.close();