Skip to content

Commit 598652c

Browse files
authored
Merge pull request #881 from microsoft/anthonykim1/resizeUsePixel
Add pixel size support to resize()
2 parents c69dc67 + 05f2d4e commit 598652c

File tree

7 files changed

+22
-12
lines changed

7 files changed

+22
-12
lines changed

src/interfaces.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ 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. On Unix, this sets the `ws_xpixel`
32+
* and `ws_ypixel` fields of the `winsize` struct. Applications running in the pty can read
33+
* these values via the `TIOCGWINSZ` ioctl. This parameter is ignored on Windows.
3134
*/
32-
resize(cols: number, rows: number): void;
35+
resize(cols: number, rows: number, pixelSize?: { width: number, height: number }): void;
3336

3437
/**
3538
* 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, pixelWidth: number, pixelHeight: 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 pixelWidth = pixelSize?.width ?? 0;
276+
const pixelHeight = pixelSize?.height ?? 0;
277+
pty.resize(this._fd, cols, rows, pixelWidth, pixelHeight);
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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,11 @@ 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. On Unix, this sets the `ws_xpixel`
163+
* and `ws_ypixel` fields of the `winsize` struct. Applications running in the pty can read
164+
* these values via the `TIOCGWINSZ` ioctl. This parameter is ignored on Windows.
162165
*/
163-
resize(columns: number, rows: number): void;
166+
resize(columns: number, rows: number, pixelSize?: { width: number, height: number }): void;
164167

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

0 commit comments

Comments
 (0)