Jul-19-2018, 12:29 AM
ok, it will be easy to switch to shutil. i decided that since i would need to do an import anyway (of sys to check the minor version) that i could just do
the code:
from os import get_terminal_size
in try/except where i def get_terminal_geometry():
one of two different ways (eliminating testing this in the function call). replacing os with shutil will be trivial.the code:
try: from shutil import get_terminal_size def get_terminal_geometry(fd=1): """Get current terminal geometry (width,heght) function get_terminal_geometry purpose get terminal geometry (width,heght) arguments (1,fd=) open file or file descriptor of tty to get geometry from return (width,height) """ return get_terminal_size(fd) except ImportError: def get_terminal_geometry(fd=1): """Get current terminal geometry (width,heght) function get_terminal_geometry purpose get terminal geometry (width,heght) arguments (1,fd=) open file or file descriptor of tty to get geometry from return (width,height) """ import fcntl,os,struct,termios if 'fileno' in dir(fd): fd=fd.fileno() try: height,width=struct.unpack('4H',fcntl.ioctl(fd, termios.TIOCGWINSZ, struct.pack('4H',0,0,0,0)))[:2] except: height,width=None,None if height is None or width is None: try: fd = os.open('/dev/tty',os.O_WRONLY) height,width=struct.unpack('4H',fcntl.ioctl(fd, termios.TIOCGWINSZ, struct.pack('4H',0,0,0,0)))[:2] os.close(fd) except: height,width=None,None if height is None or width is None: height,width=None,None return width,height
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.