-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
[PATCH] Make pty.spawn set window size #85713
Comments
The example in https://docs.python.org/3/library/pty.html that mimics script(1) can be used to reproduce the problem: since window size is not set by pty.spawn, output of "ls" becomes scattered and hard to visually parse if xterm window is not in fullscreen mode. To fix the above issue, this patch makes pty.spawn set window size ( TIOCSWINSZ ). Also, this patch makes the code of pty.fork() more readable by defining _login_pty(); the latter is reused in spawn(). |
OS: Linux 4.19.0-9-amd64 Debian 10 GNU/Linux |
Note that defining _login_pty() was not a cosmetic change; it is reused in spawn(). |
v0.2 moves _setwinsz block to parent after fork. |
Screenshot: output of "ls" before the patch is applied. |
Screenshot: output of "ls" after the patch is applied. |
Adding the test program [ test.py ] as an attachment. It was taken from https://docs.python.org/3/library/pty.html. How to reproduce issue:
Solution:
|
I am new to BPO. Just learned how to make someone nosy. @twouters, I have attached all resources. This is ready for a review. Thank you. |
Additional note: I am using the i3wm window manager. No desktop environment. |
v0.3 removes _login_pty() and defines _login_tty() instead; the latter is based on login_tty(3) from glibc. |
v0.4 puts try-except guards around imports so that existing code does not break. |
Further proposal: Rename my _login_tty to login_tty and make it available as a part of the pty library. Note that usually login_tty accompanies openpty and forkpty on a system; for example, see https://www.man7.org/linux/man-pages/man3/login_tty.3.html However, python's pty only offers openpty and forkpty in the form of pty.openpty and pty.fork respectively. While it is true that forkpty [ pty.fork ] combines openpty, fork, and login_tty, it also closes the slave end of the pty, making it unsuitable for situations where the slave end needs to be kept open; for example, in my patch, the slave end is used to set the window size; or, in case someone wants to do even better and register a SIGWINCH handler for situations in which the window size can change. |
Further note: login_tty will also enable us to set slave termios from the parent process in pty.spawn. Due to the fact that reviewing patches can be overwhelming, v0.5 removes a lot of stuff and instead simply performs window resize by calling ioctl TIOCSWINSZ on the master end of the pty. Still works as expected. |
v0.5 had introduced minor mistakes + one hack [ was using master instead of slave to set window size ]. v0.6 removes all such mistakes. |
All images, test programs, and old patches have been removed. window resize test is now being performed using stty. On linux: On BSDs: to change window size. |
Any reason this was dropped? Anyway the patch was useful for me. |
@kjoyce77 This was opened as "proof of concept" and was a dirty quick fix (not supposed to be merged). Please comment here instead: #85984. The core developers are very busy (I am not a core developer), and they do the best they can when they get time to review our pull requests. Please help them review my pull requests on that thread if you have time! |
Superseded by #85984. Let's get that one in :) |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: