def copy_winsize(target_fd, source_fd=STDIN_FILENO):
"""
Propagate terminal size from `source_fd` to `target_fd`.
"""
# Create a buffer to store terminal size attributes. Refer to tty_ioctl(4)
# for more information.
winsize = array.array("h", [
0, # unsigned short ws_row
0, # unsigned short ws_col
0, # unsigned short ws_xpixel (unused)
0, # unsigned short ws_ypixel (unused)
])
# Write window size into winsize variable.
fcntl.ioctl(source_fd, termios.TIOCGWINSZ, winsize, True)
# Send winsize to target terminal.
fcntl.ioctl(target_fd, termios.TIOCSWINSZ, winsize)
评论列表
文章目录