Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I just create another interface PixelSize which would have field width, height?
That way we can just say simply say pixelSize here.


/**
* Clears the pty's internal representation of its buffer. This is a no-op
Expand Down
2 changes: 1 addition & 1 deletion src/native.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about renaming this to width, height but might be confusing since we dont have the pixelSize like in interfaces.ts

Maybe widthPixel, heightPixel would be the better

}

interface IConptyProcess {
Expand Down
2 changes: 1 addition & 1 deletion src/terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions src/unix/pty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,20 +543,22 @@ 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)");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

xpixel, ypixel vs. width, height vs widthPixel, heightPixel 🥸

}

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

struct winsize winp;
winp.ws_col = info[1].As<Napi::Number>().Int32Value();
winp.ws_row = info[2].As<Napi::Number>().Int32Value();
winp.ws_xpixel = 0;
winp.ws_ypixel = 0;
winp.ws_xpixel = info[3].As<Napi::Number>().Int32Value();
winp.ws_ypixel = info[4].As<Napi::Number>().Int32Value();

if (ioctl(fd, TIOCSWINSZ, &winp) == -1) {
switch (errno) {
Expand Down
6 changes: 4 additions & 2 deletions src/unixTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/windowsTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
3 changes: 2 additions & 1 deletion typings/node-pty.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down