Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tty: tty.WriteStream event 'resize' on Windows #13197

Closed
vsemozhetbyt opened this issue May 24, 2017 · 12 comments
Closed

tty: tty.WriteStream event 'resize' on Windows #13197

vsemozhetbyt opened this issue May 24, 2017 · 12 comments
Labels
doc Issues and PRs related to the documentations. tty Issues and PRs related to the tty subsystem. windows Issues and PRs related to the Windows platform. wsl Issues and PRs related to the Windows Subsystem for Linux.

Comments

@vsemozhetbyt
Copy link
Contributor

  • 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.

@vsemozhetbyt vsemozhetbyt added tty Issues and PRs related to the tty subsystem. windows Issues and PRs related to the Windows platform. labels May 24, 2017
@refack
Copy link
Contributor

refack commented May 24, 2017

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

@mscdex
Copy link
Contributor

mscdex commented May 24, 2017

Perhaps it's supported in WSL?

@vsemozhetbyt
Copy link
Contributor Author

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

@refack
Copy link
Contributor

refack commented May 24, 2017

Do you know if WSL has signals?

@refack
Copy link
Contributor

refack commented May 24, 2017

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

@richardlau
Copy link
Member

richardlau commented May 27, 2017

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.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented May 27, 2017

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

@Fishrock123
Copy link
Contributor

@vsemozhetbyt sounds like the correct course of action

@Fishrock123 Fishrock123 added the doc Issues and PRs related to the documentations. label May 29, 2017
@refack
Copy link
Contributor

refack commented May 29, 2017

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);

@richardlau
Copy link
Member

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

@bzoz
Copy link
Contributor

bzoz commented Jun 8, 2017

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.

@vsemozhetbyt
Copy link
Contributor Author

vsemozhetbyt commented Jun 8, 2017

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

bzoz added a commit to JaneaSystems/libuv that referenced this issue Jul 7, 2017
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.

Ref: nodejs/node#13197
@refack refack closed this as completed in ff07eaa Jul 9, 2017
addaleax pushed a commit that referenced this issue Jul 11, 2017
PR-URL: #13576
Fixes: #13197
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Bartosz Sosnowski <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
addaleax pushed a commit that referenced this issue Jul 18, 2017
PR-URL: #13576
Fixes: #13197
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Bartosz Sosnowski <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Fishrock123 pushed a commit that referenced this issue Jul 19, 2017
PR-URL: #13576
Fixes: #13197
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Bartosz Sosnowski <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
@refack refack added the wsl Issues and PRs related to the Windows Subsystem for Linux. label Jul 22, 2017
bzoz added a commit to JaneaSystems/libuv that referenced this issue Jul 28, 2017
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.

Ref: nodejs/node#13197
bzoz added a commit to JaneaSystems/libuv that referenced this issue Aug 7, 2017
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.

Ref: nodejs/node#13197
bzoz added a commit to JaneaSystems/libuv that referenced this issue Aug 7, 2017
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.

Ref: nodejs/node#13197
MylesBorins pushed a commit that referenced this issue Aug 16, 2017
PR-URL: #13576
Fixes: #13197
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Bartosz Sosnowski <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
MylesBorins pushed a commit that referenced this issue Sep 5, 2017
PR-URL: #13576
Fixes: #13197
Reviewed-By: Tobias Nießen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Bartosz Sosnowski <[email protected]>
Reviewed-By: Gibson Fahnestock <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
bzoz added a commit to JaneaSystems/libuv that referenced this issue Sep 14, 2017
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.

Ref: nodejs/node#13197
PR-URL: libuv#1408
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
bzoz added a commit to libuv/libuv that referenced this issue Sep 14, 2017
Add SetWinEventHook for EVENT_CONSOLE_LAYOUT for better detection of
console resize events.

Ref: nodejs/node#13197
PR-URL: #1408
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Issues and PRs related to the documentations. tty Issues and PRs related to the tty subsystem. windows Issues and PRs related to the Windows platform. wsl Issues and PRs related to the Windows Subsystem for Linux.
Projects
None yet
Development

No branches or pull requests

6 participants