Skip to content

Conversation

@anthonykim1
Copy link
Contributor

@anthonykim1 anthonykim1 commented Jan 23, 2026

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

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

Edit: See result below!

@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
@anthonykim1
Copy link
Contributor Author

anthonykim1 commented Jan 26, 2026

Symlinked my local node-pty to test on xterm demo:

pixelREalShowing kittyWorking

🤩🚀

@anthonykim1 anthonykim1 marked this pull request as ready for review January 26, 2026 07:18
@jerch
Copy link
Collaborator

jerch commented Jan 26, 2026

@anthonykim1 Gonna add the ioctl's for TIOCGWINSZ/TIOCSWINSZ to the node-termios package, then you don't have to shim it with your own C helper.

@Tyriar
Copy link
Member

Tyriar commented Jan 26, 2026

@jerch we don't use that atm though and want to avoid including dev dependencies in general?

@jerch
Copy link
Collaborator

jerch commented Jan 26, 2026

@Tyriar No need to include into the automated CI testing. It is more helpful for exploring local tests as @anthonykim1 did above and would spare the need to go into C yourself (so it would help any JS/TS dev without any C experience).

@anthonykim1 anthonykim1 marked this pull request as draft January 26, 2026 16:16
@anthonykim1 anthonykim1 marked this pull request as ready for review January 26, 2026 17:20
@anthonykim1 anthonykim1 requested a review from Tyriar January 26, 2026 17:20
@Tyriar Tyriar merged commit 598652c into main Jan 26, 2026
9 checks passed
@Tyriar Tyriar deleted the anthonykim1/resizeUsePixel branch January 26, 2026 19:08
@jerch
Copy link
Collaborator

jerch commented Jan 27, 2026

@anthonykim1 The new package is online now: https://www.npmjs.com/package/node-termios/v/0.2.0

With it you can create a console app in nodejs tracking the TTY size like this:

const { native: { tcgetwinsize } } = require('node-termios');

// file descriptor of STDIN
const STDIN_FD = 0;

// needed to keep the process running
// (not needed if you keep the event loop running by other means)
process.stdin.resume();

// register a signal handler for SIGWINCH
process.on('SIGWINCH', () => {
  console.log('TTY size:', tcgetwinsize(STDIN_FD));
});

and then resizing the terminal window. This works only under macos/linux though (prolly also under FreeBSD, Solaris is untested).

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.

5 participants