From 0a506d9d3385a4d77d9743b6578472383862a43a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Fri, 23 Jan 2026 13:36:57 -0800 Subject: [PATCH] Add pixel size support to resize() --- src/interfaces.ts | 3 ++- src/native.d.ts | 2 +- src/terminal.ts | 2 +- src/unix/pty.cc | 12 +++++++----- src/unixTerminal.ts | 6 ++++-- src/windowsTerminal.ts | 2 +- typings/node-pty.d.ts | 3 ++- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/interfaces.ts b/src/interfaces.ts index 98fe5735..d14920a8 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -28,8 +28,9 @@ export interface ITerminal { * Resize the pty. * @param cols The number of columns. * @param rows The number of rows. + * @param pixelSize Optional pixel dimensions of the pty. */ - resize(cols: number, rows: number): void; + resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void; /** * Clears the pty's internal representation of its buffer. This is a no-op diff --git a/src/native.d.ts b/src/native.d.ts index 720e239e..9853df3e 100644 --- a/src/native.d.ts +++ b/src/native.d.ts @@ -14,7 +14,7 @@ interface IUnixNative { fork(file: string, args: string[], parsedEnv: string[], cwd: string, cols: number, rows: number, uid: number, gid: number, useUtf8: boolean, helperPath: string, onExitCallback: (code: number, signal: number) => void): IUnixProcess; open(cols: number, rows: number): IUnixOpenProcess; process(fd: number, pty?: string): string; - resize(fd: number, cols: number, rows: number): void; + resize(fd: number, cols: number, rows: number, xPixel: number, yPixel: number): void; } interface IConptyProcess { diff --git a/src/terminal.ts b/src/terminal.ts index 5fdde70e..487e3756 100644 --- a/src/terminal.ts +++ b/src/terminal.ts @@ -178,7 +178,7 @@ export abstract class Terminal implements ITerminal { this._socket.once(eventName, listener); } - public abstract resize(cols: number, rows: number): void; + public abstract resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void; public abstract clear(): void; public abstract destroy(): void; public abstract kill(signal?: string): void; diff --git a/src/unix/pty.cc b/src/unix/pty.cc index 9df942ef..4917560b 100644 --- a/src/unix/pty.cc +++ b/src/unix/pty.cc @@ -543,11 +543,13 @@ Napi::Value PtyResize(const Napi::CallbackInfo& info) { Napi::Env env(info.Env()); Napi::HandleScope scope(env); - if (info.Length() != 3 || + if (info.Length() != 5 || !info[0].IsNumber() || !info[1].IsNumber() || - !info[2].IsNumber()) { - throw Napi::Error::New(env, "Usage: pty.resize(fd, cols, rows)"); + !info[2].IsNumber() || + !info[3].IsNumber() || + !info[4].IsNumber()) { + throw Napi::Error::New(env, "Usage: pty.resize(fd, cols, rows, xPixel, yPixel)"); } int fd = info[0].As().Int32Value(); @@ -555,8 +557,8 @@ Napi::Value PtyResize(const Napi::CallbackInfo& info) { struct winsize winp; winp.ws_col = info[1].As().Int32Value(); winp.ws_row = info[2].As().Int32Value(); - winp.ws_xpixel = 0; - winp.ws_ypixel = 0; + winp.ws_xpixel = info[3].As().Int32Value(); + winp.ws_ypixel = info[4].As().Int32Value(); if (ioctl(fd, TIOCSWINSZ, &winp) == -1) { switch (errno) { diff --git a/src/unixTerminal.ts b/src/unixTerminal.ts index 98733dc0..516c720e 100644 --- a/src/unixTerminal.ts +++ b/src/unixTerminal.ts @@ -268,11 +268,13 @@ export class UnixTerminal extends Terminal { * TTY */ - public resize(cols: number, rows: number): void { + public resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void { if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) { throw new Error('resizing must be done using positive cols and rows'); } - pty.resize(this._fd, cols, rows); + const xPixel = pixelSize?.width ?? 0; + const yPixel = pixelSize?.height ?? 0; + pty.resize(this._fd, cols, rows, xPixel, yPixel); this._cols = cols; this._rows = rows; } diff --git a/src/windowsTerminal.ts b/src/windowsTerminal.ts index 3105e901..8516750b 100644 --- a/src/windowsTerminal.ts +++ b/src/windowsTerminal.ts @@ -138,7 +138,7 @@ export class WindowsTerminal extends Terminal { * TTY */ - public resize(cols: number, rows: number): void { + public resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void { if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) { throw new Error('resizing must be done using positive cols and rows'); } diff --git a/typings/node-pty.d.ts b/typings/node-pty.d.ts index c16ce924..c5a1a4d1 100644 --- a/typings/node-pty.d.ts +++ b/typings/node-pty.d.ts @@ -159,8 +159,9 @@ declare module 'node-pty' { * Resizes the dimensions of the pty. * @param columns The number of columns to use. * @param rows The number of rows to use. + * @param pixelSize Optional pixel dimensions of the pty. */ - resize(columns: number, rows: number): void; + resize(columns: number, rows: number, pixelSize?: { width: number, height: number }): void; /** * Clears the pty's internal representation of its buffer. This is a no-op