diff --git a/src/interfaces.ts b/src/interfaces.ts index 98fe5735..461b713e 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -28,8 +28,11 @@ 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. On Unix, this sets the `ws_xpixel` + * and `ws_ypixel` fields of the `winsize` struct. Applications running in the pty can read + * these values via the `TIOCGWINSZ` ioctl. This parameter is ignored on Windows. */ - 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..03bfbeba 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, pixelWidth: number, pixelHeight: 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..55dfb3ea 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 pixelWidth = pixelSize?.width ?? 0; + const pixelHeight = pixelSize?.height ?? 0; + pty.resize(this._fd, cols, rows, pixelWidth, pixelHeight); 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..319ba021 100644 --- a/typings/node-pty.d.ts +++ b/typings/node-pty.d.ts @@ -159,8 +159,11 @@ 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. On Unix, this sets the `ws_xpixel` + * and `ws_ypixel` fields of the `winsize` struct. Applications running in the pty can read + * these values via the `TIOCGWINSZ` ioctl. This parameter is ignored on Windows. */ - 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