Skip to content

Commit 0a506d9

Browse files
committed
Add pixel size support to resize()
1 parent c69dc67 commit 0a506d9

7 files changed

Lines changed: 18 additions & 12 deletions

File tree

src/interfaces.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,9 @@ export interface ITerminal {
2828
* Resize the pty.
2929
* @param cols The number of columns.
3030
* @param rows The number of rows.
31+
* @param pixelSize Optional pixel dimensions of the pty.
3132
*/
32-
resize(cols: number, rows: number): void;
33+
resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void;
3334

3435
/**
3536
* Clears the pty's internal representation of its buffer. This is a no-op

src/native.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ interface IUnixNative {
1414
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;
1515
open(cols: number, rows: number): IUnixOpenProcess;
1616
process(fd: number, pty?: string): string;
17-
resize(fd: number, cols: number, rows: number): void;
17+
resize(fd: number, cols: number, rows: number, xPixel: number, yPixel: number): void;
1818
}
1919

2020
interface IConptyProcess {

src/terminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ export abstract class Terminal implements ITerminal {
178178
this._socket.once(eventName, listener);
179179
}
180180

181-
public abstract resize(cols: number, rows: number): void;
181+
public abstract resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void;
182182
public abstract clear(): void;
183183
public abstract destroy(): void;
184184
public abstract kill(signal?: string): void;

src/unix/pty.cc

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -543,20 +543,22 @@ Napi::Value PtyResize(const Napi::CallbackInfo& info) {
543543
Napi::Env env(info.Env());
544544
Napi::HandleScope scope(env);
545545

546-
if (info.Length() != 3 ||
546+
if (info.Length() != 5 ||
547547
!info[0].IsNumber() ||
548548
!info[1].IsNumber() ||
549-
!info[2].IsNumber()) {
550-
throw Napi::Error::New(env, "Usage: pty.resize(fd, cols, rows)");
549+
!info[2].IsNumber() ||
550+
!info[3].IsNumber() ||
551+
!info[4].IsNumber()) {
552+
throw Napi::Error::New(env, "Usage: pty.resize(fd, cols, rows, xPixel, yPixel)");
551553
}
552554

553555
int fd = info[0].As<Napi::Number>().Int32Value();
554556

555557
struct winsize winp;
556558
winp.ws_col = info[1].As<Napi::Number>().Int32Value();
557559
winp.ws_row = info[2].As<Napi::Number>().Int32Value();
558-
winp.ws_xpixel = 0;
559-
winp.ws_ypixel = 0;
560+
winp.ws_xpixel = info[3].As<Napi::Number>().Int32Value();
561+
winp.ws_ypixel = info[4].As<Napi::Number>().Int32Value();
560562

561563
if (ioctl(fd, TIOCSWINSZ, &winp) == -1) {
562564
switch (errno) {

src/unixTerminal.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,11 +268,13 @@ export class UnixTerminal extends Terminal {
268268
* TTY
269269
*/
270270

271-
public resize(cols: number, rows: number): void {
271+
public resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void {
272272
if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
273273
throw new Error('resizing must be done using positive cols and rows');
274274
}
275-
pty.resize(this._fd, cols, rows);
275+
const xPixel = pixelSize?.width ?? 0;
276+
const yPixel = pixelSize?.height ?? 0;
277+
pty.resize(this._fd, cols, rows, xPixel, yPixel);
276278
this._cols = cols;
277279
this._rows = rows;
278280
}

src/windowsTerminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export class WindowsTerminal extends Terminal {
138138
* TTY
139139
*/
140140

141-
public resize(cols: number, rows: number): void {
141+
public resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void {
142142
if (cols <= 0 || rows <= 0 || isNaN(cols) || isNaN(rows) || cols === Infinity || rows === Infinity) {
143143
throw new Error('resizing must be done using positive cols and rows');
144144
}

typings/node-pty.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,9 @@ declare module 'node-pty' {
159159
* Resizes the dimensions of the pty.
160160
* @param columns The number of columns to use.
161161
* @param rows The number of rows to use.
162+
* @param pixelSize Optional pixel dimensions of the pty.
162163
*/
163-
resize(columns: number, rows: number): void;
164+
resize(columns: number, rows: number, pixelSize?: { width: number, height: number }): void;
164165

165166
/**
166167
* Clears the pty's internal representation of its buffer. This is a no-op

0 commit comments

Comments
 (0)