diff --git a/backend/socket-handlers/terminal-socket-handler.ts b/backend/socket-handlers/terminal-socket-handler.ts index 3deed45..9ae6656 100644 --- a/backend/socket-handlers/terminal-socket-handler.ts +++ b/backend/socket-handlers/terminal-socket-handler.ts @@ -162,9 +162,44 @@ export class TerminalSocketHandler extends SocketHandler { } }); - // TODO: Resize Terminal - socket.on("terminalResize", async (rows : unknown) => { + // Resize Terminal + socket.on( + "terminalResize", + async (terminalName: unknown, rows: unknown, cols: unknown) => { + log.info("terminalResize", `Terminal: ${terminalName}`); + try { + checkLogin(socket); + if (typeof terminalName !== "string") { + throw new Error("Terminal name must be a string."); + } - }); + if (typeof rows !== "number") { + throw new Error("Command must be a number."); + } + if (typeof cols !== "number") { + throw new Error("Command must be a number."); + } + + let terminal = Terminal.getTerminal(terminalName); + + // log.info("terminal", terminal); + if (terminal instanceof Terminal) { + //log.debug("terminalInput", "Terminal found, writing to terminal."); + terminal.rows = rows; + terminal.cols = cols; + } else { + throw new Error(`${terminalName} Terminal not found.`); + } + } catch (e) { + log.debug( + "terminalResize", + // Added to prevent the lint error when adding the type + // and ts type checker saying type is unknown. + // @ts-ignore + `Error on ${terminalName}: ${e.message}` + ); + } + } + ); } } diff --git a/backend/terminal.ts b/backend/terminal.ts index 96a8b01..dedc4e0 100644 --- a/backend/terminal.ts +++ b/backend/terminal.ts @@ -67,6 +67,7 @@ export class Terminal { set cols(cols : number) { this._cols = cols; + log.debug("Terminal", `Terminal cols: ${this._cols}`); // Added to check if cols is being set when changing terminal size. try { this.ptyProcess?.resize(this.cols, this.rows); } catch (e) { diff --git a/frontend/src/components/Terminal.vue b/frontend/src/components/Terminal.vue index 41551ba..4391a57 100644 --- a/frontend/src/components/Terminal.vue +++ b/frontend/src/components/Terminal.vue @@ -5,7 +5,8 @@