[issue13609] Add "os.get_terminal_size()" function
Zbyszek Szmek
report at bugs.python.org
Wed Feb 15 01:17:41 CET 2012
Zbyszek Szmek <zbyszek at in.waw.pl> added the comment:
> New try (I fixed my email address and the patch).
>
> The purpose of os.get_terminal_size() is the same as `stty size`, so
> `stty size` could be a model for behavior of os.get_terminal_size().
I guess that this fallback will make some things easier. As long it is documented, the user should be able to get whatever behaviour they want.
I have four small questions:
- -1 is used as the argument meaning "try stdout and stdin". But -1 is
also used the error return value for open(2) and other system
functions. I know that Python checks the return value to throw an
exception, and -1 shouldn't "leak" and be passed by mistake to
os.get_terminal_size(). Can someone confirm that this is
the case?
- Why stderr is not checked too? It would make os.get_terminal_size()
return the real terminal value in a the middle of a pipe:
cat | python -c 'import os; os.get_terminal_size()' | cat.
- some doc change is missing
- in the new version the line with ioctl(fd, TIOCGWINSZ, &w) repeats
three times. It think it could be reduced to two without loss
of readability.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue13609>
_______________________________________
More information about the Python-bugs-list
mailing list