rprichard/winpty

Resize handling

Opened this issue · 2 comments

Currently, winpty doesn't seem to propagate CSI codes when the actual console is being resized. Is that true and/or intended to work that way?
I'm using winpty together with xterm.js. For example, I could start far manager and resize the window afterwards. Winpty would correctly resize the terminal buffer, so far manager renders correctly. However, when exiting far manager, the console will be resized to the size before far manager was started; when starting far manager again, the window sizes would not match.

It's also easy to repo that by setting WINPTY_SHOW_CONSOLE and simply resizing the console; no control codes are generated.
I think the correct control code would be "[8,rows,cols,t"

(However, xterm.js doesn't handle that, too - but that's another issue)

That's the code, more or less. (http://invisible-island.net/xterm/ctlseqs/ctlseqs.html, grep for CSI Ps ; Ps ; Ps t).

Support for it is dodgy:

  • mintty: works
  • VTE: works if the terminal window has only a single terminal/pty (i.e. no tabs). Otherwise ignored.
  • xterm: code is ignored
  • Terminal.app, iTerm2: code is ignored
  • Konsole: acknowledges the code and resizes the virtual(?) terminal buffer, but the actual X11 window doesn't resize
  • IntelliJ (on Linux): Strange things happen:
    • Bash's $LINES and $COLUMNS variables don't update. It does update when I resize the terminal pane, so I'm not sure how this is happening.
    • The terminal pane doesn't resize.
    • Yet, the screen buffer has clearly resized. If the new size is smaller than the GUI size, the extra rows/cols are blank. If the new size is bigger, the extra rows/cols are clipped.
  • Eclipse TM Terminal: code is ignored
  • Win 17623 Conhost - WSL: code is ignored

It's true that winpty doesn't propagate a console size change to the terminal, but maybe it could. I'm not sure I'll ever get around to doing it.

winpty is frequently used for embedding a terminal in a pane of an IDE. I wonder how an IDE should handle a resize command. Are there any that already do?

If mintty/VTE respond to the code, they'll resize the GUI and the pty buffer (using ioctl). IIRC, resizing the pty then fires SIGWINCH. With winpty, on the other hand, the console window is already resized (and command-line programs notified of the change), by the time winpty-agent notices anything. If it forwards the size-change to the terminal, a likely result is that the terminal ignores the request. Maybe winpty should follow a protocol where it:

  • sends a size-change request to the terminal
  • wait a bit...
  • if no acknowledgement comes back from the terminal, it attempts to size the console to the last terminal size it saw

It might get into a loop if the console size doesn't stabilize on the terminal size.

Maybe a more fruitful approach would be getting Far Manager to stop resizing the console.

I thought this wasn't related to Far Manager, but it's actually the only program where I can repo the problem, it seems to save/restore the window position. Midnight Commander, on the other hand, doesn't even handle resize situations at all.
Xterm.js doesn't care about the control code; I would expect it to at least resize it's internal buffer so the output isn't distorted. However, I guess the problem is too rare to care about actually. I only used Far Commander to test behaviour of console "gui" applications.

I like your suggested solution, though.