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

The positions of the two arguments in setwinsize function appear to be reversed #71

Open
coderk17 opened this issue Aug 22, 2022 · 2 comments

Comments

@coderk17
Copy link

Recently I made a Web terminal with ptyprocess, websocket, and XTerm, but eventually found that the Web terminal size could not adapt after the resize event was triggered.

I even thought my computer was actually a big phone until I switched the positions of two parameters and the page appeared normal.

Before:

def _setwinsize(fd, rows, cols):
    # Some very old platforms have a bug that causes the value for
    # termios.TIOCSWINSZ to be truncated. There was a hack here to work
    # around this, but it caused problems with newer platforms so has been
    # removed. For details see https://github.com/pexpect/pexpect/issues/39
    TIOCSWINSZ = getattr(termios, 'TIOCSWINSZ', -2146929561)
    # Note, assume ws_xpixel and ws_ypixel are zero.
    s = struct.pack('HHHH', rows, cols, 0, 0)
    fcntl.ioctl(fd, TIOCSWINSZ, s)

After using the following modified code, the interface display is normal:

def _setwinsize(fd, rows, cols):
    # Some very old platforms have a bug that causes the value for
    # termios.TIOCSWINSZ to be truncated. There was a hack here to work
    # around this, but it caused problems with newer platforms so has been
    # removed. For details see https://github.com/pexpect/pexpect/issues/39
    width, height = cols, rows
    TIOCSWINSZ = getattr(termios, 'TIOCSWINSZ', -2146929561)
    # Note, assume ws_xpixel and ws_ypixel are zero.
    s = struct.pack('HHHH', width, height, 0, 0)
    fcntl.ioctl(fd, TIOCSWINSZ, s)
@takluyver
Copy link
Member

The ioctl man page says that rows (i.e. height) comes first, and then columns (width). I've also used this code to do basically the same thing you describe years ago, to have a web based terminal in the Jupyter interface (part of this is the terminado package).

So double check and see if it's possible that the parameters are being switched round somewhere before they get to ptyprocess. 🙂

@coderk17
Copy link
Author

All right, I'll check again and post the results below. Thank you for your reply.

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

No branches or pull requests

2 participants