From 86aba9ce3e955a79467461c92f4eb2e87d186e01 Mon Sep 17 00:00:00 2001 From: Mauricio Siu <47042324+Siumauricio@users.noreply.github.com> Date: Sat, 14 Dec 2024 23:12:21 -0600 Subject: [PATCH] refactor: remove cols --- .../docker/terminal/docker-terminal.tsx | 5 +- .../settings/web-server/terminal.tsx | 7 +- .../server/wss/docker-container-terminal.ts | 9 +-- apps/dokploy/server/wss/terminal.ts | 77 ++++++++----------- 4 files changed, 40 insertions(+), 58 deletions(-) diff --git a/apps/dokploy/components/dashboard/docker/terminal/docker-terminal.tsx b/apps/dokploy/components/dashboard/docker/terminal/docker-terminal.tsx index 4008d6fd5..42683887e 100644 --- a/apps/dokploy/components/dashboard/docker/terminal/docker-terminal.tsx +++ b/apps/dokploy/components/dashboard/docker/terminal/docker-terminal.tsx @@ -25,8 +25,6 @@ export const DockerTerminal: React.FC = ({ } const term = new Terminal({ cursorBlink: true, - cols: 80, - rows: 30, lineHeight: 1.4, convertEol: true, theme: { @@ -45,6 +43,7 @@ export const DockerTerminal: React.FC = ({ const addonAttach = new AttachAddon(ws); // @ts-ignore term.open(termRef.current); + // @ts-ignore term.loadAddon(addonFit); term.loadAddon(addonAttach); addonFit.fit(); @@ -66,7 +65,7 @@ export const DockerTerminal: React.FC = ({ -
+
diff --git a/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx b/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx index 2fe7f83cf..366784fc4 100644 --- a/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx +++ b/apps/dokploy/components/dashboard/settings/web-server/terminal.tsx @@ -20,13 +20,11 @@ export const Terminal: React.FC = ({ id, serverId }) => { } const term = new XTerm({ cursorBlink: true, - cols: 80, - rows: 30, lineHeight: 1.4, convertEol: true, theme: { cursor: "transparent", - background: "#19191A", + background: "transparent", }, }); const addonFit = new FitAddon(); @@ -40,6 +38,7 @@ export const Terminal: React.FC = ({ id, serverId }) => { // @ts-ignore term.open(termRef.current); + // @ts-ignore term.loadAddon(addonFit); term.loadAddon(addonAttach); addonFit.fit(); @@ -50,7 +49,7 @@ export const Terminal: React.FC = ({ id, serverId }) => { return (
-
+
diff --git a/apps/dokploy/server/wss/docker-container-terminal.ts b/apps/dokploy/server/wss/docker-container-terminal.ts index eeba72d52..d527b37c9 100644 --- a/apps/dokploy/server/wss/docker-container-terminal.ts +++ b/apps/dokploy/server/wss/docker-container-terminal.ts @@ -109,14 +109,7 @@ export const setupDockerContainerTerminalWebSocketServer = ( const ptyProcess = spawn( shell, ["-c", `docker exec -it ${containerId} ${activeWay}`], - { - name: "xterm-256color", - cwd: process.env.HOME, - env: process.env, - encoding: "utf8", - cols: 80, - rows: 30, - }, + {}, ); ptyProcess.onData((data) => { diff --git a/apps/dokploy/server/wss/terminal.ts b/apps/dokploy/server/wss/terminal.ts index eb0bf2e20..a6338afe1 100644 --- a/apps/dokploy/server/wss/terminal.ts +++ b/apps/dokploy/server/wss/terminal.ts @@ -70,53 +70,44 @@ export const setupTerminalWebSocketServer = ( let stderr = ""; conn .once("ready", () => { - conn.shell( - { - term: "terminal", - cols: 80, - rows: 30, - height: 30, - width: 80, - }, - (err, stream) => { - if (err) throw err; + conn.shell({}, (err, stream) => { + if (err) throw err; - stream - .on("close", (code: number, signal: string) => { - ws.send(`\nContainer closed with code: ${code}\n`); - conn.end(); - }) - .on("data", (data: string) => { - stdout += data.toString(); - ws.send(data.toString()); - }) - .stderr.on("data", (data) => { - stderr += data.toString(); - ws.send(data.toString()); - console.error("Error: ", data.toString()); - }); + stream + .on("close", (code: number, signal: string) => { + ws.send(`\nContainer closed with code: ${code}\n`); + conn.end(); + }) + .on("data", (data: string) => { + stdout += data.toString(); + ws.send(data.toString()); + }) + .stderr.on("data", (data) => { + stderr += data.toString(); + ws.send(data.toString()); + console.error("Error: ", data.toString()); + }); - ws.on("message", (message) => { - try { - let command: string | Buffer[] | Buffer | ArrayBuffer; - if (Buffer.isBuffer(message)) { - command = message.toString("utf8"); - } else { - command = message; - } - stream.write(command.toString()); - } catch (error) { - // @ts-ignore - const errorMessage = error?.message as unknown as string; - ws.send(errorMessage); + ws.on("message", (message) => { + try { + let command: string | Buffer[] | Buffer | ArrayBuffer; + if (Buffer.isBuffer(message)) { + command = message.toString("utf8"); + } else { + command = message; } - }); + stream.write(command.toString()); + } catch (error) { + // @ts-ignore + const errorMessage = error?.message as unknown as string; + ws.send(errorMessage); + } + }); - ws.on("close", () => { - stream.end(); - }); - }, - ); + ws.on("close", () => { + stream.end(); + }); + }); }) .on("error", (err) => { if (err.level === "client-authentication") {