Node: tty: tty.WriteStream event 'resize' on Windows

Created on 24 May 2017  路  12Comments  路  Source: nodejs/node

  • Version: 8.0.0 rc1
  • Platform: Windows 7 x64
  • Subsystem: tty

Is this event supported on Windows?

The script with this code from the doc exits immediately without launching the event loop. I've tried to modify it like this:

process.stdout.on('resize', () => {
  console.log('screen size has changed!');
  console.log(`${process.stdout.columns}x${process.stdout.rows}`);
});

setInterval(()=>{}, 1000);

and then to resize the console window manually or via the console window properties, but the event handler never fired.

Windows Subsystem for Linux (WSL) doc tty windows

Most helpful comment

I have no idea; I just remembered that SIGWINCH was specifically mentioned in the libuv docs and quoted the reference.

All 12 comments

Quick answer currently no. It depends on SIGWINCH which comes from [g]libc.
Maybe possible to implement https://stackoverflow.com/questions/10856926/sigwinch-equivalent-on-windows
Definalty need to document

Perhaps it's supported in WSL?

FWIW, I've tried on Git Bash for Windows with the same result.

Do you know if WSL has signals?

WSL works for me (with node v7.10 for ubuntu on Windows 10 15063)
image
But that isn't fair...

libuv emulates SIGWINCH on Windows: http://docs.libuv.org/en/v1.x/signal.html

SIGWINCH may not always be delivered in a timely manner; libuv will only detect size changes when the cursor is being moved.

@richardlau This variant with a possibility to move cursor also does not work:

process.stdout.on('resize', () => {
  console.log('screen size has changed!');
  console.log(`${process.stdout.columns}x${process.stdout.rows}`);
});

process.stdin.pipe(process.stdout);

And the event handler by itself does not launch event loop, so it is hardly processed.

Could we document this? I am not sure about wording and details.

@vsemozhetbyt sounds like the correct course of action

libuv emulates SIGWINCH on Windows: http://docs.libuv.org/en/v1.x/signal.html

@richardlau do we need to move the cursor in a special way? Because the following does not fire. And console.log(`${process.stdout.columns} X ${process.stdout.rows}`); keeps outputing the initial values.

console.log('hello')
console.log(`process.stdout.isTTY? ${process.stdout.isTTY}`)
process.stdout.on('resize', (e) => {
  console.log(e);
  console.log('screen size has changed!');
  console.log(`${process.stdout.columns}x${process.stdout.rows}`);
});

setInterval(() => {
  console.log(`${process.stdout.columns} X ${process.stdout.rows}`);
}, 1000);

I have no idea; I just remembered that SIGWINCH was specifically mentioned in the libuv docs and quoted the reference.

The console needs to be in raw mode for this to work (mind, this will not exit after ctrl-c):

process.stdin.setRawMode(true);
process.stdin.on('data', () => {}); // to keep node from exiting
process.stdout.on('resize', (e) => {
  console.log(`${process.stdout.columns}x${process.stdout.rows}`);
});

I guess an doc update should be made.

@bzoz With this code, the event is processed when I change the size via terminal options but is ignored when I change the size manually. This is true for cmd.exe. For the git bash for Windows, manual width change fires the event, height change is ignored.

Was this page helpful?
0 / 5 - 0 ratings