diff --git a/app.js b/app.js index 7d1f59c..8ab0974 100644 --- a/app.js +++ b/app.js @@ -20,6 +20,25 @@ const containerList = document.getElementById('container-list'); // Initialize the app console.log('[INFO] Client app initialized'); +// Add Kill Terminal button functionality +document.getElementById('kill-terminal-btn').onclick = () => { + const containerId = terminalTitle.dataset.containerId; + if (containerId && terminalSessions[containerId]) { + console.log(`[INFO] Killing terminal session for container: ${containerId}`); + + // Send kill command to server + window.sendCommand('killTerminal', { containerId }); + + // Clean up terminal state + terminalModal.style.display = 'none'; + delete terminalSessions[containerId]; + xterm.dispose(); // Dispose of the current terminal instance + xterm = null; // Reset xterm instance + } else { + console.error('[ERROR] No terminal session found to kill.'); + } +}; + // Add a new connection document.getElementById('add-connection-form').addEventListener('submit', (e) => { e.preventDefault(); @@ -134,7 +153,7 @@ function renderContainers(containers) { - + `; containerList.appendChild(row); @@ -161,7 +180,7 @@ function initializeTerminal() { } // Start terminal session -function startTerminal(containerId) { +function startTerminal(containerId, containerName) { if (!activePeer) { console.error('[ERROR] No active peer for terminal.'); return; @@ -176,13 +195,18 @@ function startTerminal(containerId) { xterm.write(session.output); terminalModal.style.display = 'flex'; - terminalTitle.textContent = `Container Terminal: ${containerId}`; + terminalTitle.dataset.containerId = containerId; + terminalTitle.textContent = `Container Terminal: ${containerName}`; console.log(`[INFO] Starting terminal for container: ${containerId}`); activePeer.write(JSON.stringify({ command: 'startTerminal', args: { containerId } })); xterm.onData((data) => { console.log(`[DEBUG] Sending terminal input: ${data}`); + if (data === '\u001b[2;5R') { + fitAddon.fit(); + return; + } activePeer.write(JSON.stringify({ type: 'terminalInput', data })); }); @@ -205,7 +229,7 @@ function appendTerminalOutput(data, containerId) { console.log(`[DEBUG] Appending terminal output: ${data}`); const session = terminalSessions[containerId]; session.output += data; - if (terminalTitle.textContent.includes(containerId)) { + if (terminalTitle.dataset.containerId === containerId) { xterm.write(data); } } diff --git a/index.html b/index.html index 2cbc4c7..bdb7941 100644 --- a/index.html +++ b/index.html @@ -104,11 +104,11 @@ align-items: center; } #terminal-container { - flex: 1; - overflow: hidden; /* Ensure no scrollbars appear */ - background-color: black; - color: white; - } + flex: 1; + overflow: hidden; + background-color: black; + color: white; + } #tray { position: fixed; bottom: 0; @@ -165,7 +165,10 @@