Skip to content

Add pixel arguments to set window size #79

@queue-miscreant

Description

@queue-miscreant

Is there any reason the ws_xpixel and ws_ypixel fields of the TIOCSWINSZ call are always 0? Naively, shouldn't it be possible to replace

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)

with

def _setwinsize(fd, rows, cols, pixel_height=0, pixel_width=0):
    # 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 default to zero.
    s = struct.pack('HHHH', rows, cols, pixel_width, pixel_height)
    fcntl.ioctl(fd, TIOCSWINSZ, s)

I ask because of a long chain of trying to figure out why I couldn't get some things to display correctly in a Poetry shell, which uses pexpect (which uses this). On at least my kernel (Linux 6.10), the terminal is responsive to the values supplied in those fields of the struct. Ideally, it would be nice for pexpect to be able to forward size changes to its children beyond just row and column counts.

I noticed that an old issue mentions portability problems on FreeBSD (pexpect/pexpect#39), but that involved the ioctl call having a different value. Perhaps someone better informed than me can confirm that implementing this breaks things on other systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions