Make _get_terminal_size_linux() work inside Emacs
I'm using ipython inside Emacs. Detection of the console width and height is not working with the current implementation. ioctl seems to return (0,0). Therefore, performing an explicit check for cr == (0,0) (in addition to the check for not cr) before falling back to environment variables is a quick fix that I think shouldn't make any negative impact on non-emacs users.
I've also added the import of os.environ line since env previously wasn't defined.

thanks! Appears not to cause any issues
