Skip to content

Conversation

@anthonykim1
Copy link
Contributor

@anthonykim1 anthonykim1 commented Jan 23, 2026

@anthonykim1 anthonykim1 self-assigned this Jan 23, 2026
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

* @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.

!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 🥸

@anthonykim1
Copy link
Contributor Author

anthonykim1 commented Jan 23, 2026

Testing the pass through with js script with:

  1. npm run build
  2. node examples/test-pixel-resize.js
where test-pixe-resize.js

/**

  • Test script to verify pixel size is passed to the pty.
  • Run with: node examples/test-pixel-resize.js
    */
    import * as os from 'node:os';
    import * as pty from '../lib/index.js';

const isWindows = os.platform() === 'win32';
const shell = isWindows ? 'powershell.exe' : 'bash';

const ptyProcess = pty.spawn(shell, [], {
name: 'xterm-256color',
cols: 80,
rows: 24,
cwd: isWindows ? process.env.USERPROFILE : process.env.HOME,
env: process.env
});

ptyProcess.onData(data => process.stdout.write(data));

// On Unix, we can query the terminal size including pixel dimensions
// using the escape sequence: ESC [ 1 4 t (report window size in pixels)
// or use stty/resize commands, or write a small C program

if (!isWindows) {
// Method 1: Use stty size to get rows/cols (doesn't show pixels though)
console.log('\n--- Testing resize with pixel dimensions ---\n');

// Resize with pixel dimensions: 800x600 pixels
ptyProcess.resize(100, 30, { width: 800, height: 600 });
console.log('Resized to 100x30 chars, 800x600 pixels');

// Query window size - this C one-liner reads TIOCGWINSZ and prints all 4 values
ptyProcess.write(python3 -c " import fcntl, termios, struct buf = fcntl.ioctl(0, termios.TIOCGWINSZ, b'\\x00' * 8) rows, cols, xpixel, ypixel = struct.unpack('HHHH', buf) print(f'rows={rows}, cols={cols}, xpixel={xpixel}, ypixel={ypixel}') "\r);
}

setTimeout(() => {
ptyProcess.kill();
process.exit(0);
}, 3000);

test_resize_js

TODO before merging:
Now I should test if this works when I symlink node-pty on xterm

@anthonykim1 anthonykim1 requested review from Tyriar and jerch January 23, 2026 21:56
@anthonykim1 anthonykim1 added this to the January 2026 milestone Jan 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants